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 12:27:11 UTC
[unomi] branch unomi-1.6.x updated: UNOMI-518 : improve tracked
conditions parameter resolution (#356)
This is an automated email from the ASF dual-hosted git repository.
dgriffon pushed a commit to branch unomi-1.6.x
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/unomi-1.6.x by this push:
new b96cf75 UNOMI-518 : improve tracked conditions parameter resolution (#356)
b96cf75 is described below
commit b96cf75a2f0499fc7f4dca84468313158d6a5e02
Author: David Griffon <dg...@jahia.com>
AuthorDate: Wed Oct 27 14:26:18 2021 +0200
UNOMI-518 : improve tracked conditions parameter resolution (#356)
---
.../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 4319990..b851cc6 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;
@@ -415,12 +415,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) {