]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java
Improve GIS types
[lgpl/argeo-commons.git] / server / runtime / org.argeo.server.jcr / src / main / java / org / argeo / jcr / JcrUtils.java
index c7915d0ed57bb89ed132419247c3eebc18037ff7..19a3f7703b8677b3584324d26e3cec5a28940745 100644 (file)
@@ -167,7 +167,7 @@ public class JcrUtils implements ArgeoJcrConstants {
                buf.append('Y');
                buf.append(cal.get(Calendar.YEAR));
                buf.append('/');
-               
+
                int month = cal.get(Calendar.MONTH) + 1;
                buf.append('M');
                if (month < 10)
@@ -746,8 +746,13 @@ public class JcrUtils implements ArgeoJcrConstants {
 
        /** Logs out the session, not throwing any exception, even if it is null. */
        public static void logoutQuietly(Session session) {
-               if (session != null)
-                       session.logout();
+               try {
+                       if (session != null)
+                               if (session.isLive())
+                                       session.logout();
+               } catch (Exception e) {
+                       // silent
+               }
        }
 
        /** Returns the home node of the session user or null if none was found. */
@@ -842,15 +847,35 @@ public class JcrUtils implements ArgeoJcrConstants {
                        if (session.hasPendingChanges())
                                throw new ArgeoException(
                                                "Session has pending changes, save them first");
+
                        String homePath = homeBasePath + '/'
                                        + firstCharsToPath(username, 2) + '/' + username;
-                       Node userHome = JcrUtils.mkdirs(session, homePath);
 
-                       Node userProfile = userHome.addNode(ArgeoNames.ARGEO_PROFILE);
-                       userProfile.addMixin(ArgeoTypes.ARGEO_USER_PROFILE);
-                       userProfile.setProperty(ArgeoNames.ARGEO_USER_ID, username);
-                       session.save();
-                       // we need to save the profile before adding the user home type
+                       if (session.itemExists(homePath)) {
+                               try {
+                                       throw new ArgeoException(
+                                                       "Trying to create a user home that already exists");
+                               } catch (Exception e) {
+                                       // we use this workaround to be sure to get the stack trace
+                                       // to identify the sink of the bug.
+                                       log.warn("trying to create an already existing userHome at path:"
+                                                       + homePath + ". Stack trace : ");
+                                       e.printStackTrace();
+                               }
+                       }
+
+                       Node userHome = JcrUtils.mkdirs(session, homePath);
+                       Node userProfile;
+                       if (userHome.hasNode(ArgeoNames.ARGEO_PROFILE)) {
+                               log.warn("userProfile node already exists for userHome path: "
+                                               + homePath + ". We do not add a new one");
+                       } else {
+                               userProfile = userHome.addNode(ArgeoNames.ARGEO_PROFILE);
+                               userProfile.addMixin(ArgeoTypes.ARGEO_USER_PROFILE);
+                               userProfile.setProperty(ArgeoNames.ARGEO_USER_ID, username);
+                               session.save();
+                               // we need to save the profile before adding the user home type
+                       }
                        userHome.addMixin(ArgeoTypes.ARGEO_USER_HOME);
                        // see
                        // http://jackrabbit.510166.n4.nabble.com/Jackrabbit-2-0-beta-6-Problem-adding-a-Mixin-type-with-mandatory-properties-after-setting-propertiesn-td1290332.html