]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrResultListener.java
Adapt to changes in Argeo Commons
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.jcr / src / main / java / org / argeo / slc / jcr / execution / JcrResultListener.java
index 733bac7fbbd2cfbc0b1ecbf4448fab06c6f5e70d..ce5dbf76ce6ad9202611e6dca3d34455ae6d88be 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * 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.jcr.execution;
 
 import java.util.Collections;
@@ -21,6 +36,8 @@ import org.argeo.slc.SlcException;
 import org.argeo.slc.core.attachment.Attachment;
 import org.argeo.slc.core.structure.SimpleSElement;
 import org.argeo.slc.core.structure.tree.TreeSPath;
+import org.argeo.slc.core.test.SimpleResultPart;
+import org.argeo.slc.core.test.tree.PartSubList;
 import org.argeo.slc.core.test.tree.TreeTestResult;
 import org.argeo.slc.core.test.tree.TreeTestResultListener;
 import org.argeo.slc.jcr.SlcJcrUtils;
@@ -29,7 +46,11 @@ import org.argeo.slc.jcr.SlcTypes;
 import org.argeo.slc.test.TestResultPart;
 import org.argeo.slc.test.TestStatus;
 
-/** Persists results in JCR */
+/**
+ * Persists results in JCR by listening to {@link TreeTestResult}. This is to
+ * facilitate transition from legacy approaches and should not be used in new
+ * implementations.
+ */
 public class JcrResultListener implements TreeTestResultListener, SlcNames {
        private final static Log log = LogFactory.getLog(JcrResultListener.class);
 
@@ -66,7 +87,6 @@ public class JcrResultListener implements TreeTestResultListener, SlcNames {
                                // session.save();
                        }
                        // create part node
-                       // TODO find a better name
                        SimpleSElement element = null;
                        if (testResult.getElements().containsKey(currentPath)) {
                                element = (SimpleSElement) testResult.getElements().get(
@@ -148,8 +168,8 @@ public class JcrResultListener implements TreeTestResultListener, SlcNames {
        protected Node createResultNode(TreeTestResult testResult)
                        throws RepositoryException {
                String uuid = testResult.getUuid();
-               String path = SlcJcrUtils.createResultPath(uuid);
-               Node resultNode = JcrUtils.mkdirs(session, path, SlcTypes.SLC_RESULT);
+               String path = SlcJcrUtils.createResultPath(session, uuid);
+               Node resultNode = JcrUtils.mkdirs(session, path, SlcTypes.SLC_TEST_RESULT);
                resultNode.setProperty(SLC_UUID, uuid);
                for (Map.Entry<String, String> entry : testResult.getAttributes()
                                .entrySet()) {
@@ -173,6 +193,9 @@ public class JcrResultListener implements TreeTestResultListener, SlcNames {
 
                        uuidToIdentifier.remove(uuid);
                        session.save();
+
+                       if (log.isDebugEnabled())
+                               log.debug("Closed test result " + uuid);
                } catch (RepositoryException e) {
                        JcrUtils.discardQuietly(session);
                        log.error("Cannot close result " + testResult, e);
@@ -224,7 +247,20 @@ public class JcrResultListener implements TreeTestResultListener, SlcNames {
                                                resultPath.length());
                                TreeSPath tsp = new TreeSPath(relPath);
 
-                               // TODO result part
+                               // result part
+                               SimpleResultPart srp = new SimpleResultPart();
+                               if (checkNode.getProperty(SLC_SUCCESS).getBoolean())
+                                       srp.setStatus(TestStatus.PASSED);
+                               else if (checkNode.hasProperty(SLC_ERROR_MESSAGE))
+                                       srp.setStatus(TestStatus.ERROR);
+                               else
+                                       srp.setStatus(TestStatus.FAILED);
+                               if (checkNode.hasProperty(SLC_MESSAGE))
+                                       srp.setMessage(checkNode.getProperty(SLC_MESSAGE)
+                                                       .getString());
+                               if (!ttr.getResultParts().containsKey(tsp))
+                                       ttr.getResultParts().put(tsp, new PartSubList());
+                               ttr.getResultParts().get(tsp).getParts().add(srp);
 
                                // element
                                SimpleSElement elem = new SimpleSElement();