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 2020/11/11 09:20:51 UTC
[unomi] 05/17: UNOMI-374 Merge profile without sessions (#193)
This is an automated email from the ASF dual-hosted git repository.
shuber pushed a commit to branch unomi-1.5.x
in repository https://gitbox.apache.org/repos/asf/unomi.git
commit 1a709704eb5437f11a5c88e21e64103798098c74
Author: giladw <gw...@yotpo.com>
AuthorDate: Tue Sep 22 11:48:26 2020 +0300
UNOMI-374 Merge profile without sessions (#193)
* feat(DATA_3381-merging-monthly-indices): remove itemsMonthlyIndexed f… (#39)
* feat(DATA_3381-merging-monthly-indices): remove itemsMonthlyIndexed from blueprint, put it in config instead
* feat(DATA_3381-merging-monthly-indices): sending none if monthlyIndex should contain nothing
* Revert "feat(DATA_3381-merging-monthly-indices): remove itemsMonthlyIndexed f… (#39)"
This reverts commit b309e61b67ec0c3ed116c725d6c471ce4e60b3e0.
* check for session is null in mergePofilesPropertyAction
Co-authored-by: liatiusim <62...@users.noreply.github.com>
Co-authored-by: Shir Bromberg <sb...@yotpo.com>
Co-authored-by: amitco1 <am...@yotpo.com>
(cherry picked from commit 7fda2a305962eb0d28ce47dddefb3f56bfe6b688)
---
.../actions/MergeProfilesOnPropertyAction.java | 39 +++++++++++++---------
1 file changed, 23 insertions(+), 16 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 8200985..a496ddb 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
@@ -96,7 +96,7 @@ public class MergeProfilesOnPropertyAction implements ActionExecutor {
} else {
// Create a new profile
profile = new Profile(UUID.randomUUID().toString());
- profile.setProperty("firstVisit", currentSession.getTimeStamp());
+ profile.setProperty("firstVisit", event.getTimeStamp());
profile.getSystemProperties().put(mergeProfilePropertyName, mergeProfilePropertyValue);
}
@@ -109,9 +109,10 @@ public class MergeProfilesOnPropertyAction implements ActionExecutor {
event.setProfileId(profile.getItemId());
event.setProfile(profile);
- currentSession.setProfile(profile);
-
- eventService.send(new Event("sessionReassigned", currentSession, profile, event.getScope(), event, currentSession, event.getTimeStamp()));
+ if (currentSession != null) {
+ currentSession.setProfile(profile);
+ eventService.send(new Event("sessionReassigned", currentSession, profile, event.getScope(), event, currentSession, event.getTimeStamp()));
+ }
return EventService.PROFILE_UPDATED + EventService.SESSION_UPDATED;
} else {
@@ -139,7 +140,7 @@ public class MergeProfilesOnPropertyAction implements ActionExecutor {
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)
- sendProfileCookie(currentSession.getProfile(), httpServletResponse,
+ sendProfileCookie(profile, httpServletResponse,
profileIdCookieName, profileIdCookieDomain, profileIdCookieMaxAgeInSeconds);
final String masterProfileId = masterProfile.getItemId();
@@ -147,16 +148,19 @@ public class MergeProfilesOnPropertyAction implements ActionExecutor {
event.setProfileId(masterProfileId);
event.setProfile(masterProfile);
- currentSession.setProfile(masterProfile);
- if (privacyService.isRequireAnonymousBrowsing(profile)) {
- privacyService.setRequireAnonymousBrowsing(masterProfileId, true, event.getScope());
- }
-
final Boolean anonymousBrowsing = privacyService.isRequireAnonymousBrowsing(masterProfileId);
- if (anonymousBrowsing) {
- currentSession.setProfile(privacyService.getAnonymousProfile(masterProfile));
- event.setProfileId(null);
- persistenceService.save(event);
+
+ if (currentSession != null){
+ currentSession.setProfile(masterProfile);
+ if (privacyService.isRequireAnonymousBrowsing(profile)) {
+ privacyService.setRequireAnonymousBrowsing(masterProfileId, true, event.getScope());
+ }
+
+ if (anonymousBrowsing) {
+ currentSession.setProfile(privacyService.getAnonymousProfile(masterProfile));
+ event.setProfileId(null);
+ persistenceService.save(event);
+ }
}
event.getActionPostExecutors().add(new ActionPostExecutor() {
@@ -167,9 +171,12 @@ public class MergeProfilesOnPropertyAction implements ActionExecutor {
String profileId = profile.getItemId();
if (!StringUtils.equals(profileId, masterProfileId)) {
List<Session> sessions = persistenceService.query("profileId", profileId, null, Session.class);
- if (masterProfileId.equals(profileId) && !sessions.contains(currentSession)) {
- sessions.add(currentSession);
+ if (currentSession != null){
+ if (masterProfileId.equals(profileId) && !sessions.contains(currentSession)) {
+ sessions.add(currentSession);
+ }
}
+
for (Session session : sessions) {
persistenceService.update(session.getItemId(), session.getTimeStamp(), Session.class, "profileId", anonymousBrowsing ? null : masterProfileId);
}