Skip to content

Commit a4c142c

Browse files
authored
Issue 43 add cell export import function (#72)
* #43 - Added cell lock function - Consideration of abnormal system * Maintenance of test code. * Maintenance of test code. * - Maintenance of test code. - Resolving warning. * Maintenance of test code. * Bug fix.
1 parent c16c980 commit a4c142c

File tree

56 files changed

+924
-401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+924
-401
lines changed

pom.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@
334334
</configuration>
335335
<executions>
336336
<execution>
337+
<!-- Test group assuming execution from environment outside Personium server. -->
337338
<id>integration-tests</id>
338339
<phase>integration-test</phase>
339340
<goals>
@@ -342,8 +343,24 @@
342343
<configuration>
343344
<skip>false</skip>
344345
<includes>
345-
<include>**/jersey/**/*Test.java</include>
346+
<include>**/test/jersey/**/*Test.java</include>
346347
</includes>
348+
<excludes>
349+
<!-- Tests that fail when running tests from outside for various reasons. -->
350+
<!-- TODO Should be fixed so that all tests are successful. -->
351+
<exclude>**/jersey/box/ServiceRelayTest.java</exclude>
352+
<exclude>**/jersey/AcceptEncodingTest.java</exclude>
353+
<exclude>**/jersey/StatusTest.java</exclude>
354+
<exclude>**/jersey/cell/CellBulkDeletionTest.java</exclude>
355+
<exclude>**/jersey/cell/UnitUserCellCRUDTest.java</exclude>
356+
<exclude>**/jersey/cell/EventTest.java</exclude>
357+
<exclude>**/jersey/cell/auth/AuthCheckTest.java</exclude>
358+
<exclude>**/jersey/cell/auth/AuthCookieTest.java</exclude>
359+
<exclude>**/jersey/cell/auth/AuthTest.java</exclude>
360+
<exclude>**/jersey/cell/auth/ImplicitFlowTest.java</exclude>
361+
<exclude>**/jersey/cell/auth/X509AuthTest.java</exclude>
362+
<exclude>**/jersey/cell/ctl/ExtCellReadTest.java</exclude>
363+
</excludes>
347364
</configuration>
348365
</execution>
349366
</executions>

src/main/java/io/personium/core/PersoniumCoreException.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,12 @@ public static class BarInstall {
845845
* その他エラー.
846846
*/
847847
public static class Misc {
848+
/**
849+
* File or Directory does not exist in the snapshot file.
850+
* <p>
851+
* {0} : File or Directory path in zip
852+
*/
853+
public static final PersoniumCoreException NOT_FOUND_IN_SNAPSHOT = create("PR400-MC-0001");
848854
/**
849855
* Unexpected URI.
850856
*/
@@ -859,7 +865,7 @@ public static class Misc {
859865
*/
860866
public static final PersoniumCoreException SERVER_REQUEST_TIMEOUT = create("PR408-MC-0001");
861867
/**
862-
* セル一括削除時に削除対象のセルにアクセスがあったとき.
868+
* There is other access to the target cell when processing to the cell.
863869
*/
864870
public static final PersoniumCoreException CONFLICT_CELLACCESS = create("PR409-MC-0001");
865871
/**
@@ -914,13 +920,13 @@ public static class Common {
914920
/**
915921
* Executing API that is not allowed when the cell status is "import failed".
916922
*/
917-
public static final PersoniumCoreException CELL_STATUS_IMPORT_FAILED = create("PR400-CM-0005");
923+
public static final PersoniumCoreException CELL_STATUS_IMPORT_FAILED = create("PR409-CM-0001");
918924
/**
919-
* File or Directory does not exist in the snapshot file.
925+
* Error when writing to cell is locked.
920926
* <p>
921-
* {0} : File or Directory path in zip
927+
* {0} : Processing that caused lock.
922928
*/
923-
public static final PersoniumCoreException NOT_FOUND_IN_SNAPSHOT = create("PR404-CM-0001");
929+
public static final PersoniumCoreException LOCK_WRITING_TO_CELL = create("PR409-CM-0002");
924930
/**
925931
* Failed to load the request body.
926932
*/

src/main/java/io/personium/core/PersoniumUnitConfig.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,11 @@ public static final class BAR {
327327
}
328328

329329
/**
330-
* cell export configurations.
330+
* cell snapshot configurations.
331331
*/
332-
public static final class CellExport {
332+
public static final class CellSnapshot {
333333
/** Root directory path to store the cell export file. */
334-
public static final String ROOT = KEY_ROOT + "cellExport.root";
334+
public static final String ROOT = KEY_ROOT + "cellSnapshot.root";
335335
}
336336

337337
static {
@@ -743,15 +743,15 @@ public static String getLockRetryInterval() {
743743
/**
744744
* @return セルロック取得時のリトライ回数.
745745
*/
746-
public static String getCellLockRetryTimes() {
747-
return get(Lock.CELL_RETRY_TIMES);
746+
public static int getCellLockRetryTimes() {
747+
return Integer.parseInt(get(Lock.CELL_RETRY_TIMES));
748748
}
749749

750750
/**
751751
* @return セルロック取得リトライ時の間隔.
752752
*/
753-
public static String getCellLockRetryInterval() {
754-
return get(Lock.CELL_RETRY_INTERVAL);
753+
public static long getCellLockRetryInterval() {
754+
return Long.parseLong(get(Lock.CELL_RETRY_INTERVAL));
755755
}
756756

757757
/**
@@ -821,11 +821,11 @@ public static String getBlobStoreRoot() {
821821
}
822822

823823
/**
824-
* Get root directory path to store cell export file.
825-
* @return root directory path to store cell export file
824+
* Get root directory path to store cell snapshot file.
825+
* @return root directory path to store cell snapshot file
826826
*/
827-
public static String getCellExportRoot() {
828-
return get(CellExport.ROOT);
827+
public static String getCellSnapshotRoot() {
828+
return get(CellSnapshot.ROOT);
829829
}
830830

831831
/**
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* personium.io
3+
* Copyright 2017 FUJITSU LIMITED
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.personium.core.annotations;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
/**
25+
* Annotation given to the method of API that performs writing(deletion).
26+
* When the cell is locking write, make the corresponding method inoperable.
27+
*/
28+
@Target(ElementType.METHOD)
29+
@Retention(RetentionPolicy.RUNTIME)
30+
public @interface WriteAPI {
31+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* personium.io
3+
* Copyright 2017 FUJITSU LIMITED
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.personium.core.jersey.filter;
18+
19+
import java.util.Collections;
20+
import java.util.List;
21+
22+
import com.sun.jersey.api.model.AbstractMethod;
23+
import com.sun.jersey.spi.container.ResourceFilter;
24+
import com.sun.jersey.spi.container.ResourceFilterFactory;
25+
26+
import io.personium.core.annotations.WriteAPI;
27+
28+
/**
29+
* Set filter processing for request/response of specific condition.
30+
*/
31+
public class PersoniumCoreResourceFilterFactory implements ResourceFilterFactory {
32+
33+
/**
34+
* {@inheritDoc}
35+
*/
36+
@Override
37+
public List<ResourceFilter> create(AbstractMethod am) {
38+
if (am.getAnnotation(WriteAPI.class) != null) {
39+
// Filter for @WriteAPI annotation.
40+
return Collections.<ResourceFilter>singletonList(new WriteMethodFilter());
41+
}
42+
return null;
43+
}
44+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* personium.io
3+
* Copyright 2017 FUJITSU LIMITED
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.personium.core.jersey.filter;
18+
19+
import java.util.regex.Matcher;
20+
import java.util.regex.Pattern;
21+
22+
import com.sun.jersey.spi.container.ContainerRequest;
23+
import com.sun.jersey.spi.container.ContainerRequestFilter;
24+
import com.sun.jersey.spi.container.ContainerResponseFilter;
25+
import com.sun.jersey.spi.container.ResourceFilter;
26+
27+
import io.personium.core.PersoniumCoreException;
28+
import io.personium.core.model.Cell;
29+
import io.personium.core.model.ModelFactory;
30+
import io.personium.core.model.lock.CellLockManager;
31+
32+
/**
33+
* Filter for requests with @WriteAPI annotation set.
34+
*/
35+
public class WriteMethodFilter implements ResourceFilter, ContainerRequestFilter {
36+
37+
/**
38+
* {@inheritDoc}
39+
*/
40+
@Override
41+
public ContainerRequestFilter getRequestFilter() {
42+
return this;
43+
}
44+
45+
/**
46+
* {@inheritDoc}
47+
*/
48+
@Override
49+
public ContainerResponseFilter getResponseFilter() {
50+
// do nothing.
51+
return null;
52+
}
53+
54+
/**
55+
* {@inheritDoc}
56+
*/
57+
@Override
58+
public ContainerRequest filter(ContainerRequest request) {
59+
// Get cell name from URI.
60+
String path = request.getPathSegments().get(0).getPath();
61+
if ("__ctl".equals(path)) {
62+
// For __ctl it is UnitLevelAPI.
63+
// Get {name} from [Cell('{name}') or Cell(Name='{name}')].
64+
path = request.getPathSegments().get(1).getPath();
65+
Pattern formatPattern = Pattern.compile("'(.+)'");
66+
Matcher formatMatcher = formatPattern.matcher(path);
67+
if (formatMatcher.find()) {
68+
path = formatMatcher.group(1);
69+
} else {
70+
return request;
71+
}
72+
}
73+
String cellName = path;
74+
Cell cell = ModelFactory.cell(cellName);
75+
if (cell != null) {
76+
CellLockManager.STATUS lockStatus = CellLockManager.getCellStatus(cell.getId());
77+
// If the lock status of Cell is "export", "import", do not allow access.
78+
if (CellLockManager.STATUS.EXPORT.equals(lockStatus) || CellLockManager.STATUS.IMPORT.equals(lockStatus)) {
79+
throw PersoniumCoreException.Common.LOCK_WRITING_TO_CELL.params(lockStatus.getMessage());
80+
}
81+
}
82+
return request;
83+
}
84+
}

src/main/java/io/personium/core/model/DavRsCmp.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
import io.personium.core.utils.ResourceUtils;
7777

7878
/**
79-
* A component class to process WebDAV related request delegated from JaxRS Resource objects.
79+
* A component class to process WebDAV related request delegated from JaxRS Resource objects.
8080
* Some process are further delegated to DavCmp classes.
8181
*/
8282
public class DavRsCmp {
@@ -107,7 +107,7 @@ public DavRsCmp(final DavRsCmp parent, final DavCmp davCmp) {
107107

108108
/**
109109
* returns Jax-RS resource in charge of child path.
110-
* @param nextPath child path name
110+
* @param nextPath child path name
111111
* @param request HttpServletRequest
112112
* @return Jax-RS resource in charge of the child path
113113
*/
@@ -260,7 +260,7 @@ public final Response doPropfind(final Reader requestBodyXml, final String depth
260260
}
261261

262262
String reqUri = this.getUrl();
263-
// take away trailing slash
263+
// take away trailing slash
264264
if (reqUri.endsWith("/")) {
265265
reqUri = reqUri.substring(0, reqUri.length() - 1);
266266
}
@@ -306,7 +306,7 @@ public void write(final OutputStream os) throws IOException {
306306
}
307307

308308
/**
309-
* process PROPPATCH request.
309+
* process PROPPATCH request.
310310
* @param reqBodyXml requestBody
311311
* @return Jax-RS Response object
312312
*/
@@ -339,7 +339,7 @@ public void write(final OutputStream os) throws IOException {
339339
}
340340

341341
/**
342-
* ACL Method. configuring ACL.
342+
* ACL Method. configuring ACL.
343343
* @param reader Configuration XML
344344
* @return JAX-RS Response
345345
*/
@@ -361,7 +361,7 @@ public String getConfidentialLevel() {
361361

362362
if (confidentialStringTmp == null || "".equals(confidentialStringTmp)) {
363363
if (this.parent == null) {
364-
// App Authn regarded not necessary
364+
// App Authn regarded not necessary
365365
// if there is no configuration up to box
366366
return OAuth2Helper.SchemaLevel.NONE;
367367
}
@@ -377,8 +377,8 @@ public String getConfidentialLevel() {
377377
* @return boolean
378378
*/
379379
public boolean hasPrivilege(AccessContext ac, Privilege privilege) {
380-
// skip ACL check if davCmp does not exist.
381-
// (nonexistent resource is specified)
380+
// skip ACL check if davCmp does not exist.
381+
// (nonexistent resource is specified)
382382
if (this.davCmp != null
383383
&& this.getAccessContext().requirePrivilege(this.davCmp.getAcl(), privilege, this.getCell().getUrl())) {
384384
return true;
@@ -413,7 +413,7 @@ public Response options() {
413413
}
414414

415415
/**
416-
* Check Access Control.
416+
* Check Access Control.
417417
* Exceptions are thrown if it does not have the privilege
418418
* @param ac AccessContext
419419
* @param privilege Privilege to check if it is given
@@ -563,7 +563,7 @@ static final org.apache.wink.webdav.model.Response createDavResponse(final Strin
563563
element.setTextContent(dCmp.getCellStatus());
564564
ret.setPropertyOk(element);
565565
} else {
566-
// Collection Resource
566+
// Collection Resource
567567
Resourcetype colRt = of.createResourcetype();
568568
colRt.setCollection(of.createCollection());
569569
ret.setPropertyOk(colRt);
@@ -589,9 +589,8 @@ static final org.apache.wink.webdav.model.Response createDavResponse(final Strin
589589
ret.setPropertyOk(e);
590590
}
591591
}
592-
593592

594-
// Processing Other Props
593+
// Processing Other Props
595594
Map<String, String> props = dCmp.getProperties();
596595
if (props != null) {
597596
List<String> nsList = new ArrayList<String>();

src/main/java/io/personium/core/model/ModelFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ public static Cell cell(final String id, final UriInfo uriInfo) {
6161
return CellEsImpl.load(id, uriInfo);
6262
}
6363

64+
/**
65+
* Get cell from the specified cell name.
66+
* However, the parameter "url" of Cell is not set.
67+
* @param cellName target cell name
68+
* @return cell
69+
*/
70+
public static Cell cell(String cellName) {
71+
return CellEsImpl.load(cellName);
72+
}
73+
6474
/**
6575
* Boxの内部実装モデルオブジェクトを生成して返します.
6676
* @param box Boxクラス

0 commit comments

Comments
 (0)