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/03/12 17:11:43 UTC
[unomi] 01/01: DMF-4342: improve AllEventToProfilePropertiesAction
with new optional configuration: mandatoryPropTypeSystemTag, rootProperty
This is an automated email from the ASF dual-hosted git repository.
jkevan pushed a commit to branch SPIKE-url-parameters-to-profile
in repository https://gitbox.apache.org/repos/asf/unomi.git
commit d9b9563840c125e262811a948995e1d8e6cfbbfa
Author: Kevan <ke...@jahia.com>
AuthorDate: Fri Mar 12 18:11:22 2021 +0100
DMF-4342: improve AllEventToProfilePropertiesAction with new optional configuration: mandatoryPropTypeSystemTag, rootProperty
---
.../actions/AllEventToProfilePropertiesAction.java | 60 +++++++++++++++++-----
.../actions/allEventToProfilePropertiesAction.json | 10 ++++
2 files changed, 58 insertions(+), 12 deletions(-)
diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/AllEventToProfilePropertiesAction.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/AllEventToProfilePropertiesAction.java
index cd538b5..001bc17 100644
--- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/AllEventToProfilePropertiesAction.java
+++ b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/AllEventToProfilePropertiesAction.java
@@ -18,13 +18,16 @@
package org.apache.unomi.plugins.baseplugin.actions;
import org.apache.commons.beanutils.BeanUtilsBean;
+import org.apache.commons.lang3.StringUtils;
import org.apache.unomi.api.Event;
+import org.apache.unomi.api.PropertyType;
import org.apache.unomi.api.actions.Action;
import org.apache.unomi.api.actions.ActionExecutor;
import org.apache.unomi.api.services.EventService;
import org.apache.unomi.api.services.ProfileService;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
public class AllEventToProfilePropertiesAction implements ActionExecutor {
@@ -38,21 +41,25 @@ public class AllEventToProfilePropertiesAction implements ActionExecutor {
@SuppressWarnings({"unchecked", "rawtypes"})
public int execute(Action action, Event event) {
boolean changed = false;
- Map<String, Object> properties = new HashMap<String, Object>();
- if (event.getProperties() != null) {
- properties.putAll(event.getProperties());
- }
+ Map<String, Object> properties = getEventPropsToCopy(action, event);
+ List<String> mandatoryPropTypeSystemTags = (List<String>) action.getParameterValues().get("mandatoryPropTypeSystemTag");
+ for (Map.Entry<String, Object> entry : properties.entrySet()) {
- try {
- Object targetProperties = BeanUtilsBean.getInstance().getPropertyUtils().getProperty(event.getTarget(), "properties");
- if (targetProperties instanceof Map) {
- properties.putAll((Map) targetProperties);
+ // propType Check
+ if (mandatoryPropTypeSystemTags != null && mandatoryPropTypeSystemTags.size() > 0) {
+ PropertyType propertyType = profileService.getPropertyType(entry.getKey());
+ if (propertyType == null ||
+ propertyType.getMetadata() == null ||
+ propertyType.getMetadata().getSystemTags() == null ||
+ !propertyType.getMetadata().getSystemTags().containsAll(mandatoryPropTypeSystemTags)) {
+ continue;
+ }
}
- } catch (Exception e) {
- // Ignore
- }
- for (Map.Entry<String, Object> entry : properties.entrySet()) {
+
+ // TODO: handle multiple values = addValue using PropertyHelper
+ // TODO: handle single value = alwaysSet using PropertyHelper
+ // TODO: check propertyType for value type, string, long, etc...
if (event.getProfile().getProperty(entry.getKey()) == null || !event.getProfile().getProperty(entry.getKey()).equals(event.getProperty(entry.getKey()))) {
String propertyMapping = profileService.getPropertyTypeMapping(entry.getKey());
String propertyName = (propertyMapping != null) ? propertyMapping : entry.getKey();
@@ -62,4 +69,33 @@ public class AllEventToProfilePropertiesAction implements ActionExecutor {
}
return changed ? EventService.PROFILE_UPDATED : EventService.NO_CHANGE;
}
+
+ private Map<String, Object> getEventPropsToCopy(Action action, Event event) {
+ Map<String, Object> propsToCopy = new HashMap<String, Object>();
+
+ String rootProperty = (String) action.getParameterValues().get("rootProperty");
+ boolean copyEventProps = false;
+
+ if (rootProperty == null || rootProperty.length() == 0) {
+ copyEventProps = true;
+ rootProperty = "target.properties";
+ }
+
+ // copy props from the event.properties
+ if (copyEventProps && event.getProperties() != null) {
+ propsToCopy.putAll(event.getProperties());
+ }
+
+ // copy props from the specified level (default is: target.properties)
+ try {
+ Object targetProperties = BeanUtilsBean.getInstance().getPropertyUtils().getProperty(event, rootProperty);
+ if (targetProperties instanceof Map) {
+ propsToCopy.putAll((Map) targetProperties);
+ }
+ } catch (Exception e) {
+ // Ignore
+ }
+
+ return propsToCopy;
+ }
}
diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/allEventToProfilePropertiesAction.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/allEventToProfilePropertiesAction.json
index 35d4ade..4066f27 100644
--- a/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/allEventToProfilePropertiesAction.json
+++ b/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/allEventToProfilePropertiesAction.json
@@ -11,5 +11,15 @@
},
"actionExecutor": "allEventToProfileProperties",
"parameters": [
+ {
+ "id": "rootProperty",
+ "type": "string",
+ "multivalued": false
+ },
+ {
+ "id": "mandatoryPropTypeSystemTag",
+ "type": "string",
+ "multivalued": true
+ }
]
}
\ No newline at end of file