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 2017/12/18 10:58:01 UTC
incubator-unomi git commit: UNOMI-144 Add to list action overwrites
existing profile lists - Fix by making sure we read the existing lists and
merge them with the new ones.
Repository: incubator-unomi
Updated Branches:
refs/heads/master f074cb186 -> 2e77a3323
UNOMI-144 Add to list action overwrites existing profile lists
- Fix by making sure we read the existing lists and merge them with the new ones.
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/2e77a332
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/2e77a332
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/2e77a332
Branch: refs/heads/master
Commit: 2e77a33231f5cc3c542a9dcdc91769ef263d43f6
Parents: f074cb1
Author: Serge Huber <sh...@apache.org>
Authored: Mon Dec 18 11:57:55 2017 +0100
Committer: Serge Huber <sh...@apache.org>
Committed: Mon Dec 18 11:57:55 2017 +0100
----------------------------------------------------------------------
.../unomi/lists/actions/AddToListsAction.java | 32 +++++++++++++++-----
1 file changed, 25 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/2e77a332/extensions/lists-extension/actions/src/main/java/org/apache/unomi/lists/actions/AddToListsAction.java
----------------------------------------------------------------------
diff --git a/extensions/lists-extension/actions/src/main/java/org/apache/unomi/lists/actions/AddToListsAction.java b/extensions/lists-extension/actions/src/main/java/org/apache/unomi/lists/actions/AddToListsAction.java
index 5dcaaa0..f120310 100644
--- a/extensions/lists-extension/actions/src/main/java/org/apache/unomi/lists/actions/AddToListsAction.java
+++ b/extensions/lists-extension/actions/src/main/java/org/apache/unomi/lists/actions/AddToListsAction.java
@@ -23,6 +23,7 @@ import org.apache.unomi.api.actions.ActionExecutor;
import org.apache.unomi.api.services.EventService;
import org.apache.unomi.api.services.ProfileService;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -44,15 +45,32 @@ public class AddToListsAction implements ActionExecutor {
@Override
public int execute(Action action, Event event) {
- List<String> listIdentifiers = (List<String>) action.getParameterValues().get("listIdentifiers");
+ List<String> newListIdentifiers = (List<String>) action.getParameterValues().get("listIdentifiers");
+ if (newListIdentifiers == null || newListIdentifiers.size() == 0) {
+ return EventService.NO_CHANGE;
+ }
Profile profile = event.getProfile();
- profile.getSystemProperties().put("lists", listIdentifiers);
- Event profileUpdated = new Event("profileUpdated", null, profile, event.getScope(), null, profile, new Date());
- profileUpdated.setPersistent(false);
- eventService.send(profileUpdated);
- profileService.save(profile);
+ List<String> existingListIdentifiers = (List<String>) profile.getSystemProperties().get("lists");
+ if (existingListIdentifiers == null) {
+ existingListIdentifiers = new ArrayList<>();
+ }
+ boolean listsChanged = false;
+ for (String newListIdentifier : newListIdentifiers) {
+ if (!existingListIdentifiers.contains(newListIdentifier)) {
+ existingListIdentifiers.add(newListIdentifier);
+ listsChanged = true;
+ }
+ }
- return EventService.PROFILE_UPDATED;
+ if (listsChanged) {
+ profile.getSystemProperties().put("lists", existingListIdentifiers);
+ Event profileUpdated = new Event("profileUpdated", null, profile, event.getScope(), null, profile, new Date());
+ profileUpdated.setPersistent(false);
+ eventService.send(profileUpdated);
+ return EventService.PROFILE_UPDATED;
+ } else {
+ return EventService.NO_CHANGE;
+ }
}
}