You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by js...@apache.org on 2024/04/24 15:10:12 UTC
(unomi) branch UNOMI-817 updated (63e88a215 -> 1eabd5126)
This is an automated email from the ASF dual-hosted git repository.
jsinovassinnaik pushed a change to branch UNOMI-817
in repository https://gitbox.apache.org/repos/asf/unomi.git
discard 63e88a215 fix tests
new 1eabd5126 fix tests
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (63e88a215)
\
N -- N -- N refs/heads/UNOMI-817 (1eabd5126)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../java/org/apache/unomi/rest/endpoints/SegmentServiceEndPoint.java | 2 --
1 file changed, 2 deletions(-)
(unomi) 01/01: fix tests
Posted by js...@apache.org.
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
commit 1eabd5126444f4d6e4e1039f68043ad2b3840096
Author: jsinovassin <js...@jahia.com>
AuthorDate: Wed Apr 24 10:56:52 2024 +0200
fix tests
---
.../java/org/apache/unomi/itests/SegmentIT.java | 10 ++---
.../actions/SetEventOccurenceCountAction.java | 10 +++--
.../PastEventConditionESQueryBuilder.java | 45 ++++++++++++++++------
3 files changed, 45 insertions(+), 20 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..59375b8c9 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").equals(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) {
@@ -562,8 +561,9 @@ public class SegmentIT extends BaseIT {
// insure the profile is still engaged after recalculate;
keepTrying("Profile should have 2 events in the scoring", () -> profileService.load("test_profile_id"), updatedProfile -> {
try {
- boolean eventCounted = (Integer) ((Map) updatedProfile.getSystemProperties().get("pastEvents"))
- .get(pastEventCondition.getParameterValues().get("generatedPropertyKey")) == 2;
+ Map<String, Object> pastEvent = ((List<Map<String, Object>>)updatedProfile.getSystemProperties().get("pastEvents")).stream().filter(profilePastEvent -> profilePastEvent.get("key").equals(pastEventCondition.getParameterValues().get("generatedPropertyKey"))).findFirst().get();
+
+ boolean eventCounted = (Integer) pastEvent.get("count") == 2;
boolean profileEngaged = updatedProfile.getScores().containsKey("past-event-scoring-test")
&& updatedProfile.getScores().get("past-event-scoring-test") == 50;
return eventCounted && profileEngaged;
diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetEventOccurenceCountAction.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetEventOccurenceCountAction.java
index 2b195227f..e70922d04 100644
--- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetEventOccurenceCountAction.java
+++ b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetEventOccurenceCountAction.java
@@ -30,6 +30,7 @@ import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
+import java.util.stream.Collectors;
import javax.xml.bind.DatatypeConverter;
@@ -128,11 +129,12 @@ public class SetEventOccurenceCountAction implements ActionExecutor {
}
private boolean updatePastEvents(Event event, String generatedPropertyKey, long count) {
- ArrayList<Map<String, Object>> pastEvents = (ArrayList<Map<String, Object>>) event.getProfile().getSystemProperties().get("pastEvents");
- if (pastEvents == null) {
- pastEvents = new ArrayList<>();
+ ArrayList<Map<String, Object>> pastEvents = new ArrayList<>();
+ ArrayList<Map<String, Object>> existingPastEvents = (ArrayList<Map<String, Object>>) event.getProfile().getSystemProperties().get("pastEvents");
+ if (existingPastEvents != null) {
+ pastEvents.addAll(existingPastEvents.stream().filter(pastEvent -> !pastEvent.get("key").equals(generatedPropertyKey)).collect(Collectors.toList()));
}
- pastEvents.removeIf(pastEvent -> pastEvent.get("key").equals(generatedPropertyKey));
+
Map<String, Object> pastEvent = new HashMap<>();
pastEvent.put("key", generatedPropertyKey);
pastEvent.put("count", count);
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..772be5f71 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
@@ -138,10 +138,7 @@ public class PastEventConditionESQueryBuilder implements ConditionESQueryBuilder
Condition subConditionCount = new Condition(definitionsService.getConditionType("profilePropertyCondition"));
- Condition subConditionKey = new Condition(definitionsService.getConditionType("profilePropertyCondition"));
- subConditionKey.setParameter("propertyName", "systemProperties.pastEvents.key");
- subConditionKey.setParameter("comparisonOperator", "equals");
- subConditionKey.setParameter("propertyValue", generatedPropertyKey);
+ Condition subConditionKey = getKeyEqualsCondition(generatedPropertyKey);
ConditionType profilePropertyConditionType = definitionsService.getConditionType("profilePropertyCondition");
if (eventsOccurred) {
@@ -154,12 +151,26 @@ 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");
@@ -169,14 +180,26 @@ public class PastEventConditionESQueryBuilder implements ConditionESQueryBuilder
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 Condition getKeyEqualsCondition(String generatedPropertyKey) {
+ Condition subConditionKey = new Condition(definitionsService.getConditionType("profilePropertyCondition"));
+ subConditionKey.setParameter("propertyName", "systemProperties.pastEvents.key");
+ subConditionKey.setParameter("comparisonOperator", "equals");
+ subConditionKey.setParameter("propertyValue", generatedPropertyKey);
+ return subConditionKey;
}
private Set<String> getProfileIdsMatchingEventCount(Condition eventCondition, int minimumEventCount, int maximumEventCount) {