]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
TreeTestResult persistence independent from TreeSPath and registry (at last!)
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 25 Apr 2008 08:04:41 +0000 (08:04 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 25 Apr 2008 08:04:41 +0000 (08:04 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@1071 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/tree/TreeSPath.java
org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java
org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResultPersister.java
org.argeo.slc.core/src/main/java/org/argeo/slc/hibernate/test/tree/TestResultDaoHibernate.java
org.argeo.slc.core/src/main/resources/org/argeo/slc/hibernate/test/tree/TreeTestResult.hbm.xml
org.argeo.slc.core/src/test/java/org/argeo/slc/hibernate/test/tree/TreeTestResultDaoHibernateTest.java

index 3003069965588982c7cac8e97b600326a8d91590..e38d0e3ddff6103f9771f02651a6a0a3a002b4ec 100644 (file)
@@ -19,12 +19,17 @@ public class TreeSPath implements StructurePath, Comparable<StructurePath> {
        private String name;\r
        private Character separator = DEFAULT_SEPARATOR;\r
 \r
+       private String asUniqueString;\r
+\r
        /** For ORM */\r
        private Long tid;\r
 \r
        public String getAsUniqueString() {\r
-               String parentStr = parent != null ? parent.getAsUniqueString() : "";\r
-               return parentStr + separator + name;\r
+               if (asUniqueString == null) {\r
+                       String parentStr = parent != null ? parent.getAsUniqueString() : "";\r
+                       asUniqueString = parentStr + separator + name;\r
+               }\r
+               return asUniqueString;\r
        }\r
 \r
        /** Sets all the required data from a string. */\r
@@ -32,6 +37,7 @@ public class TreeSPath implements StructurePath, Comparable<StructurePath> {
                TreeSPath twin = parseToCreatePath(str, getSeparator());\r
                name = twin.name;\r
                parent = twin.parent;\r
+               asUniqueString = getAsUniqueString();\r
        }\r
 \r
        /** The separator actually used by this path. */\r
@@ -123,7 +129,7 @@ public class TreeSPath implements StructurePath, Comparable<StructurePath> {
                return depthImpl(this);\r
        }\r
 \r
-       private static int depthImpl(TreeSPath path) {\r
+       protected int depthImpl(TreeSPath path) {\r
                if (path.getParent() == null) {\r
                        return 1;\r
                } else {\r
@@ -131,6 +137,21 @@ public class TreeSPath implements StructurePath, Comparable<StructurePath> {
                }\r
        }\r
 \r
+       public List<TreeSPath> getHierarchyAsList() {\r
+               List<TreeSPath> lst = new Vector<TreeSPath>();\r
+               addParentToList(lst, this);\r
+               lst.add(this);\r
+               return lst;\r
+       }\r
+\r
+       protected void addParentToList(List<TreeSPath> lst, TreeSPath current) {\r
+               TreeSPath parent = current.getParent();\r
+               if (parent != null) {\r
+                       addParentToList(lst, parent);\r
+                       lst.add(parent);\r
+               }\r
+       }\r
+\r
        @Override\r
        public String toString() {\r
                return getAsUniqueString();\r
@@ -145,6 +166,11 @@ public class TreeSPath implements StructurePath, Comparable<StructurePath> {
                return false;\r
        }\r
 \r
+       @Override\r
+       public int hashCode() {\r
+               return getAsUniqueString().hashCode();\r
+       }\r
+\r
        public int compareTo(StructurePath o) {\r
                return getAsUniqueString().compareTo(o.getAsUniqueString());\r
        }\r
@@ -157,7 +183,11 @@ public class TreeSPath implements StructurePath, Comparable<StructurePath> {
                this.tid = tid;\r
        }\r
 \r
-       /** Sets the separator character to use. */\r
+       /**\r
+        * Sets the separator character to use.\r
+        * \r
+        * @deprecated\r
+        */\r
        public void setSeparator(Character separator) {\r
                this.separator = separator;\r
        }\r
index 3ce0c99b5a6408d324a990c048c1df93f3366357..36233e9942a2d321cb73b39d5d86842638adb275 100644 (file)
@@ -14,6 +14,7 @@ import org.argeo.slc.core.process.SlcExecution;
 import org.argeo.slc.core.process.SlcExecutionAware;\r
 import org.argeo.slc.core.process.SlcExecutionStep;\r
 import org.argeo.slc.core.structure.StructureAware;\r
+import org.argeo.slc.core.structure.StructureElement;\r
 import org.argeo.slc.core.structure.StructureRegistry;\r
 import org.argeo.slc.core.structure.tree.TreeSPath;\r
 import org.argeo.slc.core.test.NumericTRId;\r
@@ -26,7 +27,8 @@ import org.argeo.slc.core.test.TestResultPart;
  * Complex implementation of a test result compatible with a tree based\r
  * structure.\r
  */\r
-public class TreeTestResult implements TestResult, StructureAware<TreeSPath>, SlcExecutionAware {\r
+public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,\r
+               SlcExecutionAware {\r
        private Log log = LogFactory.getLog(TreeTestResult.class);\r
        /** For ORM */\r
        private Long tid;\r
@@ -90,7 +92,19 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>, Sl
                }\r
        }\r
 \r
-       public void notifyCurrentPath(StructureRegistry<TreeSPath> registry, TreeSPath path) {\r
+       public void notifyCurrentPath(StructureRegistry<TreeSPath> registry,\r
+                       TreeSPath path) {\r
+               if (registry != null) {\r
+                       for (TreeSPath p : path.getHierarchyAsList()) {\r
+                               if (!pathNames.containsKey(p)) {\r
+                                       StructureElement elem = registry.getElement(p);\r
+                                       if (elem != null) {\r
+                                               pathNames.put(p, elem.getLabel());\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
                currentPath = (TreeSPath) path;\r
                this.registry = registry;\r
        }\r
@@ -142,10 +156,9 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>, Sl
        }\r
 \r
        /** Sets the related registry. */\r
-//     public void setRegistry(StructureRegistry<TreeSPath> registry) {\r
-//             this.registry = registry;\r
-//     }\r
-\r
+       // public void setRegistry(StructureRegistry<TreeSPath> registry) {\r
+       // this.registry = registry;\r
+       // }\r
        public Date getCloseDate() {\r
                return closeDate;\r
        }\r
@@ -158,9 +171,17 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>, Sl
        public void notifySlcExecution(SlcExecution slcExecution) {\r
                currentSlcExecutionUuid = slcExecution.getUuid();\r
                SlcExecutionStep step = slcExecution.currentStep();\r
-               if(step!=null){\r
+               if (step != null) {\r
                        currentSlcExecutionStepUuid = step.getUuid();\r
                }\r
        }\r
 \r
+       public SortedMap<TreeSPath, String> getPathNames() {\r
+               return pathNames;\r
+       }\r
+\r
+       public void setPathNames(SortedMap<TreeSPath, String> pathNames) {\r
+               this.pathNames = pathNames;\r
+       }\r
+\r
 }\r
index 164c540b8b1251bd8095aa346024e3c41c925803..12eed249afd5c98650a6ef3e1bbb268817b83fda 100644 (file)
@@ -30,7 +30,14 @@ public class TreeTestResultPersister extends AsynchronousTreeTestResultListener
                try {\r
                        TreeTestResult persistedResult = testResultDao\r
                                        .getTestResult(partStruct.resultId);\r
-\r
+                       \r
+                       if(persistedResult==null){\r
+                               testResultDao.create(partStruct.result);\r
+                       }\r
+                       else{\r
+                               testResultDao.update(partStruct.result);\r
+                       }\r
+/*\r
                        TreeSPath path = treeSPathDao.getOrCreate(partStruct.path);\r
 \r
                        StructureRegistry<TreeSPath> localRegistry = partStruct.result\r
@@ -64,7 +71,7 @@ public class TreeTestResultPersister extends AsynchronousTreeTestResultListener
                                        log.trace("Part: " + partStruct.part);\r
                                }\r
                                testResultDao.update(persistedResult);\r
-                       }\r
+                       }*/\r
                } catch (Exception e) {\r
                        log.error("Could not persist part for result #"\r
                                        + partStruct.resultId, e);\r
@@ -111,30 +118,5 @@ public class TreeTestResultPersister extends AsynchronousTreeTestResultListener
        public void setTreeSRegistryDao(TreeSRegistryDao treeSRegistryDao) {\r
                this.treeSRegistryDao = treeSRegistryDao;\r
        }\r
-/*\r
-       private void syncPath(TreeSRegistry registry,\r
-                       StructureRegistry<TreeSPath> localRegistry, TreeSPath path) {\r
-               if (path.getParent() != null) {\r
-                       TreeSPath parent = treeSPathDao.getOrCreate(path.getParent());\r
-                       syncPath(registry, localRegistry, parent);\r
-               }\r
-\r
-               if (registry.getElement(path) == null) {\r
-                       if (localRegistry != null) {\r
-                               registry.register(path, localRegistry.getElement(path));\r
-                       } else {\r
-                               registry.register(path, new SimpleSElement(path.getName()));\r
-                       }\r
-                       treeSRegistryDao.update(registry);\r
-               } else {\r
-                       if (localRegistry != null) {\r
-                               StructureElement sElement = localRegistry.getElement(path);\r
-                               if (sElement != null) {\r
-                                       registry.register(path, sElement);\r
-                                       treeSRegistryDao.update(registry);\r
-                               }\r
-                       }\r
-               }\r
 \r
-       }*/\r
 }\r
index 7b7fbf45e4aab9433397731b754a5c9f50ce2a49..9dc76d6e1dc886463238f7506d289789b3123ffb 100644 (file)
@@ -48,7 +48,7 @@ public class TestResultDaoHibernate extends HibernateDaoSupport implements
        public List<TreeTestResult> listResults(TreeSPath path) {\r
                List<TreeTestResult> list = getHibernateTemplate().find(\r
                                "from TreeTestResult res where ? in indices(res.resultParts)",\r
-                               path);\r
+                               path.getAsUniqueString());\r
                return list;\r
        }\r
 \r
index 5b7bcb38dea88d230e5c3c58c77f788f99a35c56..9de6a80456438ec23d76ed2d386b3980944db183 100644 (file)
                <map name="resultParts" table="RESULT_PARTS_MAP" cascade="all"\r
                        lazy="false" sort="natural">\r
                        <key column="PARENT_ID" />\r
-                       <map-key-many-to-many\r
+                       <!-- \r
+                               <map-key-many-to-many\r
                                class="org.argeo.slc.core.structure.tree.TreeSPath" column="PATH" />\r
+                       -->\r
+                       <composite-map-key\r
+                               class="org.argeo.slc.core.structure.tree.TreeSPath">\r
+                               <key-property name="asUniqueString" column="PATH" />\r
+                       </composite-map-key>\r
                        <many-to-many class="PartSubList" column="PART_SUB_LIST_ID"\r
                                unique="true" lazy="false" />\r
                </map>\r
+\r
+               <map name="pathNames" table="RESULT_PATH_NAMES_MAP"\r
+                       cascade="all" lazy="false" sort="natural">\r
+                       <key column="PARENT_ID" />\r
+                       <composite-map-key\r
+                               class="org.argeo.slc.core.structure.tree.TreeSPath">\r
+                               <key-property name="asUniqueString" column="PATH" />\r
+                       </composite-map-key>\r
+                       <element column="NAME" type="string" />\r
+               </map>\r
        </class>\r
 </hibernate-mapping>
\ No newline at end of file
index 24e4d823c852f18f8abad05e942c8a019bd6b741..5858c4c0ecd239a0e8072c18cc91ef82d4fd5d48 100644 (file)
@@ -35,7 +35,7 @@ public class TreeTestResultDaoHibernateTest extends AbstractSpringTestCase {
                String pathParentStr = "/root/testParent";\r
                String pathStr = pathParentStr + "/test";\r
                TreeSPath path = TreeSPath.parseToCreatePath(pathStr);\r
-               treeSPathDao.create(path);\r
+               //treeSPathDao.create(path);\r
 \r
                TreeTestResult treeTestResult = new TreeTestResult();\r
                treeTestResult.notifySlcExecution(slcExecution);\r