Repository: incubator-unomi Updated Branches: refs/heads/master e68f617bf -> e25c3f903
UNOMI-117 fix issue with condition type searched by tag, move to system tag Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/e25c3f90 Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/e25c3f90 Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/e25c3f90 Branch: refs/heads/master Commit: e25c3f903001cab6b96d8d88f02f942656077782 Parents: e68f617 Author: dgaillard <[email protected]> Authored: Mon Oct 9 17:11:18 2017 +0200 Committer: dgaillard <[email protected]> Committed: Mon Oct 9 17:11:18 2017 +0200 ---------------------------------------------------------------------- .../unomi/api/services/DefinitionsService.java | 13 ++++++++ .../services/DefinitionsServiceImpl.java | 35 ++++++++++++++++++++ .../services/services/ProfileServiceImpl.java | 4 +-- .../services/services/RulesServiceImpl.java | 14 ++++---- .../services/services/SegmentServiceImpl.java | 2 +- .../shell/migration/impl/MigrationTo130.java | 15 +++------ 6 files changed, 62 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/e25c3f90/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java b/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java index f3d0afd..f24813d 100644 --- a/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java +++ b/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java @@ -182,9 +182,22 @@ public interface DefinitionsService { * @param tag * @return */ + @Deprecated Condition extractConditionByTag(Condition rootCondition, String tag); /** + * Retrieves a condition matching the specified tag identifier from the specified root condition. + * + * TODO: remove from API and move to a different class? + * TODO: purpose and behavior not clear + * + * @param rootCondition + * @param tag + * @return + */ + Condition extractConditionBySystemTag(Condition rootCondition, String tag); + + /** * Resolves (if possible) the {@link ConditionType}s for the specified condition and its sub-conditions (if any) from the type identifiers existing on the specified condition * * TODO: remove from API and move to a different class? http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/e25c3f90/services/src/main/java/org/apache/unomi/services/services/DefinitionsServiceImpl.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/apache/unomi/services/services/DefinitionsServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/DefinitionsServiceImpl.java index 583cbc5..d35288d 100644 --- a/services/src/main/java/org/apache/unomi/services/services/DefinitionsServiceImpl.java +++ b/services/src/main/java/org/apache/unomi/services/services/DefinitionsServiceImpl.java @@ -368,6 +368,7 @@ public class DefinitionsServiceImpl implements DefinitionsService, SynchronousBu } } + @Deprecated public Condition extractConditionByTag(Condition rootCondition, String tag) { if (rootCondition.containsParameter("subConditions")) { @SuppressWarnings("unchecked") @@ -402,6 +403,40 @@ public class DefinitionsServiceImpl implements DefinitionsService, SynchronousBu } } + public Condition extractConditionBySystemTag(Condition rootCondition, String systemTag) { + if (rootCondition.containsParameter("subConditions")) { + @SuppressWarnings("unchecked") + List<Condition> subConditions = (List<Condition>) rootCondition.getParameter("subConditions"); + List<Condition> matchingConditions = new ArrayList<Condition>(); + for (Condition condition : subConditions) { + Condition c = extractConditionBySystemTag(condition, systemTag); + if (c != null) { + matchingConditions.add(c); + } + } + if (matchingConditions.size() == 0) { + return null; + } else if (matchingConditions.equals(subConditions)) { + return rootCondition; + } else if (rootCondition.getConditionTypeId().equals("booleanCondition") && "and".equals(rootCondition.getParameter("operator"))) { + if (matchingConditions.size() == 1) { + return matchingConditions.get(0); + } else { + Condition res = new Condition(); + res.setConditionType(getConditionType("booleanCondition")); + res.setParameter("operator", "and"); + res.setParameter("subConditions", matchingConditions); + return res; + } + } + throw new IllegalArgumentException(); + } else if (rootCondition.getConditionType() != null && rootCondition.getConditionType().getMetadata().getSystemTags().contains(systemTag)) { + return rootCondition; + } else { + return null; + } + } + @Override public boolean resolveConditionType(Condition rootCondition) { return ParserHelper.resolveConditionType(this, rootCondition); http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/e25c3f90/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java index 746dceb..5ec9ceb 100644 --- a/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java +++ b/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java @@ -583,8 +583,8 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList } return subConditions.size() > 0 && isAnd; } else { - Condition profileCondition = definitionsService.extractConditionByTag(condition, "profileCondition"); - Condition sessionCondition = definitionsService.extractConditionByTag(condition, "sessionCondition"); + Condition profileCondition = definitionsService.extractConditionBySystemTag(condition, "profileCondition"); + Condition sessionCondition = definitionsService.extractConditionBySystemTag(condition, "sessionCondition"); if (profileCondition != null && !persistenceService.testMatch(profileCondition, profile)) { return false; } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/e25c3f90/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java index 8c848a4..16d8d5d 100644 --- a/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java +++ b/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java @@ -178,7 +178,7 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn long ruleConditionStartTime = System.currentTimeMillis(); String scope = rule.getMetadata().getScope(); if (scope.equals(Metadata.SYSTEM_SCOPE) || scope.equals(event.getScope())) { - Condition eventCondition = definitionsService.extractConditionByTag(rule.getCondition(), "eventCondition"); + Condition eventCondition = definitionsService.extractConditionBySystemTag(rule.getCondition(), "eventCondition"); if (eventCondition == null) { updateRuleStatistics(ruleStatistics, ruleConditionStartTime); @@ -190,7 +190,7 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn continue; } - Condition sourceCondition = definitionsService.extractConditionByTag(rule.getCondition(), "sourceEventCondition"); + Condition sourceCondition = definitionsService.extractConditionBySystemTag(rule.getCondition(), "sourceEventCondition"); if (sourceCondition != null && !persistenceService.testMatch(sourceCondition, event.getSource())) { updateRuleStatistics(ruleStatistics, ruleConditionStartTime); continue; @@ -210,12 +210,12 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn } } - Condition profileCondition = definitionsService.extractConditionByTag(rule.getCondition(), "profileCondition"); + Condition profileCondition = definitionsService.extractConditionBySystemTag(rule.getCondition(), "profileCondition"); if (profileCondition != null && !persistenceService.testMatch(profileCondition, event.getProfile())) { updateRuleStatistics(ruleStatistics, ruleConditionStartTime); continue; } - Condition sessionCondition = definitionsService.extractConditionByTag(rule.getCondition(), "sessionCondition"); + Condition sessionCondition = definitionsService.extractConditionBySystemTag(rule.getCondition(), "sessionCondition"); if (sessionCondition != null && !persistenceService.testMatch(sessionCondition, event.getSession())) { updateRuleStatistics(ruleStatistics, ruleConditionStartTime); continue; @@ -340,7 +340,7 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn if (condition != null) { if (rule.getMetadata().isEnabled() && !rule.getMetadata().isMissingPlugins()) { ParserHelper.resolveConditionType(definitionsService, condition); - definitionsService.extractConditionByTag(condition, "eventCondition"); + definitionsService.extractConditionBySystemTag(condition, "eventCondition"); } } persistenceService.save(rule); @@ -352,9 +352,9 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn if (!r.getMetadata().isEnabled()) { continue; } - Condition trackedCondition = definitionsService.extractConditionByTag(r.getCondition(), "trackedCondition"); + Condition trackedCondition = definitionsService.extractConditionBySystemTag(r.getCondition(), "trackedCondition"); if(trackedCondition != null){ - Condition sourceEventPropertyCondition = definitionsService.extractConditionByTag(r.getCondition(), "sourceEventCondition"); + Condition sourceEventPropertyCondition = definitionsService.extractConditionBySystemTag(r.getCondition(), "sourceEventCondition"); if(source != null && sourceEventPropertyCondition != null) { ParserHelper.resolveConditionType(definitionsService, sourceEventPropertyCondition); if(persistenceService.testMatch(sourceEventPropertyCondition, source)){ http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/e25c3f90/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java index 47eda18..bc4cdf7 100644 --- a/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java +++ b/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java @@ -728,7 +728,7 @@ public class SegmentServiceImpl extends AbstractServiceImpl implements SegmentSe } private void getAutoGeneratedRules(Metadata metadata, Condition condition, Condition parentCondition, List<Rule> rules) { - Set<String> tags = condition.getConditionType().getMetadata().getTags(); + Set<String> tags = condition.getConditionType().getMetadata().getSystemTags(); if (tags.contains("eventCondition") && !tags.contains("profileCondition")) { try { Map<String, Object> m = new HashMap<>(3); http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/e25c3f90/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo130.java ---------------------------------------------------------------------- diff --git a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo130.java b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo130.java index bb252f6..c596175 100644 --- a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo130.java +++ b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo130.java @@ -65,12 +65,8 @@ public class MigrationTo130 implements Migration { private void migrateTags() throws IOException { initTagsStructurePriorTo130(); String hostAddress = ConsoleUtils.askUserWithDefaultAnswer(session, "Host address (default = http://localhost:9200): ", "http://localhost:9200"); - String tagsOperation = ConsoleUtils.askUserWithAuthorizedAnswer(session, "How to manage tags?\nno change: will keep tags in tags property\ncopy: will duplicate tags in systemTags property\nmove: will move tags in systemTags property\n(default/copy/move): ", Arrays.asList("no change", "copy", "move")); - - String removeNamespaceOnSystemTags = "no"; - if (tagsOperation.equals("copy") || tagsOperation.equals("move")) { - removeNamespaceOnSystemTags = ConsoleUtils.askUserWithAuthorizedAnswer(session,"As we will copy/move the tags, do you wish to remove existing namespace on tags before copy/move in systemTags? (e.g: hidden.) (yes/no): ", Arrays.asList("yes", "no")); - } + String tagsOperation = ConsoleUtils.askUserWithAuthorizedAnswer(session, "How to manage tags?\n1. copy: will duplicate tags in systemTags property\n2. move: will move tags in systemTags property\n[1 - 2]: ", Arrays.asList("1", "2")); + String removeNamespaceOnSystemTags = ConsoleUtils.askUserWithAuthorizedAnswer(session,"As we will copy/move the tags, do you wish to remove existing namespace on tags before copy/move in systemTags? (e.g: hidden.) (yes/no): ", Arrays.asList("yes", "no")); List<String> typeToMigrate = Arrays.asList("actionType", "conditionType", "campaign", "goal", "rule", "scoring", "segment", "userList"); for (String type : typeToMigrate) { @@ -145,15 +141,12 @@ public class MigrationTo130 implements Migration { } updatedHits.append("{\"update\":{\"_id\":\"").append(hitId).append("\"}}\n"); - if (tagsOperation.equals("no change")) { - updatedHits.append("{\"doc\":{\"metadata\":{\"tags\":").append(new JSONArray(tagsAfterMigration)).append("}}}\n"); - } - if (tagsOperation.equals("copy")) { + if (tagsOperation.equals("1")) { Set<String> tags = removeNamespaceOnTags(removeNamespaceOnSystemTags, tagsAfterMigration); updatedHits.append("{\"doc\":{\"metadata\":{\"tags\":").append(new JSONArray(tagsAfterMigration)) .append(",\"systemTags\":").append(new JSONArray(tags)).append("}}}\n"); } - if (tagsOperation.equals("move")) { + if (tagsOperation.equals("2")) { Set<String> tags = removeNamespaceOnTags(removeNamespaceOnSystemTags, tagsAfterMigration); updatedHits.append("{\"doc\":{\"metadata\":{\"systemTags\":").append(new JSONArray(tags)).append("}}}\n"); if (tagsInMetadata) {
