]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrResultUtils.java
Adapt to changes in Argeo Commons
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.jcr / src / main / java / org / argeo / slc / jcr / SlcJcrResultUtils.java
index 9546c350820895b632ab04726bd851f33e1ec59d..edc2d001180cf4db5cb9ba5061580b5d30bd7615 100644 (file)
@@ -18,9 +18,11 @@ package org.argeo.slc.jcr;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
 
 import org.argeo.ArgeoException;
 import org.argeo.jcr.JcrUtils;
+import org.argeo.jcr.UserJcrUtils;
 import org.argeo.slc.SlcException;
 
 /**
@@ -35,7 +37,7 @@ public class SlcJcrResultUtils {
        public static String getSlcResultsBasePath(Session session) {
                try {
 
-                       return JcrUtils.getUserHome(session).getPath() + "/"
+                       return UserJcrUtils.getUserHome(session).getPath() + "/"
                                        + SlcNames.SLC_RESULTS;
                } catch (RepositoryException re) {
                        throw new ArgeoException(
@@ -49,7 +51,7 @@ public class SlcJcrResultUtils {
         */
        public static String getMyResultsBasePath(Session session) {
                try {
-                       return JcrUtils.getUserHome(session).getPath() + "/"
+                       return UserJcrUtils.getUserHome(session).getPath() + "/"
                                        + SlcJcrConstants.SLC_MYRESULT_BASEPATH;
                } catch (RepositoryException re) {
                        throw new ArgeoException(
@@ -57,20 +59,36 @@ public class SlcJcrResultUtils {
                }
        }
 
+       /**
+        * Creates a new node with type NodeType.NT_UNSTRUCTURED at the given
+        * absolute path. If a node already exists at the given path, returns that
+        * node if it has the correct type and throws an exception otherwise.
+        * 
+        * @param session
+        * @return
+        */
        public static Node getMyResultParentNode(Session session) {
                try {
-                       if (session.nodeExists(SlcJcrResultUtils
-                                       .getMyResultsBasePath(session)))
-                               return session.getNode(getMyResultsBasePath(session));
-                       else
-                               return createResultFolderNode(session,
-                                               getMyResultsBasePath(session));
+                       String absPath = getMyResultsBasePath(session);
+                       if (session.nodeExists(absPath)) {
+                               Node currNode = session.getNode(absPath);
+                               if (currNode.isNodeType(NodeType.NT_UNSTRUCTURED))
+                                       return currNode;
+                               else
+                                       throw new SlcException(
+                                                       "A node already exists at this path : " + absPath
+                                                                       + " that has the wrong type. ");
+                       } else {
+                               Node myResParNode = JcrUtils.mkdirs(session, absPath);
+                               myResParNode.setPrimaryType(NodeType.NT_UNSTRUCTURED);
+                               session.save();
+                               return myResParNode;
+                       }
                } catch (RepositoryException re) {
                        throw new ArgeoException(
                                        "Unexpected error while creating user MyResult base node.",
                                        re);
                }
-
        }
 
        /**