]> 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
Remove deprecated APIs
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / test / tree / TreeTestResult.java
diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java
deleted file mode 100644 (file)
index f102ae6..0000000
+++ /dev/null
@@ -1,323 +0,0 @@
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.core.test.tree;\r
-\r
-import java.io.Serializable;\r
-import java.util.ArrayList;\r
-import java.util.Date;\r
-import java.util.List;\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
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.SlcException;\r
-import org.argeo.slc.core.attachment.Attachment;\r
-import org.argeo.slc.core.attachment.AttachmentsEnabled;\r
-import org.argeo.slc.core.attachment.SimpleAttachment;\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.structure.StructureAware;\r
-import org.argeo.slc.structure.StructureElement;\r
-import org.argeo.slc.structure.StructureRegistry;\r
-import org.argeo.slc.test.TestResult;\r
-import org.argeo.slc.test.TestResultListener;\r
-import org.argeo.slc.test.TestResultPart;\r
-import org.argeo.slc.test.TestRun;\r
-import org.argeo.slc.test.TestRunAware;\r
-\r
-/**\r
- * Complex implementation of a test result compatible with a tree based\r
- * structure.\r
- */\r
-public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,\r
-               Comparable<TreeTestResult>, AttachmentsEnabled, Serializable {\r
-\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 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 SortedMap<String, String> attributes = new TreeMap<String, String>();\r
-\r
-       // Runtime Data\r
-       private TreeSPath currentPath;\r
-       private transient 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 Boolean cache = true;\r
-\r
-       private transient 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
-       }\r
-\r
-       public void addResultPart(TestResultPart part) {\r
-               if (isClosed)\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
-\r
-               if (cache) {\r
-                       PartSubList subList = resultParts.get(currentPath);\r
-                       if (subList == null) {\r
-                               subList = new PartSubList();\r
-                               resultParts.put(currentPath, subList);\r
-                       }\r
-                       subList.getParts().add(part);\r
-               }\r
-\r
-               if (part instanceof TestRunAware && currentTestRun != null) {\r
-                       ((TestRunAware) part).notifyTestRun(currentTestRun);\r
-               }\r
-\r
-               // notify listeners\r
-               synchronized (listeners) {\r
-                       for (TestResultListener<TreeTestResult> listener : listeners) {\r
-                               listener.resultPartAdded(this, part);\r
-                       }\r
-               }\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 (!cache)\r
-                       return;\r
-\r
-               if (registry != null) {\r
-                       for (TreeSPath p : path.getHierarchyAsList()) {\r
-                               if (!elements.containsKey(p)) {\r
-                                       StructureElement elem = registry.getElement(p);\r
-                                       if (elem != null) {\r
-                                               elements.put(p, elem);\r
-                                       }\r
-                               } else {\r
-                                       if (log.isTraceEnabled())\r
-                                               log.trace("An element is already registered for path "\r
-                                                               + p + " and was not updated");\r
-                               }\r
-\r
-                       }\r
-               }\r
-\r
-               currentPath = path;\r
-       }\r
-\r
-       /** Gets the current path. */\r
-       public TreeSPath getCurrentPath() {\r
-               return currentPath;\r
-       }\r
-\r
-       /** Gets all the results structured as a map of <code>PartSubList<code>s. */\r
-       public SortedMap<TreeSPath, PartSubList> getResultParts() {\r
-               return resultParts;\r
-       }\r
-\r
-       /**\r
-        * Used by ORM systems. 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
-       public void close() {\r
-               if (resultParts.size() == 0) {\r
-                       if (log.isTraceEnabled())\r
-                               log.trace("Test Result #" + getUuid()\r
-                                               + " contains no results, no need to close it.");\r
-                       return;\r
-               }\r
-\r
-               if (isClosed) {\r
-                       if (warnIfAlreadyClosed)\r
-                               log.warn("Test Result #" + getUuid()\r
-                                               + " already closed. Doing nothing.");\r
-                       return;\r
-               }\r
-\r
-               closeDate = new Date();\r
-\r
-               synchronized (listeners) {\r
-                       for (TestResultListener<TreeTestResult> listener : listeners) {\r
-                               listener.close(this);\r
-                       }\r
-               }\r
-               isClosed = true;\r
-\r
-               if (log.isTraceEnabled())\r
-                       log.trace("Test Result " + getUuid() + " closed.");\r
-       }\r
-\r
-       public Date getCloseDate() {\r
-               return closeDate;\r
-       }\r
-\r
-       /** Sets the close date (for ORM) */\r
-       public void setCloseDate(Date closeDate) {\r
-               this.closeDate = closeDate;\r
-       }\r
-\r
-       public void notifyTestRun(TestRun testRun) {\r
-               currentTestRun = testRun;\r
-       }\r
-\r
-       public SortedMap<TreeSPath, StructureElement> getElements() {\r
-               return elements;\r
-       }\r
-\r
-       public void setElements(SortedMap<TreeSPath, StructureElement> pathNames) {\r
-               this.elements = pathNames;\r
-       }\r
-\r
-       public String getUuid() {\r
-               return uuid;\r
-       }\r
-\r
-       public void setUuid(String uuid) {\r
-               this.uuid = uuid;\r
-       }\r
-\r
-       public SortedMap<TreeSPath, StructureElement> getRelatedElements(\r
-                       TreeSPath path) {\r
-               if (path == null)\r
-                       throw new SlcException(\r
-                                       "Cannot retrieve element for a null path in result #"\r
-                                                       + uuid);\r
-\r
-               SortedMap<TreeSPath, StructureElement> relatedElements = new TreeMap<TreeSPath, StructureElement>();\r
-               List<TreeSPath> hierarchy = path.getHierarchyAsList();\r
-               for (TreeSPath currPath : elements.keySet()) {\r
-                       if (hierarchy.contains(currPath)) {\r
-                               relatedElements.put(currPath, elements.get(currPath));\r
-                       }\r
-               }\r
-               return relatedElements;\r
-       }\r
-\r
-       public TestRun getCurrentTestRun() {\r
-               return currentTestRun;\r
-       }\r
-\r
-       public int compareTo(TreeTestResult ttr2) {\r
-               TreeTestResult ttr1 = this;\r
-               if (ttr1.getCloseDate() != null && ttr2.getCloseDate() != null) {\r
-                       if (ttr1.getCloseDate().equals(ttr2.getCloseDate()))\r
-                               return compareUuid(ttr1, ttr2);\r
-                       else\r
-                               return -ttr1.getCloseDate().compareTo(ttr2.getCloseDate());\r
-               } else if (ttr1.getCloseDate() != null && ttr2.getCloseDate() == null) {\r
-                       return 1;\r
-               } else if (ttr1.getCloseDate() == null && ttr2.getCloseDate() != null) {\r
-                       return -1;\r
-               } else {\r
-                       return compareUuid(ttr1, ttr2);\r
-               }\r
-       }\r
-\r
-       protected int compareUuid(TestResult ttr1, TestResult ttr2) {\r
-               if (ttr1.getUuid() == null || ttr2.getUuid() == null)\r
-                       throw new SlcException(\r
-                                       "Cannot compare tree test result with null uuid");\r
-               else {\r
-                       if (ttr1.getUuid().equals(ttr2.getUuid()))\r
-                               return 0;\r
-                       return ttr1.getUuid().compareTo(ttr2.getUuid());\r
-               }\r
-       }\r
-\r
-       public boolean equals(Object obj) {\r
-               if (obj instanceof TestResult)\r
-                       return compareUuid(this, ((TestResult) obj)) == 0;\r
-               else\r
-                       return false;\r
-       }\r
-\r
-       public int hashCode() {\r
-               if (uuid != null)\r
-                       return uuid.hashCode();\r
-               else\r
-                       return super.hashCode();\r
-       }\r
-\r
-       public SortedMap<String, String> getAttributes() {\r
-               return attributes;\r
-       }\r
-\r
-       public void setAttributes(SortedMap<String, String> attributes) {\r
-               this.attributes = attributes;\r
-       }\r
-\r
-       public void setWarnIfAlreadyClosed(Boolean warnIfAlreadyClosed) {\r
-               this.warnIfAlreadyClosed = warnIfAlreadyClosed;\r
-       }\r
-\r
-       public List<SimpleAttachment> getAttachments() {\r
-               return attachments;\r
-       }\r
-\r
-       public void setAttachments(List<SimpleAttachment> attachments) {\r
-               this.attachments = attachments;\r
-       }\r
-\r
-       public void addAttachment(Attachment attachment) {\r
-               attachments.add((SimpleAttachment) attachment);\r
-               synchronized (listeners) {\r
-                       for (TestResultListener<TreeTestResult> listener : listeners) {\r
-                               if (listener instanceof TreeTestResultListener)\r
-                                       ((TreeTestResultListener) listener).addAttachment(this,\r
-                                                       attachment);\r
-                       }\r
-               }\r
-       }\r
-\r
-       public void setStrictChecks(Boolean strictChecks) {\r
-               this.strictChecks = strictChecks;\r
-       }\r
-\r
-       /**\r
-        * Whether information should be stored in thsi object or simply forwarded\r
-        * to teh listeners.\r
-        */\r
-       public void setCache(Boolean cache) {\r
-               this.cache = cache;\r
-       }\r
-\r
-}\r