X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.slc.client.ui%2Fsrc%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fmodel%2FResultParentUtils.java;fp=org.argeo.slc.client.ui%2Fsrc%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fmodel%2FResultParentUtils.java;h=0000000000000000000000000000000000000000;hb=ecc22e604e47533c79de9cecdcdeacbc752cbff1;hp=98fd19443ee19099e9287c07530a22428a1b8f26;hpb=e07ded4632e53f8b8869763bc1f1f4091361e76e;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/model/ResultParentUtils.java b/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/model/ResultParentUtils.java deleted file mode 100644 index 98fd19443..000000000 --- a/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/model/ResultParentUtils.java +++ /dev/null @@ -1,154 +0,0 @@ -package org.argeo.slc.client.ui.model; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import javax.jcr.Node; -import javax.jcr.NodeIterator; -import javax.jcr.Property; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.query.Query; -import javax.jcr.query.QueryManager; -import javax.jcr.query.QueryResult; - -import org.argeo.slc.SlcException; -import org.argeo.slc.SlcNames; -import org.argeo.slc.SlcTypes; -import org.argeo.slc.jcr.SlcJcrResultUtils; - -public class ResultParentUtils { - // private final static Log log = - // LogFactory.getLog(ResultParentUtils.class); - - // public static Object[] orderChildren(Object[] children) { - // List folders = new ArrayList(); - // List results = new ArrayList(); - // for (Object child : children) { - // if (child instanceof ResultFolder) - // folders.add((ResultFolder) child); - // else if (child instanceof SingleResultNode) - // results.add((SingleResultNode) child); - // } - // - // // Comparator first = Collections.reverseOrder(); - // Collections.sort(folders); - // // Comparator second = Collections.reverseOrder(); - // Collections.sort(results); - // - // Object[] orderedChildren = new Object[folders.size() + results.size()]; - // int i = 0; - // Iterator it = folders.iterator(); - // while (it.hasNext()) { - // orderedChildren[i] = it.next(); - // i++; - // } - // Iterator it2 = results.iterator(); - // while (it2.hasNext()) { - // orderedChildren[i] = it2.next(); - // i++; - // } - // return orderedChildren; - // } - - public static List getResultsForDates(Session session, - List dateRelPathes) { - if (dateRelPathes == null || dateRelPathes.size() == 0) - throw new SlcException("Specify at least one correct date as Path"); - - try { - String basePath = SlcJcrResultUtils.getSlcResultsBasePath(session); - Iterator it = dateRelPathes.iterator(); - StringBuffer clause = new StringBuffer(); - clause.append("SELECT * FROM ["); - clause.append(SlcTypes.SLC_TEST_RESULT); - clause.append("] as results"); - clause.append(" WHERE "); - while (it.hasNext()) { - String absPath = basePath + "/" + it.next(); - clause.append("ISDESCENDANTNODE(results, ["); - clause.append(absPath); - clause.append("]) "); - clause.append(" OR "); - } - // remove last " OR " - clause.delete(clause.length() - 4, clause.length()); - clause.append(" ORDER BY results.[" + Property.JCR_CREATED - + "] DESC"); - - // log.debug("request : " + clause.toString()); - QueryManager qm = session.getWorkspace().getQueryManager(); - Query q = qm.createQuery(clause.toString(), Query.JCR_SQL2); - QueryResult result = q.execute(); - - NodeIterator ni = result.getNodes(); - List nodes = new ArrayList(); - while (ni.hasNext()) { - nodes.add(ni.nextNode()); - } - return nodes; - } catch (RepositoryException re) { - throw new SlcException( - "Unexpected error while getting Results for given date", re); - } - } - - /** - * recursively update passed status of the current ResultFolder and its - * parent if needed - * - * @param node - * cannot be null - * - */ - public static void updatePassedStatus(Node node, boolean passed) { - try { - if (!node.hasNode(SlcNames.SLC_AGGREGATED_STATUS)) - // we have reached the root of the tree. stop the - // recursivity - return; - boolean pStatus = node.getNode(SlcNames.SLC_AGGREGATED_STATUS) - .getProperty(SlcNames.SLC_SUCCESS).getBoolean(); - if (pStatus == passed) - // nothing to update - return; - else if (!passed) { - // New status is 'failed' : we only update status of the result - // folder and its - // parent if needed - node.getNode(SlcNames.SLC_AGGREGATED_STATUS).setProperty( - SlcNames.SLC_SUCCESS, passed); - updatePassedStatus(node.getParent(), passed); - } else { - // New status is 'passed': we must first check if all siblings - // have also - // successfully completed - boolean success = true; - NodeIterator ni = node.getNodes(); - children: while (ni.hasNext()) { - Node currNode = ni.nextNode(); - if ((currNode.isNodeType(SlcTypes.SLC_DIFF_RESULT) || currNode - .isNodeType(SlcTypes.SLC_RESULT_FOLDER)) - && !currNode - .getNode(SlcNames.SLC_AGGREGATED_STATUS) - .getProperty(SlcNames.SLC_SUCCESS) - .getBoolean()) { - success = false; - break children; - } - } - if (success) { - node.getNode(SlcNames.SLC_AGGREGATED_STATUS).setProperty( - SlcNames.SLC_SUCCESS, passed); - updatePassedStatus(node.getParent(), passed); - } else - // one of the siblings had also the failed status so - // above tree remains unchanged. - return; - } - } catch (RepositoryException e) { - throw new SlcException("Cannot update result passed status", e); - } - } -}