]>
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
.apache
.commons
.logging
.Log
;
18 import org
.apache
.commons
.logging
.LogFactory
;
19 import org
.argeo
.slc
.SlcException
;
20 import org
.argeo
.slc
.jcr
.SlcJcrResultUtils
;
21 import org
.argeo
.slc
.jcr
.SlcNames
;
22 import org
.argeo
.slc
.jcr
.SlcTypes
;
24 public class ResultParentUtils
{
25 private final static Log log
= LogFactory
.getLog(ResultParentUtils
.class);
27 public static Object
[] orderChildren(Object
[] children
) {
28 List
<ResultFolder
> folders
= new ArrayList
<ResultFolder
>();
29 List
<SingleResultNode
> results
= new ArrayList
<SingleResultNode
>();
30 for (Object child
: children
) {
31 if (child
instanceof ResultFolder
)
32 folders
.add((ResultFolder
) child
);
33 else if (child
instanceof SingleResultNode
)
34 results
.add((SingleResultNode
) child
);
37 // Comparator first = Collections.reverseOrder();
38 Collections
.sort(folders
);
39 // Comparator<SingleResultNode> second = Collections.reverseOrder();
40 Collections
.sort(results
);
42 Object
[] orderedChildren
= new Object
[children
.length
];
44 Iterator
<ResultFolder
> it
= folders
.iterator();
45 while (it
.hasNext()) {
46 orderedChildren
[i
] = it
.next();
49 Iterator
<SingleResultNode
> it2
= results
.iterator();
50 while (it2
.hasNext()) {
51 orderedChildren
[i
] = it2
.next();
54 return orderedChildren
;
57 public static ResultParent
[] getResultsForDates(Session session
,
58 List
<String
> dateRelPathes
) {
59 if (dateRelPathes
== null || dateRelPathes
.size() == 0)
60 throw new SlcException("Specify at least one correct date as Path");
63 String basePath
= SlcJcrResultUtils
.getSlcResultsBasePath(session
);
64 Iterator
<String
> it
= dateRelPathes
.iterator();
65 StringBuffer clause
= new StringBuffer();
66 clause
.append("SELECT * FROM [");
67 clause
.append(SlcTypes
.SLC_DIFF_RESULT
);
68 clause
.append("] as results");
69 clause
.append(" WHERE ");
70 while (it
.hasNext()) {
71 String absPath
= basePath
+ "/" + it
.next();
72 clause
.append("ISDESCENDANTNODE(results, [");
73 clause
.append(absPath
);
75 clause
.append(" OR ");
78 clause
.delete(clause
.length() - 4, clause
.length());
79 clause
.append(" ORDER BY results.[" + Property
.JCR_CREATED
82 // log.debug("request : " + clause.toString());
83 QueryManager qm
= session
.getWorkspace().getQueryManager();
84 Query q
= qm
.createQuery(clause
.toString(), Query
.JCR_SQL2
);
85 QueryResult result
= q
.execute();
87 NodeIterator ni
= result
.getNodes();
88 ResultParent
[] results
= new ResultParent
[(int) ni
.getSize()];
90 while (ni
.hasNext()) {
91 Node currNode
= ni
.nextNode();
92 SingleResultNode srn
= new SingleResultNode(null, currNode
,
93 currNode
.getProperty(SlcNames
.SLC_TEST_CASE
)
100 } catch (RepositoryException re
) {
101 throw new SlcException(
102 "Unexpected error while getting Results for given date", re
);
107 * recursively update passed status of the parent ResultFolder and its
114 public static void updatePassedStatus(Node node
, boolean passed
) {
116 Node pNode
= node
.getParent();
117 if (!pNode
.hasNode(SlcNames
.SLC_STATUS
))
118 // we have reached the root of the tree. stop the
121 boolean pStatus
= pNode
.getNode(SlcNames
.SLC_STATUS
)
122 .getProperty(SlcNames
.SLC_SUCCESS
).getBoolean();
123 if (pStatus
== passed
)
127 // error we only update status of the result folder and its
129 pNode
.getNode(SlcNames
.SLC_STATUS
).setProperty(
130 SlcNames
.SLC_SUCCESS
, passed
);
131 updatePassedStatus(pNode
, passed
);
133 // success we must first check if all siblings have also
134 // successfully completed
135 boolean success
= true;
136 NodeIterator ni
= pNode
.getNodes();
137 children
: while (ni
.hasNext()) {
138 Node currNode
= ni
.nextNode();
139 if ((currNode
.isNodeType(SlcTypes
.SLC_DIFF_RESULT
) || currNode
140 .isNodeType(SlcTypes
.SLC_RESULT_FOLDER
))
141 && !currNode
.getNode(SlcNames
.SLC_STATUS
)
142 .getProperty(SlcNames
.SLC_SUCCESS
)
149 pNode
.getNode(SlcNames
.SLC_STATUS
).setProperty(
150 SlcNames
.SLC_SUCCESS
, passed
);
151 updatePassedStatus(pNode
, passed
);
153 // one of the siblings had also the failed status so
154 // above tree remains unchanged.
157 } catch (RepositoryException e
) {
158 throw new SlcException("Cannot register listeners", e
);
162 public static void updateStatusOnRemoval(Node node
) {
164 if (!node
.hasNode(SlcNames
.SLC_STATUS
))
167 boolean pStatus
= node
.getNode(SlcNames
.SLC_STATUS
)
168 .getProperty(SlcNames
.SLC_SUCCESS
).getBoolean();
173 // success we must first check if all siblings have also
174 // successfully completed
175 boolean success
= true;
176 NodeIterator ni
= node
.getNodes();
177 children
: while (ni
.hasNext()) {
178 Node currNode
= ni
.nextNode();
179 if ((currNode
.isNodeType(SlcTypes
.SLC_DIFF_RESULT
) || currNode
180 .isNodeType(SlcTypes
.SLC_RESULT_FOLDER
))
181 && !currNode
.getNode(SlcNames
.SLC_STATUS
)
182 .getProperty(SlcNames
.SLC_SUCCESS
)
189 node
.getNode(SlcNames
.SLC_STATUS
).setProperty(
190 SlcNames
.SLC_SUCCESS
, true);
191 updatePassedStatus(node
, true);
193 // one of the siblings had also the failed status so
194 // above tree remains unchanged.
197 } catch (RepositoryException e
) {
198 throw new SlcException("Unexpected error while updating status on removal", e
);