]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrResultUtils.java
edc2d001180cf4db5cb9ba5061580b5d30bd7615
2 * Copyright (C) 2007-2012 Mathieu Baudier
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.jcr
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.RepositoryException
;
20 import javax
.jcr
.Session
;
21 import javax
.jcr
.nodetype
.NodeType
;
23 import org
.argeo
.ArgeoException
;
24 import org
.argeo
.jcr
.JcrUtils
;
25 import org
.argeo
.jcr
.UserJcrUtils
;
26 import org
.argeo
.slc
.SlcException
;
29 * Utilities around the SLC JCR Result model. Note that it relies on fixed base
30 * paths (convention over configuration) for optimization purposes.
32 public class SlcJcrResultUtils
{
35 * Returns the path to the current slc:result node
37 public static String
getSlcResultsBasePath(Session session
) {
40 return UserJcrUtils
.getUserHome(session
).getPath() + "/"
41 + SlcNames
.SLC_RESULTS
;
42 } catch (RepositoryException re
) {
43 throw new ArgeoException(
44 "Unexpected error while getting Slc Results Base Path.", re
);
49 * Returns the path to the current Result UI specific node, depending the
52 public static String
getMyResultsBasePath(Session session
) {
54 return UserJcrUtils
.getUserHome(session
).getPath() + "/"
55 + SlcJcrConstants
.SLC_MYRESULT_BASEPATH
;
56 } catch (RepositoryException re
) {
57 throw new ArgeoException(
58 "Unexpected error while getting Slc Results Base Path.", re
);
63 * Creates a new node with type NodeType.NT_UNSTRUCTURED at the given
64 * absolute path. If a node already exists at the given path, returns that
65 * node if it has the correct type and throws an exception otherwise.
70 public static Node
getMyResultParentNode(Session session
) {
72 String absPath
= getMyResultsBasePath(session
);
73 if (session
.nodeExists(absPath
)) {
74 Node currNode
= session
.getNode(absPath
);
75 if (currNode
.isNodeType(NodeType
.NT_UNSTRUCTURED
))
78 throw new SlcException(
79 "A node already exists at this path : " + absPath
80 + " that has the wrong type. ");
82 Node myResParNode
= JcrUtils
.mkdirs(session
, absPath
);
83 myResParNode
.setPrimaryType(NodeType
.NT_UNSTRUCTURED
);
87 } catch (RepositoryException re
) {
88 throw new ArgeoException(
89 "Unexpected error while creating user MyResult base node.",
95 * Creates a new node with type SlcTypes.SLC_RESULT_FOLDER at the given
96 * absolute path. If a node already exists at the given path, returns that
97 * node if it has the correct type and throws an exception otherwise.
103 public static synchronized Node
createResultFolderNode(Session session
,
106 if (session
.nodeExists(absPath
)) {
108 Node currNode
= session
.getNode(absPath
);
109 if (currNode
.isNodeType(SlcTypes
.SLC_RESULT_FOLDER
))
112 throw new SlcException(
113 "A node already exists at this path : " + absPath
114 + " that has the wrong type. ");
116 Node rfNode
= JcrUtils
.mkdirs(session
, absPath
);
117 rfNode
.setPrimaryType(SlcTypes
.SLC_RESULT_FOLDER
);
118 Node statusNode
= rfNode
.addNode(SlcNames
.SLC_STATUS
,
120 statusNode
.setProperty(SlcNames
.SLC_SUCCESS
, true);
123 } catch (RepositoryException re
) {
124 throw new ArgeoException(
125 "Unexpected error while creating Result Folder node.", re
);