X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.jcr%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fjcr%2FSlcJcrResultUtils.java;h=edc2d001180cf4db5cb9ba5061580b5d30bd7615;hb=4e7678886b9f37c7e47896ff0889aa6cafbb3372;hp=9546c350820895b632ab04726bd851f33e1ec59d;hpb=e8997305e4d5fe939e2e4ec55195afdc0d488bbc;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrResultUtils.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrResultUtils.java index 9546c3508..edc2d0011 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrResultUtils.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrResultUtils.java @@ -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); } - } /**