You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by jk...@apache.org on 2021/10/12 12:13:40 UTC

[unomi] branch master updated: UNOMI-515: allow event to be evaluated by the sourceEventPropertyConditionEvaluator (#351)

This is an automated email from the ASF dual-hosted git repository.

jkevan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git


The following commit(s) were added to refs/heads/master by this push:
     new c6a7fa5  UNOMI-515: allow event to be evaluated by the sourceEventPropertyConditionEvaluator (#351)
c6a7fa5 is described below

commit c6a7fa568a5f16ad35f1f6c3187964933300408a
Author: kevan Jahanshahi <ke...@jahia.com>
AuthorDate: Tue Oct 12 14:13:36 2021 +0200

    UNOMI-515: allow event to be evaluated by the sourceEventPropertyConditionEvaluator (#351)
---
 .../SourceEventPropertyConditionEvaluator.java           | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/SourceEventPropertyConditionEvaluator.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/SourceEventPropertyConditionEvaluator.java
index 98669dd..19bbca7 100644
--- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/SourceEventPropertyConditionEvaluator.java
+++ b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/SourceEventPropertyConditionEvaluator.java
@@ -17,6 +17,7 @@
 
 package org.apache.unomi.plugins.baseplugin.conditions;
 
+import org.apache.unomi.api.Event;
 import org.apache.unomi.api.Item;
 import org.apache.unomi.api.conditions.Condition;
 import org.apache.unomi.api.conditions.ConditionType;
@@ -54,6 +55,11 @@ public class SourceEventPropertyConditionEvaluator implements ConditionEvaluator
 
     @Override
     public boolean eval(Condition condition, Item item, Map<String, Object> context, ConditionEvaluatorDispatcher dispatcher) {
+        // in case the evaluated item is an event, we switch to his source internal object for further evaluations
+        if (item instanceof Event) {
+            item = ((Event) item).getSource();
+        }
+
         Condition andCondition = new Condition(definitionsService.getConditionType("booleanCondition"));
         andCondition.setParameter("operator", "and");
         ArrayList<Condition> conditions = new ArrayList<Condition>();
@@ -63,9 +69,15 @@ public class SourceEventPropertyConditionEvaluator implements ConditionEvaluator
         }
 
         if(conditions.size() > 0){
-            andCondition.setParameter("subConditions", conditions);
-            return dispatcher.eval(andCondition, item);
+            if (item != null) {
+                andCondition.setParameter("subConditions", conditions);
+                return dispatcher.eval(andCondition, item);
+            } else {
+                // item is null but there is conditions: it's not a match
+                return false;
+            }
         } else {
+            // no conditions: it's always a match
             return true;
         }
     }