X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=runtime%2Forg.argeo.slc.support.jcr%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fjcr%2FSlcJcrResultUtils.java;h=edc2d001180cf4db5cb9ba5061580b5d30bd7615;hb=a0a151ee3a0aed29a3cb03d81e35d540ca9fdb03;hp=0f07fe56729444c2a40a829101994d843bd4e591;hpb=844bc386a1854a29d282a23ffda820ed7a52b74e;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 0f07fe567..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,6 +18,7 @@ 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; @@ -58,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); } - } /**