]>
git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ResultParentUtils.java
1 package org
.argeo
.slc
.client
.ui
.model
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Collections
;
5 import java
.util
.Iterator
;
9 import javax
.jcr
.NodeIterator
;
10 import javax
.jcr
.Property
;
11 import javax
.jcr
.RepositoryException
;
12 import javax
.jcr
.Session
;
13 import javax
.jcr
.query
.Query
;
14 import javax
.jcr
.query
.QueryManager
;
15 import javax
.jcr
.query
.QueryResult
;
17 import org
.argeo
.slc
.SlcException
;
18 import org
.argeo
.slc
.jcr
.SlcJcrResultUtils
;
19 import org
.argeo
.slc
.jcr
.SlcNames
;
20 import org
.argeo
.slc
.jcr
.SlcTypes
;
22 public class ResultParentUtils
{
23 // private final static Log log =
24 // LogFactory.getLog(ResultParentUtils.class);
26 public static Object
[] orderChildren(Object
[] children
) {
27 List
<ResultFolder
> folders
= new ArrayList
<ResultFolder
>();
28 List
<SingleResultNode
> results
= new ArrayList
<SingleResultNode
>();
29 for (Object child
: children
) {
30 if (child
instanceof ResultFolder
)
31 folders
.add((ResultFolder
) child
);
32 else if (child
instanceof SingleResultNode
)
33 results
.add((SingleResultNode
) child
);
36 // Comparator first = Collections.reverseOrder();
37 Collections
.sort(folders
);
38 // Comparator<SingleResultNode> second = Collections.reverseOrder();
39 Collections
.sort(results
);
41 Object
[] orderedChildren
= new Object
[folders
.size() + results
.size()];
43 Iterator
<ResultFolder
> it
= folders
.iterator();
44 while (it
.hasNext()) {
45 orderedChildren
[i
] = it
.next();
48 Iterator
<SingleResultNode
> it2
= results
.iterator();
49 while (it2
.hasNext()) {
50 orderedChildren
[i
] = it2
.next();
53 return orderedChildren
;
56 public static List
<Node
> getResultsForDates(Session session
,
57 List
<String
> dateRelPathes
) {
58 if (dateRelPathes
== null || dateRelPathes
.size() == 0)
59 throw new SlcException("Specify at least one correct date as Path");
62 String basePath
= SlcJcrResultUtils
.getSlcResultsBasePath(session
);
63 Iterator
<String
> it
= dateRelPathes
.iterator();
64 StringBuffer clause
= new StringBuffer();
65 clause
.append("SELECT * FROM [");
66 clause
.append(SlcTypes
.SLC_DIFF_RESULT
);
67 clause
.append("] as results");
68 clause
.append(" WHERE ");
69 while (it
.hasNext()) {
70 String absPath
= basePath
+ "/" + it
.next();
71 clause
.append("ISDESCENDANTNODE(results, [");
72 clause
.append(absPath
);
74 clause
.append(" OR ");
77 clause
.delete(clause
.length() - 4, clause
.length());
78 clause
.append(" ORDER BY results.[" + Property
.JCR_CREATED
81 // log.debug("request : " + clause.toString());
82 QueryManager qm
= session
.getWorkspace().getQueryManager();
83 Query q
= qm
.createQuery(clause
.toString(), Query
.JCR_SQL2
);
84 QueryResult result
= q
.execute();
86 NodeIterator ni
= result
.getNodes();
87 List
<Node
> nodes
= new ArrayList
<Node
>();
88 while (ni
.hasNext()) {
89 nodes
.add(ni
.nextNode());
92 } catch (RepositoryException re
) {
93 throw new SlcException(
94 "Unexpected error while getting Results for given date", re
);
99 * recursively update passed status of the parent ResultFolder and its
106 public static void updatePassedStatus(Node node
, boolean passed
) {
108 Node pNode
= node
.getParent();
109 if (!pNode
.hasNode(SlcNames
.SLC_STATUS
))
110 // we have reached the root of the tree. stop the
113 boolean pStatus
= pNode
.getNode(SlcNames
.SLC_STATUS
)
114 .getProperty(SlcNames
.SLC_SUCCESS
).getBoolean();
115 if (pStatus
== passed
)
119 // error we only update status of the result folder and its
121 pNode
.getNode(SlcNames
.SLC_STATUS
).setProperty(
122 SlcNames
.SLC_SUCCESS
, passed
);
123 updatePassedStatus(pNode
, passed
);
125 // success we must first check if all siblings have also
126 // successfully completed
127 boolean success
= true;
128 NodeIterator ni
= pNode
.getNodes();
129 children
: while (ni
.hasNext()) {
130 Node currNode
= ni
.nextNode();
131 if ((currNode
.isNodeType(SlcTypes
.SLC_DIFF_RESULT
) || currNode
132 .isNodeType(SlcTypes
.SLC_RESULT_FOLDER
))
133 && !currNode
.getNode(SlcNames
.SLC_STATUS
)
134 .getProperty(SlcNames
.SLC_SUCCESS
)
141 pNode
.getNode(SlcNames
.SLC_STATUS
).setProperty(
142 SlcNames
.SLC_SUCCESS
, passed
);
143 updatePassedStatus(pNode
, passed
);
145 // one of the siblings had also the failed status so
146 // above tree remains unchanged.
149 } catch (RepositoryException e
) {
150 throw new SlcException("Cannot register listeners", e
);
154 public static void updateStatusOnRemoval(Node node
) {
156 if (!node
.hasNode(SlcNames
.SLC_STATUS
))
159 boolean pStatus
= node
.getNode(SlcNames
.SLC_STATUS
)
160 .getProperty(SlcNames
.SLC_SUCCESS
).getBoolean();
165 // success we must first check if all siblings have also
166 // successfully completed
167 boolean success
= true;
168 NodeIterator ni
= node
.getNodes();
169 children
: while (ni
.hasNext()) {
170 Node currNode
= ni
.nextNode();
171 if ((currNode
.isNodeType(SlcTypes
.SLC_DIFF_RESULT
) || currNode
172 .isNodeType(SlcTypes
.SLC_RESULT_FOLDER
))
173 && !currNode
.getNode(SlcNames
.SLC_STATUS
)
174 .getProperty(SlcNames
.SLC_SUCCESS
)
181 node
.getNode(SlcNames
.SLC_STATUS
).setProperty(
182 SlcNames
.SLC_SUCCESS
, true);
183 updatePassedStatus(node
, true);
185 // one of the siblings had also the failed status so
186 // above tree remains unchanged.
189 } catch (RepositoryException e
) {
190 throw new SlcException(
191 "Unexpected error while updating status on removal", e
);