]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/TreeTestResultPersister.java
Manage with Maven
[gpl/argeo-slc.git] / org.argeo.slc / src / main / java / org / argeo / slc / core / test / tree / TreeTestResultPersister.java
index 0c32a1a4cfd82caf5a743400e3844c4a66237e24..ca92b49084e9f045fcc5ed824e2d1b0987a2b7d5 100644 (file)
@@ -4,7 +4,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;\r
 \r
 import org.argeo.slc.core.structure.SimpleSElement;\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.structure.tree.TreeSRegistry;\r
@@ -32,16 +31,9 @@ public class TreeTestResultPersister extends AsynchronousTreeTestResultListener
 \r
                        TreeSPath path = treeSPathDao.getOrCreate(partStruct.path);\r
 \r
+                       StructureRegistry localRegistry = partStruct.result.getRegistry();\r
                        TreeSRegistry registry = getOrCreateTreeSRegistry(path);\r
-                       if (registry.getElement(path) == null) {\r
-                               StructureRegistry localRegistry = partStruct.result\r
-                                               .getRegistry();\r
-                               if (localRegistry != null) {\r
-                                       registry.register(path, localRegistry.getElement(path));\r
-                               } else {\r
-                                       registry.register(path, new SimpleSElement(path.getName()));\r
-                               }\r
-                       }\r
+                       syncPath(registry, localRegistry, path);\r
 \r
                        if (persistedResult == null) {\r
                                persistedResult = new TreeTestResult();\r
@@ -76,6 +68,20 @@ public class TreeTestResultPersister extends AsynchronousTreeTestResultListener
                }\r
        }\r
 \r
+       @Override\r
+       protected void postClose(TreeTestResult testResult) {\r
+               TreeTestResult persistedResult = (TreeTestResult) testResultDao\r
+                               .getTestResult(testResult.getTestResultId());\r
+\r
+               if (persistedResult != null) {\r
+                       persistedResult.setCloseDate(testResult.getCloseDate());\r
+                       testResultDao.update(persistedResult);\r
+               }\r
+               if (log.isDebugEnabled())\r
+                       log.debug("Closed result persister for result "\r
+                                       + testResult.getNumericResultId());\r
+       }\r
+\r
        private TreeSRegistry getOrCreateTreeSRegistry(TreeSPath path) {\r
                TreeSRegistry registry = treeSRegistryDao.getTreeSRegistry(path);\r
                if (registry == null) {\r
@@ -89,17 +95,36 @@ public class TreeTestResultPersister extends AsynchronousTreeTestResultListener
                }\r
        }\r
 \r
-       /** Sets the dao to use in order to persist the results. */\r
+       /** Sets the DAO to use in order to persist the results. */\r
        public void setTestResultDao(TestResultDao testResultDao) {\r
                this.testResultDao = testResultDao;\r
        }\r
 \r
+       /** Sets the tree structure path DAO. */\r
        public void setTreeSPathDao(TreeSPathDao treeSPathDao) {\r
                this.treeSPathDao = treeSPathDao;\r
        }\r
 \r
+       /** Sets the tree structure registry DAO. */\r
        public void setTreeSRegistryDao(TreeSRegistryDao treeSRegistryDao) {\r
                this.treeSRegistryDao = treeSRegistryDao;\r
        }\r
 \r
+       private void syncPath(TreeSRegistry registry,\r
+                       StructureRegistry 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
+               }\r
+\r
+       }\r
 }\r