You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2018/02/15 16:22:14 UTC
incubator-unomi git commit: UNOMI-157 Make setPropertyAction behavior
configurable
Repository: incubator-unomi
Updated Branches:
refs/heads/master 636037486 -> aba4e1b9d
UNOMI-157 Make setPropertyAction behavior configurable
Signed-off-by: Serge Huber <sh...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/aba4e1b9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/aba4e1b9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/aba4e1b9
Branch: refs/heads/master
Commit: aba4e1b9de0fffe728fea71bfc7c05d1997a3f8e
Parents: 6360374
Author: Serge Huber <sh...@apache.org>
Authored: Thu Feb 15 17:22:06 2018 +0100
Committer: Serge Huber <sh...@apache.org>
Committed: Thu Feb 15 17:22:06 2018 +0100
----------------------------------------------------------------------
.../baseplugin/actions/SetPropertyAction.java | 40 ++++++++++++--------
.../resources/OSGI-INF/blueprint/blueprint.xml | 12 +++++-
2 files changed, 36 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/aba4e1b9/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 2952a7e..53c3ffc 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
@@ -33,6 +33,12 @@ public class SetPropertyAction implements ActionExecutor {
private EventService eventService;
+ private boolean useEventToUpdateProfile = true;
+
+ public void setUseEventToUpdateProfile(boolean useEventToUpdateProfile) {
+ this.useEventToUpdateProfile = useEventToUpdateProfile;
+ }
+
public int execute(Action action, Event event) {
boolean storeInSession = Boolean.TRUE.equals(action.getParameterValues().get("storeInSession"));
@@ -46,9 +52,6 @@ public class SetPropertyAction implements ActionExecutor {
Object setPropertyValueMultiple = action.getParameterValues().get("setPropertyValueMultiple");
Object setPropertyValueBoolean = action.getParameterValues().get("setPropertyValueBoolean");
- Event updateProperties = new Event("updateProperties", event.getSession(), event.getProfile(), event.getScope(), null, event.getProfile(), new Date());
- updateProperties.setPersistent(false);
-
if (propertyValue == null) {
if (propertyValueInteger != null) {
propertyValue = PropertyHelper.getInteger(propertyValueInteger);
@@ -68,21 +71,28 @@ public class SetPropertyAction implements ActionExecutor {
if (storeInSession) {
// in the case of session storage we directly update the session
- Object target = event.getSession();
-
- if (PropertyHelper.setProperty(target, propertyName, propertyValue, (String) action.getParameterValues().get("setPropertyStrategy"))) {
+ if (PropertyHelper.setProperty(event.getSession(), propertyName, propertyValue, (String) action.getParameterValues().get("setPropertyStrategy"))) {
return EventService.SESSION_UPDATED;
}
} else {
- // in the case of profile storage we use the update profile properties event instead.
- Map<String, Object> propertyToUpdate = new HashMap<>();
- propertyToUpdate.put(propertyName, propertyValue);
-
- updateProperties.setProperty(UpdatePropertiesAction.PROPS_TO_UPDATE, propertyToUpdate);
- int changes = eventService.send(updateProperties);
-
- if ((changes & EventService.PROFILE_UPDATED) == EventService.PROFILE_UPDATED) {
- return EventService.PROFILE_UPDATED;
+ if (useEventToUpdateProfile) {
+ // in the case of profile storage we use the update profile properties event instead.
+ Map<String, Object> propertyToUpdate = new HashMap<>();
+ propertyToUpdate.put(propertyName, propertyValue);
+
+ Event updateProperties = new Event("updateProperties", event.getSession(), event.getProfile(), event.getScope(), null, event.getProfile(), new Date());
+ updateProperties.setPersistent(false);
+
+ updateProperties.setProperty(UpdatePropertiesAction.PROPS_TO_UPDATE, propertyToUpdate);
+ int changes = eventService.send(updateProperties);
+
+ if ((changes & EventService.PROFILE_UPDATED) == EventService.PROFILE_UPDATED) {
+ return EventService.PROFILE_UPDATED;
+ }
+ } else {
+ if (PropertyHelper.setProperty(event.getProfile(), propertyName, propertyValue, (String) action.getParameterValues().get("setPropertyStrategy"))) {
+ return EventService.SESSION_UPDATED;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/aba4e1b9/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 6778b4f..31e68db 100644
--- a/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -17,7 +17,16 @@
-->
<blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
+ xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
+ http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">
+
+ <cm:property-placeholder persistent-id="org.apache.unomi.plugins.base"
+ update-strategy="reload" placeholder-prefix="${base.">
+ <cm:default-properties>
+ <cm:property name="useEventToUpdateProfile" value="false" />
+ </cm:default-properties>
+ </cm:property-placeholder>
<reference id="definitionsService" interface="org.apache.unomi.api.services.DefinitionsService"/>
<reference id="persistenceService" interface="org.apache.unomi.persistence.spi.PersistenceService"/>
@@ -167,6 +176,7 @@
</service-properties>
<bean class="org.apache.unomi.plugins.baseplugin.actions.SetPropertyAction">
<property name="eventService" ref="eventService"/>
+ <property name="useEventToUpdateProfile" value="${base.useEventToUpdateProfile}" />
</bean>
</service>