This is an automated email from the ASF dual-hosted git repository.
jsinovassinnaik pushed a commit to branch UNOMI-817
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/UNOMI-817 by this push:
new d3a3bd1b0 fix tests
d3a3bd1b0 is described below
commit d3a3bd1b0cb17eec28820bcfe3cdf53d3b237a43
Author: jsinovassin <[email protected]>
AuthorDate: Wed Apr 24 10:56:52 2024 +0200
fix tests
---
.../java/org/apache/unomi/itests/SegmentIT.java | 5 ++--
.../PastEventConditionESQueryBuilder.java | 33 +++++++++++++++++-----
.../rest/endpoints/SegmentServiceEndPoint.java | 2 ++
3 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
b/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
index 3b3aa9314..414b163bb 100644
--- a/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
@@ -547,9 +547,8 @@ public class SegmentIT extends BaseIT {
// insure the profile is engaged;
try {
- Assert.assertTrue("Profile should have 2 events in the scoring",
- (Long) ((Map)
testEvent.getProfile().getSystemProperties().get("pastEvents"))
-
.get(pastEventCondition.getParameterValues().get("generatedPropertyKey")) == 2);
+ Map<String, Object> pastEvent = ((List<Map<String,
Object>>)testEvent.getProfile().getSystemProperties().get("pastEvents")).stream().filter(profilePastEvent
-> profilePastEvent.get("key") ==
pastEventCondition.getParameterValues().get("generatedPropertyKey")).findFirst().get();
+ Assert.assertEquals("Profile should have 2 events in the scoring",
2, (long) pastEvent.get("count"));
Assert.assertTrue("Profile is engaged",
testEvent.getProfile().getScores().containsKey("past-event-scoring-test")
&&
testEvent.getProfile().getScores().get("past-event-scoring-test") == 50);
} catch (Exception e) {
diff --git
a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/PastEventConditionESQueryBuilder.java
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/PastEventConditionESQueryBuilder.java
index 28e8c1939..38a109c95 100644
---
a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/PastEventConditionESQueryBuilder.java
+++
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/PastEventConditionESQueryBuilder.java
@@ -154,29 +154,48 @@ public class PastEventConditionESQueryBuilder implements
ConditionESQueryBuilder
booleanCondition.setParameter("subConditions",
Arrays.asList(subConditionCount, subConditionKey));
countCondition.setParameter("subCondition", booleanCondition);
+ return countCondition;
+
} else {
- Condition keyMissing = new Condition(profilePropertyConditionType);
- keyMissing.setParameter("propertyName",
"systemProperties.pastEvents.key");
- keyMissing.setParameter("comparisonOperator", "missing");
- keyMissing.setParameter("propertyValue", generatedPropertyKey);
+ // 1. Key not present in profile
+ Condition keyNestedCondition = new Condition();
+
keyNestedCondition.setConditionType(definitionsService.getConditionType("nestedCondition"));
+ keyNestedCondition.setParameter("path",
"systemProperties.pastEvents");
+
+ Condition keyEquals = new Condition(profilePropertyConditionType);
+ keyEquals.setParameter("propertyName",
"systemProperties.pastEvents.key");
+ keyEquals.setParameter("comparisonOperator", "equals");
+ keyEquals.setParameter("propertyValue", generatedPropertyKey);
+
+ keyNestedCondition.setParameter("subCondition", keyEquals);
+
+ Condition mustNotExist = new
Condition(definitionsService.getConditionType("notCondition"));
+ mustNotExist.setParameter("subCondition", keyNestedCondition);
+
+ // 2. Key present in profile but value equals to 0
Condition counterZero = new
Condition(profilePropertyConditionType);
counterZero.setParameter("propertyName",
"systemProperties.pastEvents.count");
counterZero.setParameter("comparisonOperator", "equals");
counterZero.setParameter("propertyValueInteger", 0);
+
Condition keyExistsAndCounterZero = new
Condition(definitionsService.getConditionType("booleanCondition"));
keyExistsAndCounterZero.setParameter("operator", "and");
keyExistsAndCounterZero.setParameter("subConditions",
Arrays.asList(subConditionKey, counterZero));
+ Condition nestedKeyExistsAndCounterZero = new Condition();
+
nestedKeyExistsAndCounterZero.setConditionType(definitionsService.getConditionType("nestedCondition"));
+ nestedKeyExistsAndCounterZero.setParameter("path",
"systemProperties.pastEvents");
+ nestedKeyExistsAndCounterZero.setParameter("subCondition",
keyExistsAndCounterZero);
+
Condition counterCondition = new Condition();
counterCondition.setConditionType(definitionsService.getConditionType("booleanCondition"));
counterCondition.setParameter("operator", "or");
- counterCondition.setParameter("subConditions",
Arrays.asList(keyMissing, keyExistsAndCounterZero));
+ counterCondition.setParameter("subConditions",
Arrays.asList(mustNotExist, nestedKeyExistsAndCounterZero));
- countCondition.setParameter("subCondition", counterCondition);
+ return counterCondition;
}
- return countCondition;
}
private Set<String> getProfileIdsMatchingEventCount(Condition
eventCondition, int minimumEventCount, int maximumEventCount) {
diff --git
a/rest/src/main/java/org/apache/unomi/rest/endpoints/SegmentServiceEndPoint.java
b/rest/src/main/java/org/apache/unomi/rest/endpoints/SegmentServiceEndPoint.java
index 3cd547598..fbf854ecb 100644
---
a/rest/src/main/java/org/apache/unomi/rest/endpoints/SegmentServiceEndPoint.java
+++
b/rest/src/main/java/org/apache/unomi/rest/endpoints/SegmentServiceEndPoint.java
@@ -171,6 +171,8 @@ public class SegmentServiceEndPoint {
@GET
@Path("/{segmentID}")
public Segment getSegmentDefinition(@PathParam("segmentID") String
segmentId) {
+
+ segmentService.recalculatePastEventConditions();
return segmentService.getSegmentDefinition(segmentId);
}