jsinovassin commented on code in PR #659:
URL: https://github.com/apache/unomi/pull/659#discussion_r1611228027


##########
plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/PastEventConditionESQueryBuilder.java:
##########
@@ -122,44 +128,42 @@ protected static boolean getStrategyFromOperator(String 
operator) {
         return operator == null || operator.equals("eventsOccurred");
     }
 
-    private Condition getProfileIdsCondition(Set<String> ids, boolean 
shouldMatch) {
-        Condition idsCondition = new Condition();
-        
idsCondition.setConditionType(definitionsService.getConditionType("idsCondition"));
-        idsCondition.setParameter("ids", ids);
-        idsCondition.setParameter("match", shouldMatch);
-        return idsCondition;
-    }
-
     private Condition getProfileConditionForCounter(String 
generatedPropertyKey, Integer minimumEventCount, Integer maximumEventCount, 
boolean eventsOccurred) {
-        String generatedPropertyName = "systemProperties.pastEvents." + 
generatedPropertyKey;
-        ConditionType profilePropertyConditionType = 
definitionsService.getConditionType("profilePropertyCondition");
         if (eventsOccurred) {
-            Condition counterIsBetweenBoundaries = new Condition();
-            
counterIsBetweenBoundaries.setConditionType(profilePropertyConditionType);
-            counterIsBetweenBoundaries.setParameter("propertyName", 
generatedPropertyName);
-            counterIsBetweenBoundaries.setParameter("comparisonOperator", 
"between");
-            counterIsBetweenBoundaries.setParameter("propertyValuesInteger", 
Arrays.asList(minimumEventCount, maximumEventCount));
-            return counterIsBetweenBoundaries;
+            return createEventOccurredCondition(generatedPropertyKey, 
minimumEventCount, maximumEventCount);
         } else {
-            Condition counterMissing = new Condition();
-            counterMissing.setConditionType(profilePropertyConditionType);
-            counterMissing.setParameter("propertyName", generatedPropertyName);
-            counterMissing.setParameter("comparisonOperator", "missing");
-
-            Condition counterZero = new Condition();
-            counterZero.setConditionType(profilePropertyConditionType);
-            counterZero.setParameter("propertyName", generatedPropertyName);
-            counterZero.setParameter("comparisonOperator", "equals");
-            counterZero.setParameter("propertyValueInteger", 0);
-
-            Condition counterCondition = new Condition();
-            
counterCondition.setConditionType(definitionsService.getConditionType("booleanCondition"));
-            counterCondition.setParameter("operator", "or");
-            counterCondition.setParameter("subConditions", 
Arrays.asList(counterMissing, counterZero));
-            return counterCondition;
+            return createEventNotOccurredCondition(generatedPropertyKey);
         }
     }
 
+    private Condition createEventOccurredCondition(String 
generatedPropertyKey, Integer minimumEventCount, Integer maximumEventCount) {
+        Condition subConditionCount = 
conditionHelper.createProfilePropertyCondition("systemProperties.pastEvents.count",
 "between", Arrays.asList(minimumEventCount, maximumEventCount), 
"propertyValuesInteger");
+        Condition subConditionKey = 
conditionHelper.createProfilePropertyCondition("systemProperties.pastEvents.key",
 "equals", generatedPropertyKey, "propertyValue");
+
+        Condition booleanCondition = 
conditionHelper.createBooleanCondition("and", Arrays.asList(subConditionCount, 
subConditionKey));
+        return 
conditionHelper.createNestedCondition("systemProperties.pastEvents", 
booleanCondition);
+    }
+
+    private Condition createEventNotOccurredCondition(String 
generatedPropertyKey) {
+        Condition pastEventsNotExist = 
createPastEventMustNotExistCondition(generatedPropertyKey);
+        Condition counterZero = 
conditionHelper.createProfilePropertyCondition("systemProperties.pastEvents.count",
 "equals", 0, "propertyValueInteger");
+        Condition keyEquals = 
conditionHelper.createProfilePropertyCondition("systemProperties.pastEvents.key",
 "equals", generatedPropertyKey, "propertyValue");
+        Condition keyExistsAndCounterZero = 
conditionHelper.createBooleanCondition("and", Arrays.asList(keyEquals, 
counterZero));
+        Condition nestedKeyExistsAndCounterZero = 
conditionHelper.createNestedCondition("systemProperties.pastEvents", 
keyExistsAndCounterZero);
+
+        return conditionHelper.createBooleanCondition("or", 
Arrays.asList(pastEventsNotExist, nestedKeyExistsAndCounterZero));

Review Comment:
   It was part of my first implementation, but the results of the request was 
not the expected result. So I changed to have two nested conditions. 
   I tried again to after the refacto of the condition builder, you can find 
the implementation in another PR https://github.com/apache/unomi/pull/664, 
especially this commit: 
https://github.com/apache/unomi/pull/664/commits/1f0230bb6b8713b9bf98ead48a1c2db000f9073c
   but it's not working.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to