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 2021/01/06 15:20:42 UTC
[unomi] branch master updated:
UNOMI-413-mergeProfileOnPropertyAction: support take Events profile as
master,
fix persistence bug when new profile is merged and it was the event profile
(#232)
This is an automated email from the ASF dual-hosted git repository.
shuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/master by this push:
new 1c9b970 UNOMI-413-mergeProfileOnPropertyAction: support take Events profile as master, fix persistence bug when new profile is merged and it was the event profile (#232)
1c9b970 is described below
commit 1c9b970d6d21ea3d2c6744292e748c32278b6876
Author: giladw <gw...@yotpo.com>
AuthorDate: Wed Jan 6 17:20:34 2021 +0200
UNOMI-413-mergeProfileOnPropertyAction: support take Events profile as master, fix persistence bug when new profile is merged and it was the event profile (#232)
---
.../actions/MergeProfilesOnPropertyAction.java | 22 ++++++++++++++++++----
.../cxs/actions/mergeProfilesOnPropertyAction.json | 5 +++++
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java
index ffdf626..b01990b 100644
--- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java
+++ b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java
@@ -132,11 +132,18 @@ public class MergeProfilesOnPropertyAction implements ActionExecutor {
return StringUtils.isEmpty(mergeProfilePreviousPropertyValue) ? EventService.PROFILE_UPDATED : EventService.NO_CHANGE;
}
- // Use oldest profile for master profile
- final Profile masterProfile = profileService.mergeProfiles(profiles.get(0), profiles);
+ Profile markedMasterProfile;
+ boolean forceEventProfileAsMaster = action.getParameterValues().containsKey("forceEventProfileAsMaster") ?
+ (boolean) action.getParameterValues().get("forceEventProfileAsMaster") : false;
+ if (forceEventProfileAsMaster)
+ markedMasterProfile = event.getProfile();
+ else
+ markedMasterProfile = profiles.get(0);// Use oldest profile for master profile
+
+ final Profile masterProfile = profileService.mergeProfiles(markedMasterProfile, profiles);
// Profile has changed
- if (!masterProfile.getItemId().equals(profileId)) {
+ if (forceEventProfileAsMaster || !masterProfile.getItemId().equals(profileId)) {
HttpServletResponse httpServletResponse = (HttpServletResponse) event.getAttributes().get(Event.HTTP_RESPONSE_ATTRIBUTE);
// we still send back the current profile cookie. It will be changed on the next request to the ContextServlet.
// The current profile will be deleted only then because we cannot delete it right now (too soon)
@@ -192,7 +199,14 @@ public class MergeProfilesOnPropertyAction implements ActionExecutor {
sourceMap.put("mergedWith", masterProfileId);
profile.setSystemProperty("lastUpdated", new Date());
sourceMap.put("systemProperties", profile.getSystemProperties());
- persistenceService.update(profile, null, Profile.class, sourceMap);
+
+ boolean isExist = persistenceService.load(profile.getItemId(), Profile.class) != null;
+
+ if (isExist == false) //save the original event profile is it has been changed
+ persistenceService.save(profile);
+ else
+ persistenceService.update(profile, null, Profile.class, sourceMap,true);
+
}
}
} catch (Exception e) {
diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/mergeProfilesOnPropertyAction.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/mergeProfilesOnPropertyAction.json
index 6082f9f..07bf38c 100644
--- a/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/mergeProfilesOnPropertyAction.json
+++ b/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/mergeProfilesOnPropertyAction.json
@@ -15,6 +15,11 @@
"id": "mergeProfilePropertyName",
"type": "string",
"multivalued": false
+ },
+ {
+ "id": "forceEventProfileAsMaster",
+ "type": "boolean",
+ "multivalued": false
}
]
}
\ No newline at end of file