1 package org
.argeo
.slc
.jcr
;
4 import javax
.jcr
.RepositoryException
;
5 import javax
.jcr
.Session
;
6 import javax
.jcr
.nodetype
.NodeType
;
8 import org
.argeo
.api
.NodeUtils
;
9 import org
.argeo
.jcr
.JcrUtils
;
10 import org
.argeo
.slc
.SlcException
;
11 import org
.argeo
.slc
.SlcNames
;
12 import org
.argeo
.slc
.SlcTypes
;
15 * Utilities around the SLC JCR Result model. Note that it relies on fixed base
16 * paths (convention over configuration) for optimization purposes.
18 public class SlcJcrResultUtils
{
21 * Returns the path to the current slc:result node
23 public static String
getSlcResultsBasePath(Session session
) {
25 Node userHome
= NodeUtils
.getUserHome(session
);
27 throw new SlcException("No user home available for "
28 + session
.getUserID());
29 return userHome
.getPath() + '/' + SlcNames
.SLC_SYSTEM
+ '/'
30 + SlcNames
.SLC_RESULTS
;
31 } catch (RepositoryException re
) {
32 throw new SlcException(
33 "Unexpected error while getting Slc Results Base Path.", re
);
38 * Returns the base node to store SlcResults. If it does not exists, it is
39 * created. If a node already exists at the given path with the wrong type,
40 * it throws an exception.
45 public static Node
getSlcResultsParentNode(Session session
) {
47 String absPath
= getSlcResultsBasePath(session
);
48 if (session
.nodeExists(absPath
)) {
49 Node currNode
= session
.getNode(absPath
);
50 if (currNode
.isNodeType(NodeType
.NT_UNSTRUCTURED
))
53 throw new SlcException(
54 "A node already exists at this path : " + absPath
55 + " that has the wrong type. ");
57 Node slcResParNode
= JcrUtils
.mkdirs(session
, absPath
);
58 slcResParNode
.setPrimaryType(NodeType
.NT_UNSTRUCTURED
);
62 } catch (RepositoryException re
) {
63 throw new SlcException(
64 "Unexpected error while creating slcResult root parent node.",
70 * Returns the path to the current Result UI specific node, depending the
73 public static String
getMyResultsBasePath(Session session
) {
75 Node userHome
= NodeUtils
.getUserHome(session
);
77 throw new SlcException("No user home available for "
78 + session
.getUserID());
79 return userHome
.getPath() + '/' + SlcNames
.SLC_SYSTEM
+ '/'
80 + SlcNames
.SLC_MY_RESULTS
;
81 } catch (RepositoryException re
) {
82 throw new SlcException(
83 "Unexpected error while getting Slc Results Base Path.", re
);
88 * Creates a new node with type SlcTypes.SLC_MY_RESULT_ROOT_FOLDER at the
89 * given absolute path. If a node already exists at the given path, returns
90 * that node if it has the correct type and throws an exception otherwise.
95 public static Node
getMyResultParentNode(Session session
) {
97 String absPath
= getMyResultsBasePath(session
);
98 if (session
.nodeExists(absPath
)) {
99 Node currNode
= session
.getNode(absPath
);
100 if (currNode
.isNodeType(SlcTypes
.SLC_MY_RESULT_ROOT_FOLDER
))
103 throw new SlcException(
104 "A node already exists at this path : " + absPath
105 + " that has the wrong type. ");
107 Node myResParNode
= JcrUtils
.mkdirs(session
, absPath
);
108 myResParNode
.setPrimaryType(SlcTypes
.SLC_MY_RESULT_ROOT_FOLDER
);
112 } catch (RepositoryException re
) {
113 throw new SlcException(
114 "Unexpected error while creating user MyResult base node.",
120 * Creates a new node with type SlcTypes.SLC_RESULT_FOLDER at the given
121 * absolute path. If a node already exists at the given path, returns that
122 * node if it has the correct type and throws an exception otherwise.
128 public static synchronized Node
createResultFolderNode(Session session
,
131 if (session
.nodeExists(absPath
)) {
133 Node currNode
= session
.getNode(absPath
);
134 if (currNode
.isNodeType(SlcTypes
.SLC_RESULT_FOLDER
))
137 throw new SlcException(
138 "A node already exists at this path : " + absPath
139 + " that has the wrong type. ");
141 Node rfNode
= JcrUtils
.mkdirs(session
, absPath
);
142 rfNode
.setPrimaryType(SlcTypes
.SLC_RESULT_FOLDER
);
143 Node statusNode
= rfNode
.addNode(SlcNames
.SLC_AGGREGATED_STATUS
,
145 statusNode
.setProperty(SlcNames
.SLC_SUCCESS
, true);
148 } catch (RepositoryException re
) {
149 throw new SlcException(
150 "Unexpected error while creating Result Folder node.", re
);