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

[unomi] branch UNOMI-518-improve-tracked-conditions created (now b3938b7)

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

dgriffon pushed a change to branch UNOMI-518-improve-tracked-conditions
in repository https://gitbox.apache.org/repos/asf/unomi.git.


      at b3938b7  UNOMI-518 : improve tracked conditions parameter resolution

This branch includes the following new commits:

     new b3938b7  UNOMI-518 : improve tracked conditions parameter resolution

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.


[unomi] 01/01: UNOMI-518 : improve tracked conditions parameter resolution

Posted by dg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dgriffon pushed a commit to branch UNOMI-518-improve-tracked-conditions
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit b3938b7d7afc4a40880cb9957b7254bd4d48f636
Author: David Griffon <dg...@jahia.com>
AuthorDate: Wed Oct 27 12:35:51 2021 +0200

    UNOMI-518 : improve tracked conditions parameter resolution
---
 .../java/org/apache/unomi/itests/RuleServiceIT.java |  6 ++++--
 .../src/test/resources/testClickEventCondition.json | 19 ++++++++++++++++---
 .../unomi/services/impl/rules/RulesServiceImpl.java | 21 ++++++++++++++++-----
 3 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/itests/src/test/java/org/apache/unomi/itests/RuleServiceIT.java b/itests/src/test/java/org/apache/unomi/itests/RuleServiceIT.java
index b8519f8..67d30e5 100644
--- a/itests/src/test/java/org/apache/unomi/itests/RuleServiceIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/RuleServiceIT.java
@@ -196,14 +196,16 @@ public class RuleServiceIT extends BaseIT {
             ConditionBuilder builder = new ConditionBuilder(definitionsService);
             Rule trackParameterRule = new Rule(new Metadata(TEST_SCOPE, "tracked-parameter-rule", "Tracked parameter rule", "A rule with tracked parameter"));
             Condition trackedCondition = builder.condition("clickEventCondition").build();
-            trackedCondition.setParameter("tracked_properties_pageInfo_pagePath", "/test-page.html");
+            trackedCondition.setParameter("path", "/test-page.html");
+            trackedCondition.setParameter("referrer", "https://unomi.apache.org");
             trackedCondition.getConditionType().getMetadata().getSystemTags().add("trackedCondition");
             trackParameterRule.setCondition(trackedCondition);
             rulesService.setRule(trackParameterRule);
             // Add rule that has a trackParameter condition that does not match
             Rule unTrackParameterRule = new Rule(new Metadata(TEST_SCOPE, "not-tracked-parameter-rule", "Not Tracked parameter rule", "A rule that has a parameter not tracked"));
             Condition unTrackedCondition = builder.condition("clickEventCondition").build();
-            unTrackedCondition.setParameter("tracked_properties_pageInfo_pagePath", "/test-page-that-does-not-exist.html");
+            unTrackedCondition.setParameter("path", "/test-page.html");
+            unTrackedCondition.setParameter("referrer", "https://localhost");
             unTrackedCondition.getConditionType().getMetadata().getSystemTags().add("trackedCondition");
             unTrackParameterRule.setCondition(unTrackedCondition);
             rulesService.setRule(unTrackParameterRule);
diff --git a/itests/src/test/resources/testClickEventCondition.json b/itests/src/test/resources/testClickEventCondition.json
index 4cb5646..c38903d 100644
--- a/itests/src/test/resources/testClickEventCondition.json
+++ b/itests/src/test/resources/testClickEventCondition.json
@@ -26,9 +26,11 @@
           }
         },
         {
-          "type": "sourceEventPropertyCondition",
+          "type": "eventPropertyCondition",
           "parameterValues": {
-            "path": "parameter::tracked_properties_pageInfo_pagePath"
+            "propertyName": "source.properties.pageInfo.pagePath",
+            "propertyValue": "parameter::path",
+            "comparisonOperator": "equals"
           }
         },
         {
@@ -45,11 +47,22 @@
   },
   "parameters": [
     {
-      "id": "tracked_properties_pageInfo_pagePath",
+      "id": "path",
       "type": "string",
       "multivalued": false
     },
     {
+      "id": "referrer",
+      "type": "string",
+      "multivalued": false
+    },
+    {
+      "id": "trackedConditionParameters",
+      "type": "string",
+      "multivalued": false,
+      "defaultValue": "path:properties.pageInfo.pagePath,referrer:properties.pageInfo.referringURL"
+    },
+    {
       "id": "itemId",
       "type": "string",
       "multivalued": false
diff --git a/services/src/main/java/org/apache/unomi/services/impl/rules/RulesServiceImpl.java b/services/src/main/java/org/apache/unomi/services/impl/rules/RulesServiceImpl.java
index fbf4710..fc8e464 100644
--- a/services/src/main/java/org/apache/unomi/services/impl/rules/RulesServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/impl/rules/RulesServiceImpl.java
@@ -46,7 +46,7 @@ import java.util.concurrent.TimeUnit;
 public class RulesServiceImpl implements RulesService, EventListenerService, SynchronousBundleListener {
 
     public static final String RULE_QUERY_PREFIX = "rule_";
-    public static final String TRACKED_PARAMETER_PREFIX = "tracked_";
+    public static final String TRACKED_PARAMETER = "trackedConditionParameters";
     private static final Logger logger = LoggerFactory.getLogger(RulesServiceImpl.class.getName());
 
     private BundleContext bundleContext;
@@ -410,12 +410,23 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn
                     if (persistenceService.testMatch(evalCondition, source)) {
                         trackedConditions.add(trackedCondition);
                     }
-                } else {
+                } else if (
+                        trackedCondition.getConditionType() != null &&
+                        trackedCondition.getConditionType().getParameters() != null &&
+                        trackedCondition.getConditionType().getParameters().size() > 0
+                ) {
                     // lookup for track parameters
                     Map<String, Object> trackedParameters = new HashMap<>();
-                    trackedCondition.getParameterValues().forEach((key, value) -> {
-                        if (!TRACKED_PARAMETER_PREFIX.equals(key) && StringUtils.startsWith(key, TRACKED_PARAMETER_PREFIX)) {
-                            trackedParameters.put(StringUtils.replace(StringUtils.substringAfter(key, TRACKED_PARAMETER_PREFIX), "_", "."), value);
+                    trackedCondition.getConditionType().getParameters().forEach(parameter -> {
+                        try {
+                        if (TRACKED_PARAMETER.equals(parameter.getId())) {
+                            Arrays.stream(StringUtils.split(parameter.getDefaultValue(), ",")).forEach(trackedParameter -> {
+                                    String[] param = StringUtils.split(StringUtils.trim(trackedParameter), ":");
+                                    trackedParameters.put(StringUtils.trim(param[1]), trackedCondition.getParameter(StringUtils.trim(param[0])));
+                            });
+                        }
+                        } catch (Exception e) {
+                            logger.warn("Unable to parse tracked parameter from {} for condition type {}", parameter, trackedCondition.getConditionType().getItemId());
                         }
                     });
                     if (trackedParameters.size() > 0) {