]>
git.argeo.org Git - gpl/argeo-slc.git/blob - legacy/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/model/ResultParentUtils.java
98fd19443ee19099e9287c07530a22428a1b8f26
1 package org
.argeo
.slc
.client
.ui
.model
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Iterator
;
8 import javax
.jcr
.NodeIterator
;
9 import javax
.jcr
.Property
;
10 import javax
.jcr
.RepositoryException
;
11 import javax
.jcr
.Session
;
12 import javax
.jcr
.query
.Query
;
13 import javax
.jcr
.query
.QueryManager
;
14 import javax
.jcr
.query
.QueryResult
;
16 import org
.argeo
.slc
.SlcException
;
17 import org
.argeo
.slc
.SlcNames
;
18 import org
.argeo
.slc
.SlcTypes
;
19 import org
.argeo
.slc
.jcr
.SlcJcrResultUtils
;
21 public class ResultParentUtils
{
22 // private final static Log log =
23 // LogFactory.getLog(ResultParentUtils.class);
25 // public static Object[] orderChildren(Object[] children) {
26 // List<ResultFolder> folders = new ArrayList<ResultFolder>();
27 // List<SingleResultNode> results = new ArrayList<SingleResultNode>();
28 // for (Object child : children) {
29 // if (child instanceof ResultFolder)
30 // folders.add((ResultFolder) child);
31 // else if (child instanceof SingleResultNode)
32 // results.add((SingleResultNode) child);
35 // // Comparator first = Collections.reverseOrder();
36 // Collections.sort(folders);
37 // // Comparator<SingleResultNode> second = Collections.reverseOrder();
38 // Collections.sort(results);
40 // Object[] orderedChildren = new Object[folders.size() + results.size()];
42 // Iterator<ResultFolder> it = folders.iterator();
43 // while (it.hasNext()) {
44 // orderedChildren[i] = it.next();
47 // Iterator<SingleResultNode> it2 = results.iterator();
48 // while (it2.hasNext()) {
49 // orderedChildren[i] = it2.next();
52 // return orderedChildren;
55 public static List
<Node
> getResultsForDates(Session session
,
56 List
<String
> dateRelPathes
) {
57 if (dateRelPathes
== null || dateRelPathes
.size() == 0)
58 throw new SlcException("Specify at least one correct date as Path");
61 String basePath
= SlcJcrResultUtils
.getSlcResultsBasePath(session
);
62 Iterator
<String
> it
= dateRelPathes
.iterator();
63 StringBuffer clause
= new StringBuffer();
64 clause
.append("SELECT * FROM [");
65 clause
.append(SlcTypes
.SLC_TEST_RESULT
);
66 clause
.append("] as results");
67 clause
.append(" WHERE ");
68 while (it
.hasNext()) {
69 String absPath
= basePath
+ "/" + it
.next();
70 clause
.append("ISDESCENDANTNODE(results, [");
71 clause
.append(absPath
);
73 clause
.append(" OR ");
76 clause
.delete(clause
.length() - 4, clause
.length());
77 clause
.append(" ORDER BY results.[" + Property
.JCR_CREATED
80 // log.debug("request : " + clause.toString());
81 QueryManager qm
= session
.getWorkspace().getQueryManager();
82 Query q
= qm
.createQuery(clause
.toString(), Query
.JCR_SQL2
);
83 QueryResult result
= q
.execute();
85 NodeIterator ni
= result
.getNodes();
86 List
<Node
> nodes
= new ArrayList
<Node
>();
87 while (ni
.hasNext()) {
88 nodes
.add(ni
.nextNode());
91 } catch (RepositoryException re
) {
92 throw new SlcException(
93 "Unexpected error while getting Results for given date", re
);
98 * recursively update passed status of the current ResultFolder and its
105 public static void updatePassedStatus(Node node
, boolean passed
) {
107 if (!node
.hasNode(SlcNames
.SLC_AGGREGATED_STATUS
))
108 // we have reached the root of the tree. stop the
111 boolean pStatus
= node
.getNode(SlcNames
.SLC_AGGREGATED_STATUS
)
112 .getProperty(SlcNames
.SLC_SUCCESS
).getBoolean();
113 if (pStatus
== passed
)
117 // New status is 'failed' : we only update status of the result
120 node
.getNode(SlcNames
.SLC_AGGREGATED_STATUS
).setProperty(
121 SlcNames
.SLC_SUCCESS
, passed
);
122 updatePassedStatus(node
.getParent(), passed
);
124 // New status is 'passed': we must first check if all siblings
126 // successfully completed
127 boolean success
= true;
128 NodeIterator ni
= node
.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
))
134 .getNode(SlcNames
.SLC_AGGREGATED_STATUS
)
135 .getProperty(SlcNames
.SLC_SUCCESS
)
142 node
.getNode(SlcNames
.SLC_AGGREGATED_STATUS
).setProperty(
143 SlcNames
.SLC_SUCCESS
, passed
);
144 updatePassedStatus(node
.getParent(), passed
);
146 // one of the siblings had also the failed status so
147 // above tree remains unchanged.
150 } catch (RepositoryException e
) {
151 throw new SlcException("Cannot update result passed status", e
);