]>
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
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.client
.ui
.model
;
18 import java
.util
.ArrayList
;
19 import java
.util
.Iterator
;
20 import java
.util
.List
;
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
;
31 import org
.argeo
.slc
.SlcException
;
32 import org
.argeo
.slc
.jcr
.SlcJcrResultUtils
;
33 import org
.argeo
.slc
.jcr
.SlcNames
;
34 import org
.argeo
.slc
.jcr
.SlcTypes
;
36 public class ResultParentUtils
{
37 // private final static Log log =
38 // LogFactory.getLog(ResultParentUtils.class);
40 // public static Object[] orderChildren(Object[] children) {
41 // List<ResultFolder> folders = new ArrayList<ResultFolder>();
42 // List<SingleResultNode> results = new ArrayList<SingleResultNode>();
43 // for (Object child : children) {
44 // if (child instanceof ResultFolder)
45 // folders.add((ResultFolder) child);
46 // else if (child instanceof SingleResultNode)
47 // results.add((SingleResultNode) child);
50 // // Comparator first = Collections.reverseOrder();
51 // Collections.sort(folders);
52 // // Comparator<SingleResultNode> second = Collections.reverseOrder();
53 // Collections.sort(results);
55 // Object[] orderedChildren = new Object[folders.size() + results.size()];
57 // Iterator<ResultFolder> it = folders.iterator();
58 // while (it.hasNext()) {
59 // orderedChildren[i] = it.next();
62 // Iterator<SingleResultNode> it2 = results.iterator();
63 // while (it2.hasNext()) {
64 // orderedChildren[i] = it2.next();
67 // return orderedChildren;
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");
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_DIFF_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
);
88 clause
.append(" OR ");
91 clause
.delete(clause
.length() - 4, clause
.length());
92 clause
.append(" ORDER BY results.[" + Property
.JCR_CREATED
95 // log.debug("request : " + clause.toString());
96 QueryManager qm
= session
.getWorkspace().getQueryManager();
97 Query q
= qm
.createQuery(clause
.toString(), Query
.JCR_SQL2
);
98 QueryResult result
= q
.execute();
100 NodeIterator ni
= result
.getNodes();
101 List
<Node
> nodes
= new ArrayList
<Node
>();
102 while (ni
.hasNext()) {
103 nodes
.add(ni
.nextNode());
106 } catch (RepositoryException re
) {
107 throw new SlcException(
108 "Unexpected error while getting Results for given date", re
);
113 * recursively update passed status of the current ResultFolder and its
120 public static void updatePassedStatus(Node node
, boolean passed
) {
122 if (!node
.hasNode(SlcNames
.SLC_STATUS
))
123 // we have reached the root of the tree. stop the
126 boolean pStatus
= node
.getNode(SlcNames
.SLC_STATUS
)
127 .getProperty(SlcNames
.SLC_SUCCESS
).getBoolean();
128 if (pStatus
== passed
)
132 // New status is 'failed' : we only update status of the result
135 node
.getNode(SlcNames
.SLC_STATUS
).setProperty(
136 SlcNames
.SLC_SUCCESS
, passed
);
137 updatePassedStatus(node
.getParent(), passed
);
139 // New status is 'passed': we must first check if all siblings
141 // successfully completed
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
.getNode(SlcNames
.SLC_STATUS
)
149 .getProperty(SlcNames
.SLC_SUCCESS
)
156 node
.getNode(SlcNames
.SLC_STATUS
).setProperty(
157 SlcNames
.SLC_SUCCESS
, passed
);
158 updatePassedStatus(node
.getParent(), passed
);
160 // one of the siblings had also the failed status so
161 // above tree remains unchanged.
164 } catch (RepositoryException e
) {
165 throw new SlcException("Cannot update result passed status", e
);