]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.server/src/main/java/org/argeo/slc/services/test/impl/TestManagerServiceImpl.java
Improve formatting
[gpl/argeo-slc.git] / org.argeo.slc.server / src / main / java / org / argeo / slc / services / test / impl / TestManagerServiceImpl.java
1 package org.argeo.slc.services.test.impl;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5
6 import org.argeo.slc.core.process.SlcExecution;
7 import org.argeo.slc.core.test.TestRunDescriptor;
8 import org.argeo.slc.core.test.tree.TreeTestResult;
9 import org.argeo.slc.core.test.tree.TreeTestResultCollection;
10 import org.argeo.slc.dao.process.SlcExecutionDao;
11 import org.argeo.slc.dao.test.TestRunDescriptorDao;
12 import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao;
13 import org.argeo.slc.dao.test.tree.TreeTestResultDao;
14 import org.argeo.slc.services.test.TestManagerService;
15
16 public class TestManagerServiceImpl implements TestManagerService {
17 private Log log = LogFactory.getLog(getClass());
18
19 private final TreeTestResultDao treeTestResultDao;
20 private final TestRunDescriptorDao testRunDescriptorDao;
21 private final SlcExecutionDao slcExecutionDao;
22 private final TreeTestResultCollectionDao treeTestResultCollectionDao;
23
24 public TestManagerServiceImpl(TreeTestResultDao treeTestResultDao,
25 TestRunDescriptorDao testRunDescriptorDao,
26 SlcExecutionDao slcExecutionDao,
27 TreeTestResultCollectionDao treeTestResultCollectionDao) {
28 this.treeTestResultDao = treeTestResultDao;
29 this.testRunDescriptorDao = testRunDescriptorDao;
30 this.slcExecutionDao = slcExecutionDao;
31 this.treeTestResultCollectionDao = treeTestResultCollectionDao;
32 }
33
34 public void registerTestRunDescriptor(TestRunDescriptor testRunDescriptor) {
35 if (testRunDescriptor != null) {
36 if (log.isDebugEnabled())
37 log.debug("Updating test run descriptor with id "
38 + testRunDescriptor.getTestRunUuid());
39
40 testRunDescriptorDao.saveOrUpdate(testRunDescriptor);
41
42 // Update tree test result collection
43 // TODO: optimize
44 SlcExecution slcExecution = slcExecutionDao
45 .getSlcExecution(testRunDescriptor.getSlcExecutionUuid());
46 if (slcExecution != null) {
47 addResultToCollection(slcExecution.getUser(), testRunDescriptor
48 .getTestResultUuid());
49 }
50 }
51 }
52
53 public void addResultToCollection(String collectionId, String resultUuid) {
54 TreeTestResultCollection ttrc = treeTestResultCollectionDao
55 .getTestResultCollection(collectionId);
56 if (ttrc == null) {
57 ttrc = new TreeTestResultCollection(collectionId);
58 treeTestResultCollectionDao.create(ttrc);
59 }
60 TreeTestResult ttr = treeTestResultDao.getTestResult(resultUuid);
61 ttrc.getResults().add(ttr);
62 treeTestResultCollectionDao.update(ttrc);
63 }
64
65 public void removeResultFromCollection(String collectionId,
66 String resultUuid) {
67 TreeTestResultCollection ttrc = treeTestResultCollectionDao
68 .getTestResultCollection(collectionId);
69 if (ttrc != null) {
70 TreeTestResult ttr = treeTestResultDao.getTestResult(resultUuid);
71 if (ttrc.getResults().remove(ttr)) {
72 treeTestResultCollectionDao.update(ttrc);
73 }
74 }
75 }
76
77 }