Repository: incubator-unomi Updated Branches: refs/heads/master 64d109ef1 -> b33cdaee6
UNOMI-129 : Modify SetPropertyAction to use UpdateProfilePropertiesAction Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/b33cdaee Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/b33cdaee Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/b33cdaee Branch: refs/heads/master Commit: b33cdaee66d9225a4f396e4e9e8abef405b83ea2 Parents: 64d109e Author: Abdelkader Midani <[email protected]> Authored: Thu Oct 12 17:27:43 2017 +0200 Committer: Abdelkader Midani <[email protected]> Committed: Thu Oct 12 17:27:43 2017 +0200 ---------------------------------------------------------------------- .../unomi/persistence/spi/PropertyHelper.java | 2 +- .../baseplugin/actions/SetPropertyAction.java | 21 +++++++++-- .../actions/UpdateProfilePropertiesAction.java | 38 ++++++++++++-------- .../resources/OSGI-INF/blueprint/blueprint.xml | 4 ++- 4 files changed, 46 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b33cdaee/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PropertyHelper.java ---------------------------------------------------------------------- diff --git a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PropertyHelper.java b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PropertyHelper.java index d6e5be8..283ebbe 100644 --- a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PropertyHelper.java +++ b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PropertyHelper.java @@ -139,7 +139,7 @@ public class PropertyHelper { } else if ("integer".equals(valueTypeId)) { return getInteger(propertyValue); } else { - return propertyValue.toString(); + return propertyValue; } } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b33cdaee/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetPropertyAction.java ---------------------------------------------------------------------- diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetPropertyAction.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetPropertyAction.java index 00793fa..17517c8 100644 --- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetPropertyAction.java +++ b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetPropertyAction.java @@ -24,10 +24,15 @@ import org.apache.unomi.api.services.EventService; import org.apache.unomi.persistence.spi.PropertyHelper; import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; import java.util.TimeZone; public class SetPropertyAction implements ActionExecutor { + private EventService eventService; + public int execute(Action action, Event event) { boolean storeInSession = Boolean.TRUE.equals(action.getParameterValues().get("storeInSession")); @@ -41,6 +46,9 @@ public class SetPropertyAction implements ActionExecutor { Object setPropertyValueMultiple = action.getParameterValues().get("setPropertyValueMultiple"); Object setPropertyValueBoolean = action.getParameterValues().get("setPropertyValueBoolean"); + Event updateProfileProperties = new Event("updateProfileProperties", null, event.getProfile(), null, null, event.getProfile(), new Date()); + updateProfileProperties.setPersistent(false); + if (propertyValue == null) { if (propertyValueInteger != null) { propertyValue = PropertyHelper.getInteger(propertyValueInteger); @@ -58,12 +66,21 @@ public class SetPropertyAction implements ActionExecutor { propertyValue = format.format(event.getTimeStamp()); } - Object target = storeInSession ? event.getSession() : event.getProfile(); + Map<String, Object> propertyToUpdate = new HashMap<>(); + propertyToUpdate.put(propertyName, propertyValue); + + updateProfileProperties.setProperty(UpdateProfilePropertiesAction.PROPS_TO_UPDATE, propertyToUpdate); + int changes = eventService.send(updateProfileProperties); - if (PropertyHelper.setProperty(target, propertyName, propertyValue, (String) action.getParameterValues().get("setPropertyStrategy"))) { + if ((changes & EventService.PROFILE_UPDATED) == EventService.PROFILE_UPDATED) { return storeInSession ? EventService.SESSION_UPDATED : EventService.PROFILE_UPDATED; } + return EventService.NO_CHANGE; } + public void setEventService(EventService eventService) { + this.eventService = eventService; + } + } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b33cdaee/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/UpdateProfilePropertiesAction.java ---------------------------------------------------------------------- diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/UpdateProfilePropertiesAction.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/UpdateProfilePropertiesAction.java index 0a16434..919c996 100644 --- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/UpdateProfilePropertiesAction.java +++ b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/UpdateProfilePropertiesAction.java @@ -61,27 +61,35 @@ public class UpdateProfilePropertiesAction implements ActionExecutor { boolean isProfileUpdated = false; Map<String, Object> propsToAdd = (HashMap<String, Object>) event.getProperties().get(PROPS_TO_ADD); - for (String prop : propsToAdd.keySet()) { - String[] splitPropName = prop.split(Pattern.quote(".")); - PropertyType propType = profileService.getPropertyType(splitPropName[splitPropName.length - 1]); - if (propType != null) { - isProfileUpdated |= PropertyHelper.setProperty(target, prop, PropertyHelper.getValueByTypeId(propsToAdd.get(prop), propType.getValueTypeId()), "setIfMissing"); + if (propsToAdd != null) { + for (String prop : propsToAdd.keySet()) { + String[] splitPropName = prop.split(Pattern.quote(".")); + PropertyType propType = profileService.getPropertyType(splitPropName[splitPropName.length - 1]); + if (propType != null) { + isProfileUpdated |= PropertyHelper.setProperty(target, prop, PropertyHelper.getValueByTypeId(propsToAdd.get(prop), propType.getValueTypeId()), "setIfMissing"); + } } } + Map<String, Object> propsToUpdate = (HashMap<String, Object>) event.getProperties().get(PROPS_TO_UPDATE); - for (String prop : propsToUpdate.keySet()) { - String[] splitPropName = prop.split(Pattern.quote(".")); - PropertyType propType = profileService.getPropertyType(splitPropName[splitPropName.length - 1]); - if (propType != null) { - isProfileUpdated |= PropertyHelper.setProperty(target, prop, PropertyHelper.getValueByTypeId(propsToUpdate.get(prop), propType.getValueTypeId()), "alwaysSet"); + if (propsToUpdate != null) { + for (String prop : propsToUpdate.keySet()) { + String[] splitPropName = prop.split(Pattern.quote(".")); + PropertyType propType = profileService.getPropertyType(splitPropName[splitPropName.length - 1]); + if (propType != null) { + isProfileUpdated |= PropertyHelper.setProperty(target, prop, PropertyHelper.getValueByTypeId(propsToUpdate.get(prop), propType.getValueTypeId()), "alwaysSet"); + } } } + List<String> propsToDelete = (List<String>) event.getProperties().get(PROPS_TO_DELETE); - for (String prop : propsToDelete) { - String[] splitPropName = prop.split(Pattern.quote(".")); - PropertyType propType = profileService.getPropertyType(splitPropName[splitPropName.length - 1]); - if (propType != null) { - isProfileUpdated |= PropertyHelper.setProperty(target, prop, null, "remove"); + if (propsToDelete != null) { + for (String prop : propsToDelete) { + String[] splitPropName = prop.split(Pattern.quote(".")); + PropertyType propType = profileService.getPropertyType(splitPropName[splitPropName.length - 1]); + if (propType != null) { + isProfileUpdated |= PropertyHelper.setProperty(target, prop, null, "remove"); + } } } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b33cdaee/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 360b776..bbd8bc1 100644 --- a/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -165,7 +165,9 @@ <service-properties> <entry key="actionExecutorId" value="setProperty"/> </service-properties> - <bean class="org.apache.unomi.plugins.baseplugin.actions.SetPropertyAction"/> + <bean class="org.apache.unomi.plugins.baseplugin.actions.SetPropertyAction"> + <property name="eventService" ref="eventService"/> + </bean> </service> <service auto-export="interfaces">
