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
.cms
.jcr
.CmsJcrUtils
;
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
= CmsJcrUtils
.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.
44 public static Node
getSlcResultsParentNode(Session session
) {
46 String absPath
= getSlcResultsBasePath(session
);
47 if (session
.nodeExists(absPath
)) {
48 Node currNode
= session
.getNode(absPath
);
49 if (currNode
.isNodeType(NodeType
.NT_UNSTRUCTURED
))
52 throw new SlcException(
53 "A node already exists at this path : " + absPath
54 + " that has the wrong type. ");
56 Node slcResParNode
= JcrUtils
.mkdirs(session
, absPath
);
57 slcResParNode
.setPrimaryType(NodeType
.NT_UNSTRUCTURED
);
61 } catch (RepositoryException re
) {
62 throw new SlcException(
63 "Unexpected error while creating slcResult root parent node.",
69 * Returns the path to the current Result UI specific node, depending the
72 public static String
getMyResultsBasePath(Session session
) {
74 Node userHome
= CmsJcrUtils
.getUserHome(session
);
76 throw new SlcException("No user home available for "
77 + session
.getUserID());
78 return userHome
.getPath() + '/' + SlcNames
.SLC_SYSTEM
+ '/'
79 + SlcNames
.SLC_MY_RESULTS
;
80 } catch (RepositoryException re
) {
81 throw new SlcException(
82 "Unexpected error while getting Slc Results Base Path.", re
);
87 * Creates a new node with type SlcTypes.SLC_MY_RESULT_ROOT_FOLDER at the
88 * given absolute path. If a node already exists at the given path, returns
89 * that node if it has the correct type and throws an exception otherwise.
93 public static Node
getMyResultParentNode(Session session
) {
95 String absPath
= getMyResultsBasePath(session
);
96 if (session
.nodeExists(absPath
)) {
97 Node currNode
= session
.getNode(absPath
);
98 if (currNode
.isNodeType(SlcTypes
.SLC_MY_RESULT_ROOT_FOLDER
))
101 throw new SlcException(
102 "A node already exists at this path : " + absPath
103 + " that has the wrong type. ");
105 Node myResParNode
= JcrUtils
.mkdirs(session
, absPath
);
106 myResParNode
.setPrimaryType(SlcTypes
.SLC_MY_RESULT_ROOT_FOLDER
);
110 } catch (RepositoryException re
) {
111 throw new SlcException(
112 "Unexpected error while creating user MyResult base node.",
118 * Creates a new node with type SlcTypes.SLC_RESULT_FOLDER at the given
119 * absolute path. If a node already exists at the given path, returns that
120 * node if it has the correct type and throws an exception otherwise.
125 public static synchronized Node
createResultFolderNode(Session session
,
128 if (session
.nodeExists(absPath
)) {
130 Node currNode
= session
.getNode(absPath
);
131 if (currNode
.isNodeType(SlcTypes
.SLC_RESULT_FOLDER
))
134 throw new SlcException(
135 "A node already exists at this path : " + absPath
136 + " that has the wrong type. ");
138 Node rfNode
= JcrUtils
.mkdirs(session
, absPath
);
139 rfNode
.setPrimaryType(SlcTypes
.SLC_RESULT_FOLDER
);
140 Node statusNode
= rfNode
.addNode(SlcNames
.SLC_AGGREGATED_STATUS
,
142 statusNode
.setProperty(SlcNames
.SLC_SUCCESS
, true);
145 } catch (RepositoryException re
) {
146 throw new SlcException(
147 "Unexpected error while creating Result Folder node.", re
);