X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=inline;f=runtime%2Forg.argeo.slc.server%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fservices%2Ftest%2Fimpl%2FTestManagerServiceImpl.java;fp=runtime%2Forg.argeo.slc.server%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fservices%2Ftest%2Fimpl%2FTestManagerServiceImpl.java;h=b9a3a7045b6a14e0dad8c8950b141443d365876a;hb=805f03392d3e1a561257614db979f0c2c82c1328;hp=0000000000000000000000000000000000000000;hpb=44e8a4c4f5da330764fcc19dea09337e9d114cd4;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/test/impl/TestManagerServiceImpl.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/test/impl/TestManagerServiceImpl.java new file mode 100644 index 000000000..b9a3a7045 --- /dev/null +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/test/impl/TestManagerServiceImpl.java @@ -0,0 +1,74 @@ +package org.argeo.slc.services.test.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.slc.core.process.SlcExecution; +import org.argeo.slc.core.test.TestRunDescriptor; +import org.argeo.slc.core.test.tree.TreeTestResultCollection; +import org.argeo.slc.dao.process.SlcExecutionDao; +import org.argeo.slc.dao.test.TestRunDescriptorDao; +import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao; +import org.argeo.slc.dao.test.tree.TreeTestResultDao; +import org.argeo.slc.services.test.TestManagerService; + +public class TestManagerServiceImpl implements TestManagerService { + private Log log = LogFactory.getLog(getClass()); + + private final TreeTestResultDao treeTestResultDao; + private final TestRunDescriptorDao testRunDescriptorDao; + private final SlcExecutionDao slcExecutionDao; + private final TreeTestResultCollectionDao treeTestResultCollectionDao; + + public TestManagerServiceImpl(TreeTestResultDao treeTestResultDao, + TestRunDescriptorDao testRunDescriptorDao, + SlcExecutionDao slcExecutionDao, + TreeTestResultCollectionDao treeTestResultCollectionDao) { + this.treeTestResultDao = treeTestResultDao; + this.testRunDescriptorDao = testRunDescriptorDao; + this.slcExecutionDao = slcExecutionDao; + this.treeTestResultCollectionDao = treeTestResultCollectionDao; + } + + public void registerTestRunDescriptor(TestRunDescriptor testRunDescriptor) { + if (testRunDescriptor != null) { + testRunDescriptorDao.saveOrUpdate(testRunDescriptor); + + // Update tree test result collection + // TODO: optimize + + if (testRunDescriptor.getSlcExecutionUuid() != null) { + SlcExecution slcExecution = slcExecutionDao + .getSlcExecution(testRunDescriptor + .getSlcExecutionUuid()); + if (slcExecution != null) { + String collectionId = slcExecution.getUser() != null ? slcExecution + .getUser() + : "default"; + addResultToCollection(collectionId, testRunDescriptor + .getTestResultUuid()); + } + } + } + } + + public void addResultToCollection(String collectionId, String resultUuid) { + TreeTestResultCollection ttrc = treeTestResultCollectionDao + .getTestResultCollection(collectionId); + if (ttrc == null) { + ttrc = new TreeTestResultCollection(collectionId); + treeTestResultCollectionDao.create(ttrc); + } + treeTestResultCollectionDao.addResultToCollection(ttrc, resultUuid); + } + + public void removeResultFromCollection(String collectionId, + String resultUuid) { + TreeTestResultCollection ttrc = treeTestResultCollectionDao + .getTestResultCollection(collectionId); + if (ttrc != null) { + treeTestResultCollectionDao.removeResultFromCollection(ttrc, + resultUuid); + } + } + +}