--- /dev/null
+package org.argeo.slc.services.test.impl;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.argeo.slc.core.process.SlcExecution;\r
+import org.argeo.slc.core.test.TestRunDescriptor;\r
+import org.argeo.slc.core.test.tree.TreeTestResultCollection;\r
+import org.argeo.slc.dao.process.SlcExecutionDao;\r
+import org.argeo.slc.dao.test.TestRunDescriptorDao;\r
+import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao;\r
+import org.argeo.slc.dao.test.tree.TreeTestResultDao;\r
+import org.argeo.slc.services.test.TestManagerService;\r
+\r
+public class TestManagerServiceImpl implements TestManagerService {\r
+ private Log log = LogFactory.getLog(getClass());\r
+\r
+ private final TreeTestResultDao treeTestResultDao;\r
+ private final TestRunDescriptorDao testRunDescriptorDao;\r
+ private final SlcExecutionDao slcExecutionDao;\r
+ private final TreeTestResultCollectionDao treeTestResultCollectionDao;\r
+\r
+ public TestManagerServiceImpl(TreeTestResultDao treeTestResultDao,\r
+ TestRunDescriptorDao testRunDescriptorDao,\r
+ SlcExecutionDao slcExecutionDao,\r
+ TreeTestResultCollectionDao treeTestResultCollectionDao) {\r
+ this.treeTestResultDao = treeTestResultDao;\r
+ this.testRunDescriptorDao = testRunDescriptorDao;\r
+ this.slcExecutionDao = slcExecutionDao;\r
+ this.treeTestResultCollectionDao = treeTestResultCollectionDao;\r
+ }\r
+\r
+ public void registerTestRunDescriptor(TestRunDescriptor testRunDescriptor) {\r
+ if (testRunDescriptor != null) {\r
+ testRunDescriptorDao.saveOrUpdate(testRunDescriptor);\r
+\r
+ // Update tree test result collection\r
+ // TODO: optimize\r
+\r
+ if (testRunDescriptor.getSlcExecutionUuid() != null) {\r
+ SlcExecution slcExecution = slcExecutionDao\r
+ .getSlcExecution(testRunDescriptor\r
+ .getSlcExecutionUuid());\r
+ if (slcExecution != null) {\r
+ String collectionId = slcExecution.getUser() != null ? slcExecution\r
+ .getUser()\r
+ : "default";\r
+ addResultToCollection(collectionId, testRunDescriptor\r
+ .getTestResultUuid());\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ public void addResultToCollection(String collectionId, String resultUuid) {\r
+ TreeTestResultCollection ttrc = treeTestResultCollectionDao\r
+ .getTestResultCollection(collectionId);\r
+ if (ttrc == null) {\r
+ ttrc = new TreeTestResultCollection(collectionId);\r
+ treeTestResultCollectionDao.create(ttrc);\r
+ }\r
+ treeTestResultCollectionDao.addResultToCollection(ttrc, resultUuid);\r
+ }\r
+\r
+ public void removeResultFromCollection(String collectionId,\r
+ String resultUuid) {\r
+ TreeTestResultCollection ttrc = treeTestResultCollectionDao\r
+ .getTestResultCollection(collectionId);\r
+ if (ttrc != null) {\r
+ treeTestResultCollectionDao.removeResultFromCollection(ttrc,\r
+ resultUuid);\r
+ }\r
+ }\r
+\r
+}\r