1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.argeo.slc.jcr;
17
18 import javax.jcr.Node;
19 import javax.jcr.RepositoryException;
20 import javax.jcr.Session;
21 import javax.jcr.nodetype.NodeType;
22
23 import org.argeo.jcr.JcrUtils;
24 import org.argeo.node.NodeUtils;
25 import org.argeo.slc.SlcException;
26 import org.argeo.slc.SlcNames;
27 import org.argeo.slc.SlcTypes;
28
29
30
31
32
33 public class SlcJcrResultUtils {
34
35
36
37
38 public static String getSlcResultsBasePath(Session session) {
39 try {
40 Node userHome = NodeUtils.getUserHome(session);
41 if (userHome == null)
42 throw new SlcException("No user home available for "
43 + session.getUserID());
44 return userHome.getPath() + '/' + SlcNames.SLC_SYSTEM + '/'
45 + SlcNames.SLC_RESULTS;
46 } catch (RepositoryException re) {
47 throw new SlcException(
48 "Unexpected error while getting Slc Results Base Path.", re);
49 }
50 }
51
52
53
54
55
56
57
58
59
60 public static Node getSlcResultsParentNode(Session session) {
61 try {
62 String absPath = getSlcResultsBasePath(session);
63 if (session.nodeExists(absPath)) {
64 Node currNode = session.getNode(absPath);
65 if (currNode.isNodeType(NodeType.NT_UNSTRUCTURED))
66 return currNode;
67 else
68 throw new SlcException(
69 "A node already exists at this path : " + absPath
70 + " that has the wrong type. ");
71 } else {
72 Node slcResParNode = JcrUtils.mkdirs(session, absPath);
73 slcResParNode.setPrimaryType(NodeType.NT_UNSTRUCTURED);
74 session.save();
75 return slcResParNode;
76 }
77 } catch (RepositoryException re) {
78 throw new SlcException(
79 "Unexpected error while creating slcResult root parent node.",
80 re);
81 }
82 }
83
84
85
86
87
88 public static String getMyResultsBasePath(Session session) {
89 try {
90 Node userHome = NodeUtils.getUserHome(session);
91 if (userHome == null)
92 throw new SlcException("No user home available for "
93 + session.getUserID());
94 return userHome.getPath() + '/' + SlcNames.SLC_SYSTEM + '/'
95 + SlcNames.SLC_MY_RESULTS;
96 } catch (RepositoryException re) {
97 throw new SlcException(
98 "Unexpected error while getting Slc Results Base Path.", re);
99 }
100 }
101
102
103
104
105
106
107
108
109
110 public static Node getMyResultParentNode(Session session) {
111 try {
112 String absPath = getMyResultsBasePath(session);
113 if (session.nodeExists(absPath)) {
114 Node currNode = session.getNode(absPath);
115 if (currNode.isNodeType(SlcTypes.SLC_MY_RESULT_ROOT_FOLDER))
116 return currNode;
117 else
118 throw new SlcException(
119 "A node already exists at this path : " + absPath
120 + " that has the wrong type. ");
121 } else {
122 Node myResParNode = JcrUtils.mkdirs(session, absPath);
123 myResParNode.setPrimaryType(SlcTypes.SLC_MY_RESULT_ROOT_FOLDER);
124 session.save();
125 return myResParNode;
126 }
127 } catch (RepositoryException re) {
128 throw new SlcException(
129 "Unexpected error while creating user MyResult base node.",
130 re);
131 }
132 }
133
134
135
136
137
138
139
140
141
142
143 public static synchronized Node createResultFolderNode(Session session,
144 String absPath) {
145 try {
146 if (session.nodeExists(absPath)) {
147
148 Node currNode = session.getNode(absPath);
149 if (currNode.isNodeType(SlcTypes.SLC_RESULT_FOLDER))
150 return currNode;
151 else
152 throw new SlcException(
153 "A node already exists at this path : " + absPath
154 + " that has the wrong type. ");
155 }
156 Node rfNode = JcrUtils.mkdirs(session, absPath);
157 rfNode.setPrimaryType(SlcTypes.SLC_RESULT_FOLDER);
158 Node statusNode = rfNode.addNode(SlcNames.SLC_AGGREGATED_STATUS,
159 SlcTypes.SLC_CHECK);
160 statusNode.setProperty(SlcNames.SLC_SUCCESS, true);
161 session.save();
162 return rfNode;
163 } catch (RepositoryException re) {
164 throw new SlcException(
165 "Unexpected error while creating Result Folder node.", re);
166 }
167 }
168 }