This is an automated email from the ASF dual-hosted git repository.

jsinovassinnaik pushed a commit to branch UNOMI-785-fix-npe
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit a804a830c05601601b25f6496a7d7ade91fddad6
Author: jsinovassin <jsinovassinn...@jahia.com>
AuthorDate: Thu Jul 20 18:24:30 2023 +0200

    UNOMI-785 : create new profile in case session profile not existing anymore
---
 .../unomi/rest/endpoints/ContextJsonEndpoint.java      | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git 
a/rest/src/main/java/org/apache/unomi/rest/endpoints/ContextJsonEndpoint.java 
b/rest/src/main/java/org/apache/unomi/rest/endpoints/ContextJsonEndpoint.java
index a7ebea0da..7ac46970c 100644
--- 
a/rest/src/main/java/org/apache/unomi/rest/endpoints/ContextJsonEndpoint.java
+++ 
b/rest/src/main/java/org/apache/unomi/rest/endpoints/ContextJsonEndpoint.java
@@ -50,14 +50,7 @@ import javax.ws.rs.*;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import java.util.*;
 
 @WebService
 @Consumes(MediaType.APPLICATION_JSON)
@@ -232,7 +225,14 @@ public class ContextJsonEndpoint {
                         // Session user has been switched, profile id in 
cookie is not up to date
                         // We must reload the profile with the session ID as 
some properties could be missing from the session profile
                         // #personalIdentifier
-                        profile = 
profileService.load(sessionProfile.getItemId());
+                        Profile persistedProfile = 
profileService.load(sessionProfile.getItemId());
+                        if (persistedProfile == null){
+                            logger.error("Profile with id {} in session {} not 
existing anymore in profile index. A new profile will be created", 
sessionProfile.getItemId(), sessionProfile.getItemId());
+                            profile = createNewProfile(null, timestamp);
+                            profileCreated = true;
+                        } else {
+                            profile = persistedProfile;
+                        }
                     }
 
                     // Handle anonymous situation

Reply via email to