]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ResultParentUtils.java
remove useless carriage return
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / model / ResultParentUtils.java
index fc4eec77f640d08926851b0c4e15cba36b33ee85..d569167dc9c1b0e9e6e435fed81f153a1f3b5aa5 100644 (file)
@@ -1,7 +1,21 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.argeo.slc.client.ui.model;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
@@ -14,47 +28,46 @@ import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.argeo.slc.SlcException;
 import org.argeo.slc.jcr.SlcJcrResultUtils;
 import org.argeo.slc.jcr.SlcNames;
 import org.argeo.slc.jcr.SlcTypes;
 
 public class ResultParentUtils {
-       private final static Log log = LogFactory.getLog(ResultParentUtils.class);
+       // private final static Log log =
+       // LogFactory.getLog(ResultParentUtils.class);
 
-       public static Object[] orderChildren(Object[] children) {
-               List<ResultFolder> folders = new ArrayList<ResultFolder>();
-               List<SingleResultNode> results = new ArrayList<SingleResultNode>();
-               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<SingleResultNode> second = Collections.reverseOrder();
-               Collections.sort(results);
-
-               Object[] orderedChildren = new Object[children.length];
-               int i = 0;
-               Iterator<ResultFolder> it = folders.iterator();
-               while (it.hasNext()) {
-                       orderedChildren[i] = it.next();
-                       i++;
-               }
-               Iterator<SingleResultNode> it2 = results.iterator();
-               while (it2.hasNext()) {
-                       orderedChildren[i] = it2.next();
-                       i++;
-               }
-               return orderedChildren;
-       }
+       // public static Object[] orderChildren(Object[] children) {
+       // List<ResultFolder> folders = new ArrayList<ResultFolder>();
+       // List<SingleResultNode> results = new ArrayList<SingleResultNode>();
+       // 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<SingleResultNode> second = Collections.reverseOrder();
+       // Collections.sort(results);
+       //
+       // Object[] orderedChildren = new Object[folders.size() + results.size()];
+       // int i = 0;
+       // Iterator<ResultFolder> it = folders.iterator();
+       // while (it.hasNext()) {
+       // orderedChildren[i] = it.next();
+       // i++;
+       // }
+       // Iterator<SingleResultNode> it2 = results.iterator();
+       // while (it2.hasNext()) {
+       // orderedChildren[i] = it2.next();
+       // i++;
+       // }
+       // return orderedChildren;
+       // }
 
-       public static ResultParent[] getResultsForDates(Session session,
+       public static List<Node> getResultsForDates(Session session,
                        List<String> dateRelPathes) {
                if (dateRelPathes == null || dateRelPathes.size() == 0)
                        throw new SlcException("Specify at least one correct date as Path");
@@ -85,18 +98,11 @@ public class ResultParentUtils {
                        QueryResult result = q.execute();
 
                        NodeIterator ni = result.getNodes();
-                       ResultParent[] results = new ResultParent[(int) ni.getSize()];
-                       int i = 0;
+                       List<Node> nodes = new ArrayList<Node>();
                        while (ni.hasNext()) {
-                               Node currNode = ni.nextNode();
-                               SingleResultNode srn = new SingleResultNode(null, currNode,
-                                               currNode.getProperty(SlcNames.SLC_TEST_CASE)
-                                                               .getString());
-
-                               results[i] = srn;
-                               i++;
+                               nodes.add(ni.nextNode());
                        }
-                       return results;
+                       return nodes;
                } catch (RepositoryException re) {
                        throw new SlcException(
                                        "Unexpected error while getting Results for given date", re);
@@ -104,7 +110,7 @@ public class ResultParentUtils {
        }
 
        /**
-        * recursively update passed status of the parent ResultFolder and its
+        * recursively update passed status of the current ResultFolder and its
         * parent if needed
         * 
         * @param node
@@ -113,64 +119,25 @@ public class ResultParentUtils {
         */
        public static void updatePassedStatus(Node node, boolean passed) {
                try {
-                       Node pNode = node.getParent();
-                       if (!pNode.hasNode(SlcNames.SLC_STATUS))
+                       if (!node.hasNode(SlcNames.SLC_STATUS))
                                // we have reached the root of the tree. stop the
                                // recursivity
                                return;
-                       boolean pStatus = pNode.getNode(SlcNames.SLC_STATUS)
+                       boolean pStatus = node.getNode(SlcNames.SLC_STATUS)
                                        .getProperty(SlcNames.SLC_SUCCESS).getBoolean();
                        if (pStatus == passed)
                                // nothing to update
                                return;
                        else if (!passed) {
-                               // error we only update status of the result folder and its
+                               // New status is 'failed' : we only update status of the result
+                               // folder and its
                                // parent if needed
-                               pNode.getNode(SlcNames.SLC_STATUS).setProperty(
+                               node.getNode(SlcNames.SLC_STATUS).setProperty(
                                                SlcNames.SLC_SUCCESS, passed);
-                               updatePassedStatus(pNode, passed);
+                               updatePassedStatus(node.getParent(), passed);
                        } else {
-                               // success we must first check if all siblings have also
-                               // successfully completed
-                               boolean success = true;
-                               NodeIterator ni = pNode.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_STATUS)
-                                                                       .getProperty(SlcNames.SLC_SUCCESS)
-                                                                       .getBoolean()) {
-                                               success = false;
-                                               break children;
-                                       }
-                               }
-                               if (success) {
-                                       pNode.getNode(SlcNames.SLC_STATUS).setProperty(
-                                                       SlcNames.SLC_SUCCESS, passed);
-                                       updatePassedStatus(pNode, passed);
-                               } else
-                                       // one of the siblings had also the failed status so
-                                       // above tree remains unchanged.
-                                       return;
-                       }
-               } catch (RepositoryException e) {
-                       throw new SlcException("Cannot register listeners", e);
-               }
-       }
-
-       public static void updateStatusOnRemoval(Node node) {
-               try {
-                       if (!node.hasNode(SlcNames.SLC_STATUS))
-                               // nothing to do
-                               return;
-                       boolean pStatus = node.getNode(SlcNames.SLC_STATUS)
-                                       .getProperty(SlcNames.SLC_SUCCESS).getBoolean();
-                       if (pStatus == true)
-                               // nothing to update
-                               return;
-                       else {
-                               // success we must first check if all siblings have also
+                               // New status is 'passed': we must first check if all siblings
+                               // have also
                                // successfully completed
                                boolean success = true;
                                NodeIterator ni = node.getNodes();
@@ -187,16 +154,15 @@ public class ResultParentUtils {
                                }
                                if (success) {
                                        node.getNode(SlcNames.SLC_STATUS).setProperty(
-                                                       SlcNames.SLC_SUCCESS, true);
-                                       updatePassedStatus(node, true);
+                                                       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("Unexpected error while updating status on removal", e);
+                       throw new SlcException("Cannot update result passed status", e);
                }
        }
-
 }