Skip to content

Commit

Permalink
Merge pull request #392 from SawamiWataru/develop
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'personium/1.7.8_es6.6.1-dev' into develop
  • Loading branch information
Akira Ohishi authored Apr 10, 2019
2 parents 0282e22 + 3f85661 commit b5c0b07
Show file tree
Hide file tree
Showing 14 changed files with 426 additions and 52 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<dependency>
<groupId>io.personium</groupId>
<artifactId>personium-lib-es-adapter</artifactId>
<version>1_es6.6.1_2</version>
<version>1_es6.6.1_3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.personium</groupId>
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/io/personium/core/event/PersoniumEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
package io.personium.core.event;

import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -239,13 +239,6 @@ public void convertObject(String cellUrl) {
this.object = UriUtils.convertSchemeFromLocalCellToHttp(cellUrl, this.object);
}

/**
* Convert PersoniumEvent object to publish.
*/
public void convertToPublish() {
this.roles = null;
}

/**
* Validate Type property.
* @param typeValue the property
Expand Down
62 changes: 60 additions & 2 deletions src/main/java/io/personium/core/rule/RuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -125,6 +125,8 @@ class RuleInfo {
PersoniumEventType.cellctl(Box.EDM_TYPE_NAME, PersoniumEventType.Operation.UPDATE);
private static final String RULEEVENT_BOX_MERGE =
PersoniumEventType.cellctl(Box.EDM_TYPE_NAME, PersoniumEventType.Operation.MERGE);
private static final String RULEEVENT_BOX_RECURSIVE_DELETE =
PersoniumEventType.box(PersoniumEventType.Operation.DELETE);
private static final String RULEEVENT_CELL_IMPORT = PersoniumEventType.cell(PersoniumEventType.Operation.IMPORT);

private static RuleManager instance = null;
Expand Down Expand Up @@ -327,7 +329,6 @@ public void judge(PersoniumEvent event) {
}

// publish event
event.convertToPublish();
publish(event);

CellLockManager.decrementReferenceCount(cell.getId());
Expand All @@ -349,6 +350,7 @@ private void publish(PersoniumEvent event) {
|| RULEEVENT_BOX_NAVPROP_RULE_CREATE.equals(type)
|| RULEEVENT_BOX_UPDATE.equals(type)
|| RULEEVENT_BOX_MERGE.equals(type)
|| RULEEVENT_BOX_RECURSIVE_DELETE.equals(type)
|| RULEEVENT_CELL_IMPORT.equals(type))) {
ruleEventPublisher.publish(event);
}
Expand Down Expand Up @@ -693,6 +695,10 @@ public boolean handleRuleEvent(PersoniumEvent event) {
setBoxInfo(cell, box);
}
ret = true;
} else if (RULEEVENT_BOX_RECURSIVE_DELETE.equals(type)) {
String boxUri = event.getObject().get();
String boxName = boxUri.substring(boxUri.lastIndexOf(UriUtils.STRING_SLASH) + 1);
ret = unregisterRule(boxName, cell);
} else if (RULEEVENT_CELL_IMPORT.equals(type)) {
deleteRule(cell.getId());
loadRule(cell);
Expand Down Expand Up @@ -874,6 +880,47 @@ private boolean registerRule(OEntity oEntity, Cell cell) {
return true;
}

/**
* Unregister rule.
* @param boxName name of box linked with the rule
* @param cell cell object that the rule belongs to
* @return true if unregistering is success, false otherwise
*/
private boolean unregisterRule(String boxName, Cell cell) {
List<RuleInfo> ruleList = getRuleListLinkedBox(boxName, cell);
if (ruleList.isEmpty()) {
return true;
}
for (RuleInfo rule : ruleList) {
// Get key string for HashMap from ruleName and box's id
String key = getRuleKey(rule.name, rule.box.id);
if (!unregisterRuleByKey(key, rule.box.id, cell)) {
return false;
}
}
return true;
}

/**
* Get rule list linked box.
* @param boxName boxName name of box linked with the rule
* @param cell cell object that the rule belongs to
* @return rule list
*/
private List<RuleInfo> getRuleListLinkedBox(String boxName, Cell cell) {
List<RuleInfo> ruleList = new ArrayList<RuleInfo>();
Map<String, RuleInfo> map = rules.get(cell.getId());
if (map == null || map.isEmpty()) {
return ruleList;
}
for (RuleInfo rule : map.values()) {
if (boxName.equals(rule.boxname)) {
ruleList.add(rule);
}
}
return ruleList;
}

/**
* Unregister rule.
* @param ruleName name of rule unregistered
Expand All @@ -894,6 +941,17 @@ private boolean unregisterRule(String ruleName, String boxName, Cell cell) {
// Get key string for HashMap from ruleName and box's id
String key = getRuleKey(ruleName, boxId);

return unregisterRuleByKey(key, boxId, cell);
}

/**
* Unregister rule.
* @param key key is ruleName and box's id
* @param boxId id of box linked with the rule
* @param cell cell object that the rule belongs to
* @return true if unregistering is success, false otherwise
*/
private boolean unregisterRuleByKey(String key, String boxId, Cell cell) {
// Remove rule and box as necessary.
synchronized (lockObj) {
Map<String, RuleInfo> map = rules.get(cell.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void tearDown() throws Exception {
public void create処理が正常に終了する() {
EsIndex index = esClient.idxAdmin("index_for_test");
assertNotNull(index);
DataSourceAccessor dsa = new DataSourceAccessor(index, "TypeForTest", "RoutingIdTest");
DataSourceAccessor dsa = new DataSourceAccessor(index, "cell", "RoutingIdTest");
PersoniumIndexResponse response = dsa.create("id00001", new HashMap<Object, Object>());
assertNotNull(response);
assertEquals("id00001", response.getId());
Expand All @@ -111,7 +111,7 @@ public void tearDown() throws Exception {
public void ID省略でcreate処理が正常に終了する() {
EsIndex index = esClient.idxAdmin("index_for_test");
assertNotNull(index);
DataSourceAccessor dsa = new DataSourceAccessor(index, "TypeForTest", "RoutingIdTest");
DataSourceAccessor dsa = new DataSourceAccessor(index, "cell", "RoutingIdTest");
PersoniumIndexResponse response = dsa.create(new HashMap<Object, Object>());
assertNotNull(response);
assertFalse(response.getId().equals(""));
Expand All @@ -124,7 +124,7 @@ public void tearDown() throws Exception {
public void update処理が正常に終了する() {
EsIndex index = esClient.idxAdmin("index_for_test");
assertNotNull(index);
DataSourceAccessor dsa = new DataSourceAccessor(index, "TypeForTest", "RoutingIdTest");
DataSourceAccessor dsa = new DataSourceAccessor(index, "cell", "RoutingIdTest");
PersoniumIndexResponse response = dsa.update("id00001", new HashMap<Object, Object>());
assertNotNull(response);
assertEquals("id00001", response.getId());
Expand All @@ -137,7 +137,7 @@ public void tearDown() throws Exception {
public void search処理が正常に終了する() {
EsIndex index = esClient.idxAdmin("index_for_test");
assertNotNull(index);
DataSourceAccessor dsa = new DataSourceAccessor(index, "TypeForTest", "RoutingIdTest");
DataSourceAccessor dsa = new DataSourceAccessor(index, "cell", "RoutingIdTest");
dsa.create("id00001", new HashMap<Object, Object>());
PersoniumSearchResponse response = dsa.search(new HashMap<String, Object>());
assertNotNull(response);
Expand All @@ -150,7 +150,7 @@ public void tearDown() throws Exception {
public void search処理でクエリにサイズを指定した場合指定したサイズのドキュメントが取得できる() {
EsIndex index = esClient.idxAdmin("index_for_test");
assertNotNull(index);
DataSourceAccessor dsa = new DataSourceAccessor(index, "TypeForTest", "RoutingIdTest");
DataSourceAccessor dsa = new DataSourceAccessor(index, "cell", "RoutingIdTest");
dsa.create("id00001", new HashMap<Object, Object>());
dsa.create("id00002", new HashMap<Object, Object>());
dsa.create("id00003", new HashMap<Object, Object>());
Expand All @@ -171,7 +171,7 @@ public void tearDown() throws Exception {
public void search処理でクエリに実データ数以上のサイズを指定した場合実データと同じドキュメント数が取得できる() {
EsIndex index = esClient.idxAdmin("index_for_test");
assertNotNull(index);
DataSourceAccessor dsa = new DataSourceAccessor(index, "TypeForTest", "RoutingIdTest");
DataSourceAccessor dsa = new DataSourceAccessor(index, "cell", "RoutingIdTest");
dsa.create("id00001", new HashMap<Object, Object>());
dsa.create("id00002", new HashMap<Object, Object>());
dsa.create("id00003", new HashMap<Object, Object>());
Expand All @@ -190,7 +190,7 @@ public void tearDown() throws Exception {
public void search処理でクエリにサイズ0を指定した場合0件取得できる() {
EsIndex index = esClient.idxAdmin("index_for_test");
assertNotNull(index);
DataSourceAccessor dsa = new DataSourceAccessor(index, "TypeForTest", "RoutingIdTest");
DataSourceAccessor dsa = new DataSourceAccessor(index, "cell", "RoutingIdTest");
dsa.create("id00001", new HashMap<Object, Object>());
dsa.create("id00002", new HashMap<Object, Object>());
dsa.create("id00003", new HashMap<Object, Object>());
Expand All @@ -209,7 +209,7 @@ public void tearDown() throws Exception {
public void search処理でクエリにnullを指定した場合全件取得できる() {
EsIndex index = esClient.idxAdmin("index_for_test");
assertNotNull(index);
DataSourceAccessor dsa = new DataSourceAccessor(index, "TypeForTest", "RoutingIdTest");
DataSourceAccessor dsa = new DataSourceAccessor(index, "cell", "RoutingIdTest");
dsa.create("id00001", new HashMap<Object, Object>());
dsa.create("id00002", new HashMap<Object, Object>());
dsa.create("id00003", new HashMap<Object, Object>());
Expand All @@ -234,7 +234,7 @@ public void tearDown() throws Exception {
public void search処理でクエリにサイズを指定しなかった場合ドキュメントが全件取得できる() {
EsIndex index = esClient.idxAdmin("index_for_test");
assertNotNull(index);
DataSourceAccessor dsa = new DataSourceAccessor(index, "TypeForTest", "RoutingIdTest");
DataSourceAccessor dsa = new DataSourceAccessor(index, "cell", "RoutingIdTest");

Map<String, String> data = new HashMap<String, String>();
data.put("test", "value");
Expand Down Expand Up @@ -264,7 +264,7 @@ public void tearDown() throws Exception {
public void count処理でクエリにnullを指定した場合全件数取得できる() {
EsIndex index = esClient.idxAdmin("index_for_test");
assertNotNull(index);
DataSourceAccessor dsa = new DataSourceAccessor(index, "TypeForTest", "RoutingIdTest");
DataSourceAccessor dsa = new DataSourceAccessor(index, "cell", "RoutingIdTest");
dsa.create("id00001", new HashMap<Object, Object>());
dsa.create("id00002", new HashMap<Object, Object>());
dsa.create("id00003", new HashMap<Object, Object>());
Expand All @@ -288,7 +288,7 @@ public void tearDown() throws Exception {
public void count処理でクエリに空のクエリを指定した場合全件数取得できる() {
EsIndex index = esClient.idxAdmin("index_for_test");
assertNotNull(index);
DataSourceAccessor dsa = new DataSourceAccessor(index, "TypeForTest", "RoutingIdTest");
DataSourceAccessor dsa = new DataSourceAccessor(index, "cell", "RoutingIdTest");
dsa.create("id00001", new HashMap<Object, Object>());
dsa.create("id00002", new HashMap<Object, Object>());
dsa.create("id00003", new HashMap<Object, Object>());
Expand All @@ -312,7 +312,7 @@ public void tearDown() throws Exception {
public void count処理でクエリに3件ヒットするクエリを指定した場合件数が3で取得できる() {
EsIndex index = esClient.idxAdmin("index_for_test");
assertNotNull(index);
DataSourceAccessor dsa = new DataSourceAccessor(index, "TypeForTest", "RoutingIdTest");
DataSourceAccessor dsa = new DataSourceAccessor(index, "cell", "RoutingIdTest");
Map<String, Object> body = new HashMap<String, Object>();
body.put("sample", "test");
dsa.create("id00001", body);
Expand Down Expand Up @@ -341,7 +341,7 @@ public void tearDown() throws Exception {
public void count処理でクエリに3件ヒットするクエリにサイズ2を指定した場合件数が3で取得できる() {
EsIndex index = esClient.idxAdmin("index_for_test");
assertNotNull(index);
DataSourceAccessor dsa = new DataSourceAccessor(index, "TypeForTest", "RoutingIdTest");
DataSourceAccessor dsa = new DataSourceAccessor(index, "cell", "RoutingIdTest");
Map<String, Object> body = new HashMap<String, Object>();
body.put("sample", "test");
dsa.create("id00001", body);
Expand Down Expand Up @@ -371,7 +371,7 @@ public void tearDown() throws Exception {
public void delete処理が正常に終了する() {
EsIndex index = esClient.idxAdmin("index_for_test");
assertNotNull(index);
DataSourceAccessor dsa = new DataSourceAccessor(index, "TypeForTest", "RoutingIdTest");
DataSourceAccessor dsa = new DataSourceAccessor(index, "cell", "RoutingIdTest");
dsa.create("id00001", new HashMap<Object, Object>());
PersoniumDeleteResponse response = dsa.delete("id00001", -1);
assertNotNull(response);
Expand All @@ -385,7 +385,7 @@ public void tearDown() throws Exception {
public void インデックスが存在しない場合にdelete処理でnullが返却される() {
EsIndex index = esClient.idxAdmin("index_for_test");
assertNotNull(index);
DataSourceAccessor dsa = new DataSourceAccessor(index, "TypeForTest", "RoutingIdTest");
DataSourceAccessor dsa = new DataSourceAccessor(index, "cell", "RoutingIdTest");
PersoniumDeleteResponse response = dsa.delete("id00001", -1);
assertNull(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
public class ODataEntityAccessorTest {

private static final String INDEX_NAME = "index_for_test";
private static final String TYPE_NAME = "TypeForTest";
private static final String TYPE_NAME = "userdata";
private static final String ROUTING_ID = "RoutingIdTest";

private static EsClient esClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1421,8 +1421,8 @@ public MoveCollectionTest() {
DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME,
BOX_NAME + "/" + srcColName + "/__src/" + FILE_NAME, FILE_BODY, MediaType.TEXT_PLAIN,
HttpStatus.SC_CREATED);
DavResourceUtils.setServiceProppatch(TOKEN, HttpStatus.SC_MULTI_STATUS, CELL_NAME, BOX_NAME, srcColName,
FILE_NAME, "test");
DavResourceUtils.setServiceProppatch(CELL_NAME, BOX_NAME, srcColName, TOKEN,
"test", FILE_NAME, HttpStatus.SC_MULTI_STATUS);

// 移動
String srcUrl = UrlUtils.box(CELL_NAME, BOX_NAME, srcColName);
Expand Down
Loading

0 comments on commit b5c0b07

Please sign in to comment.