]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java
Improve logging
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / test / tree / TreeTestResult.java
index 7a90133d6418a01434be38fe3ef7a3cafcd128d2..de27b55f1089f4c926a97f9acefdd809b48a822e 100644 (file)
@@ -7,6 +7,7 @@ import java.util.List;
 import java.util.Map;\r
 import java.util.SortedMap;\r
 import java.util.TreeMap;\r
+import java.util.UUID;\r
 import java.util.Vector;\r
 \r
 import org.apache.commons.logging.Log;\r
@@ -31,29 +32,31 @@ import org.argeo.slc.test.TestRunAware;
  */\r
 public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,\r
                Comparable<TreeTestResult>, AttachmentsEnabled, Serializable {\r
-       private static final long serialVersionUID = 1L;\r
-\r
-       private Log log = LogFactory.getLog(TreeTestResult.class);\r
-\r
-       private List<TestResultListener<TreeTestResult>> listeners = new Vector<TestResultListener<TreeTestResult>>();\r
 \r
-       private TreeSPath currentPath;\r
-       private TestRun currentTestRun;\r
+       private static final long serialVersionUID = 1L;\r
+       private final static Log log = LogFactory.getLog(TreeTestResult.class);\r
 \r
+       // Persistence data\r
+       private String uuid = UUID.randomUUID().toString();\r
        private Date closeDate;\r
 \r
-       private Boolean isClosed = false;\r
-\r
-       private Boolean warnIfAlreadyClosed = true;\r
-\r
-       private String uuid;\r
-\r
        private SortedMap<TreeSPath, PartSubList> resultParts = new TreeMap<TreeSPath, PartSubList>();\r
        private SortedMap<TreeSPath, StructureElement> elements = new TreeMap<TreeSPath, StructureElement>();\r
        private List<SimpleAttachment> attachments = new ArrayList<SimpleAttachment>();\r
 \r
+       // Headers. Used to accelerate request on a specific test result.\r
        private Map<String, String> attributes = new TreeMap<String, String>();\r
 \r
+       // Runtime Data\r
+       private TreeSPath currentPath;\r
+       private TestRun currentTestRun;\r
+       private Boolean warnIfAlreadyClosed = true;\r
+       private Boolean strictChecks = false;\r
+       // TODO is it really necessary closeDate == null ?\r
+       private Boolean isClosed = false;\r
+\r
+       private List<TestResultListener<TreeTestResult>> listeners = new Vector<TestResultListener<TreeTestResult>>();\r
+\r
        /** Sets the list of listeners. */\r
        public void setListeners(List<TestResultListener<TreeTestResult>> listeners) {\r
                this.listeners = listeners;\r
@@ -61,7 +64,11 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
 \r
        public void addResultPart(TestResultPart part) {\r
                if (isClosed)\r
-                       throw new SlcException("Cannot result parts to a closed result");\r
+                       notifyIssue(\r
+                                       "Trying to add result parts to an already closed result,"\r
+                                                       + " consider changing the scope of this test result:"\r
+                                                       + " you are referencing the same stored data with each new call.",\r
+                                       null);\r
 \r
                if (currentPath == null)\r
                        throw new SlcException("No current path set.");\r
@@ -84,6 +91,13 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
                }\r
        }\r
 \r
+       protected void notifyIssue(String msg, Exception e) {\r
+               if (strictChecks)\r
+                       throw new SlcException(msg, e);\r
+               else\r
+                       log.error(msg, e);\r
+       }\r
+\r
        public void notifyCurrentPath(StructureRegistry<TreeSPath> registry,\r
                        TreeSPath path) {\r
                if (registry != null) {\r
@@ -115,8 +129,11 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
                return resultParts;\r
        }\r
 \r
-       /** Used by ORM systems. */\r
-       void setResultParts(SortedMap<TreeSPath, PartSubList> resultParts) {\r
+       /**\r
+        * Used by ORM systems. \r
+        * Changed to public in order to enable jcr persistence\r
+        */\r
+       public void setResultParts(SortedMap<TreeSPath, PartSubList> resultParts) {\r
                this.resultParts = resultParts;\r
        }\r
 \r
@@ -270,4 +287,8 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
                }\r
        }\r
 \r
+       public void setStrictChecks(Boolean strictChecks) {\r
+               this.strictChecks = strictChecks;\r
+       }\r
+\r
 }\r