1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.argeo.slc.client.ui.model;
17
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21
22 import javax.jcr.Node;
23 import javax.jcr.NodeIterator;
24 import javax.jcr.Property;
25 import javax.jcr.RepositoryException;
26 import javax.jcr.Session;
27 import javax.jcr.query.Query;
28 import javax.jcr.query.QueryManager;
29 import javax.jcr.query.QueryResult;
30
31 import org.argeo.slc.SlcException;
32 import org.argeo.slc.SlcNames;
33 import org.argeo.slc.SlcTypes;
34 import org.argeo.slc.jcr.SlcJcrResultUtils;
35
36 public class ResultParentUtils {
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 public static List<Node> getResultsForDates(Session session,
71 List<String> dateRelPathes) {
72 if (dateRelPathes == null || dateRelPathes.size() == 0)
73 throw new SlcException("Specify at least one correct date as Path");
74
75 try {
76 String basePath = SlcJcrResultUtils.getSlcResultsBasePath(session);
77 Iterator<String> it = dateRelPathes.iterator();
78 StringBuffer clause = new StringBuffer();
79 clause.append("SELECT * FROM [");
80 clause.append(SlcTypes.SLC_TEST_RESULT);
81 clause.append("] as results");
82 clause.append(" WHERE ");
83 while (it.hasNext()) {
84 String absPath = basePath + "/" + it.next();
85 clause.append("ISDESCENDANTNODE(results, [");
86 clause.append(absPath);
87 clause.append("]) ");
88 clause.append(" OR ");
89 }
90
91 clause.delete(clause.length() - 4, clause.length());
92 clause.append(" ORDER BY results.[" + Property.JCR_CREATED
93 + "] DESC");
94
95
96 QueryManager qm = session.getWorkspace().getQueryManager();
97 Query q = qm.createQuery(clause.toString(), Query.JCR_SQL2);
98 QueryResult result = q.execute();
99
100 NodeIterator ni = result.getNodes();
101 List<Node> nodes = new ArrayList<Node>();
102 while (ni.hasNext()) {
103 nodes.add(ni.nextNode());
104 }
105 return nodes;
106 } catch (RepositoryException re) {
107 throw new SlcException(
108 "Unexpected error while getting Results for given date", re);
109 }
110 }
111
112
113
114
115
116
117
118
119
120 public static void updatePassedStatus(Node node, boolean passed) {
121 try {
122 if (!node.hasNode(SlcNames.SLC_AGGREGATED_STATUS))
123
124
125 return;
126 boolean pStatus = node.getNode(SlcNames.SLC_AGGREGATED_STATUS)
127 .getProperty(SlcNames.SLC_SUCCESS).getBoolean();
128 if (pStatus == passed)
129
130 return;
131 else if (!passed) {
132
133
134
135 node.getNode(SlcNames.SLC_AGGREGATED_STATUS).setProperty(
136 SlcNames.SLC_SUCCESS, passed);
137 updatePassedStatus(node.getParent(), passed);
138 } else {
139
140
141
142 boolean success = true;
143 NodeIterator ni = node.getNodes();
144 children: while (ni.hasNext()) {
145 Node currNode = ni.nextNode();
146 if ((currNode.isNodeType(SlcTypes.SLC_DIFF_RESULT) || currNode
147 .isNodeType(SlcTypes.SLC_RESULT_FOLDER))
148 && !currNode
149 .getNode(SlcNames.SLC_AGGREGATED_STATUS)
150 .getProperty(SlcNames.SLC_SUCCESS)
151 .getBoolean()) {
152 success = false;
153 break children;
154 }
155 }
156 if (success) {
157 node.getNode(SlcNames.SLC_AGGREGATED_STATUS).setProperty(
158 SlcNames.SLC_SUCCESS, passed);
159 updatePassedStatus(node.getParent(), passed);
160 } else
161
162
163 return;
164 }
165 } catch (RepositoryException e) {
166 throw new SlcException("Cannot update result passed status", e);
167 }
168 }
169 }