]> git.argeo.org Git - gpl/argeo-slc.git/blob - impl/TestManagerServiceImpl.java
Prepare next development cycle
[gpl/argeo-slc.git] / 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
45 if (testRunDescriptor.getSlcExecutionUuid() != null) {
46 SlcExecution slcExecution = slcExecutionDao
47 .getSlcExecution(testRunDescriptor
48 .getSlcExecutionUuid());
49 if (slcExecution != null) {
50 addResultToCollection(slcExecution.getUser(),
51 testRunDescriptor.getTestResultUuid());
52 }
53 }
54 }
55 }
56
57 public void addResultToCollection(String collectionId, String resultUuid) {
58 TreeTestResultCollection ttrc = treeTestResultCollectionDao
59 .getTestResultCollection(collectionId);
60 if (ttrc == null) {
61 ttrc = new TreeTestResultCollection(collectionId);
62 treeTestResultCollectionDao.create(ttrc);
63 }
64 TreeTestResult ttr = treeTestResultDao.getTestResult(resultUuid);
65 ttrc.getResults().add(ttr);
66 treeTestResultCollectionDao.update(ttrc);
67 }
68
69 public void removeResultFromCollection(String collectionId,
70 String resultUuid) {
71 TreeTestResultCollection ttrc = treeTestResultCollectionDao
72 .getTestResultCollection(collectionId);
73 if (ttrc != null) {
74 TreeTestResult ttr = treeTestResultDao.getTestResult(resultUuid);
75 if (ttrc.getResults().remove(ttr)) {
76 treeTestResultCollectionDao.update(ttrc);
77 }
78 }
79 }
80
81 }