]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrResultUtils.java
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
;
22 import org
.argeo
.ArgeoException
;
23 import org
.argeo
.jcr
.ArgeoJcrUtils
;
24 import org
.argeo
.jcr
.JcrUtils
;
25 import org
.argeo
.slc
.SlcException
;
28 * Utilities around the SLC JCR Result model. Note that it relies on fixed base
29 * paths (convention over configuration) for optimization purposes.
31 public class SlcJcrResultUtils
{
34 * Returns the path to the current slc:result node
36 public static String
getSlcResultsBasePath(Session session
) {
39 return ArgeoJcrUtils
.getUserHome(session
).getPath() + "/"
40 + SlcNames
.SLC_RESULTS
;
41 } catch (RepositoryException re
) {
42 throw new ArgeoException(
43 "Unexpected error while getting Slc Results Base Path.", re
);
48 * Returns the path to the current Result UI specific node, depending the
51 public static String
getMyResultsBasePath(Session session
) {
53 return ArgeoJcrUtils
.getUserHome(session
).getPath() + "/"
54 + SlcJcrConstants
.SLC_MYRESULT_BASEPATH
;
55 } catch (RepositoryException re
) {
56 throw new ArgeoException(
57 "Unexpected error while getting Slc Results Base Path.", re
);
61 public static Node
getMyResultParentNode(Session session
) {
63 if (session
.nodeExists(SlcJcrResultUtils
64 .getMyResultsBasePath(session
)))
65 return session
.getNode(getMyResultsBasePath(session
));
67 return createResultFolderNode(session
,
68 getMyResultsBasePath(session
));
69 } catch (RepositoryException re
) {
70 throw new ArgeoException(
71 "Unexpected error while creating user MyResult base node.",
78 * Creates a new node with type SlcTypes.SLC_RESULT_FOLDER at the given
79 * absolute path. If a node already exists at the given path, returns that
80 * node if it has the correct type and throws an exception otherwise.
86 public static synchronized Node
createResultFolderNode(Session session
,
89 if (session
.nodeExists(absPath
)) {
91 Node currNode
= session
.getNode(absPath
);
92 if (currNode
.isNodeType(SlcTypes
.SLC_RESULT_FOLDER
))
95 throw new SlcException(
96 "A node already exists at this path : " + absPath
97 + " that has the wrong type. ");
99 Node rfNode
= JcrUtils
.mkdirs(session
, absPath
);
100 rfNode
.setPrimaryType(SlcTypes
.SLC_RESULT_FOLDER
);
101 Node statusNode
= rfNode
.addNode(SlcNames
.SLC_STATUS
,
103 statusNode
.setProperty(SlcNames
.SLC_SUCCESS
, true);
106 } catch (RepositoryException re
) {
107 throw new ArgeoException(
108 "Unexpected error while creating Result Folder node.", re
);