]>
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
519dd3aeae337464c712f6ef37d7c6ec9ba1ca4d
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
[children
.length
];
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 ResultParent
[] 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 ResultParent
[] results
= new ResultParent
[(int) ni
.getSize()];
89 while (ni
.hasNext()) {
90 Node currNode
= ni
.nextNode();
91 SingleResultNode srn
= new SingleResultNode(null, currNode
,
92 currNode
.getProperty(SlcNames
.SLC_TEST_CASE
)
99 } catch (RepositoryException re
) {
100 throw new SlcException(
101 "Unexpected error while getting Results for given date", re
);
106 * recursively update passed status of the parent ResultFolder and its
113 public static void updatePassedStatus(Node node
, boolean passed
) {
115 Node pNode
= node
.getParent();
116 if (!pNode
.hasNode(SlcNames
.SLC_STATUS
))
117 // we have reached the root of the tree. stop the
120 boolean pStatus
= pNode
.getNode(SlcNames
.SLC_STATUS
)
121 .getProperty(SlcNames
.SLC_SUCCESS
).getBoolean();
122 if (pStatus
== passed
)
126 // error we only update status of the result folder and its
128 pNode
.getNode(SlcNames
.SLC_STATUS
).setProperty(
129 SlcNames
.SLC_SUCCESS
, passed
);
130 updatePassedStatus(pNode
, passed
);
132 // success we must first check if all siblings have also
133 // successfully completed
134 boolean success
= true;
135 NodeIterator ni
= pNode
.getNodes();
136 children
: while (ni
.hasNext()) {
137 Node currNode
= ni
.nextNode();
138 if ((currNode
.isNodeType(SlcTypes
.SLC_DIFF_RESULT
) || currNode
139 .isNodeType(SlcTypes
.SLC_RESULT_FOLDER
))
140 && !currNode
.getNode(SlcNames
.SLC_STATUS
)
141 .getProperty(SlcNames
.SLC_SUCCESS
)
148 pNode
.getNode(SlcNames
.SLC_STATUS
).setProperty(
149 SlcNames
.SLC_SUCCESS
, passed
);
150 updatePassedStatus(pNode
, passed
);
152 // one of the siblings had also the failed status so
153 // above tree remains unchanged.
156 } catch (RepositoryException e
) {
157 throw new SlcException("Cannot register listeners", e
);
161 public static void updateStatusOnRemoval(Node node
) {
163 if (!node
.hasNode(SlcNames
.SLC_STATUS
))
166 boolean pStatus
= node
.getNode(SlcNames
.SLC_STATUS
)
167 .getProperty(SlcNames
.SLC_SUCCESS
).getBoolean();
172 // success we must first check if all siblings have also
173 // successfully completed
174 boolean success
= true;
175 NodeIterator ni
= node
.getNodes();
176 children
: while (ni
.hasNext()) {
177 Node currNode
= ni
.nextNode();
178 if ((currNode
.isNodeType(SlcTypes
.SLC_DIFF_RESULT
) || currNode
179 .isNodeType(SlcTypes
.SLC_RESULT_FOLDER
))
180 && !currNode
.getNode(SlcNames
.SLC_STATUS
)
181 .getProperty(SlcNames
.SLC_SUCCESS
)
188 node
.getNode(SlcNames
.SLC_STATUS
).setProperty(
189 SlcNames
.SLC_SUCCESS
, true);
190 updatePassedStatus(node
, true);
192 // one of the siblings had also the failed status so
193 // above tree remains unchanged.
196 } catch (RepositoryException e
) {
197 throw new SlcException("Unexpected error while updating status on removal", e
);