]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/impl/test/TestManagerServiceImpl.java
First consistent version with JMS
[gpl/argeo-slc.git] / runtime / org.argeo.slc.server / src / main / java / org / argeo / slc / services / impl / test / TestManagerServiceImpl.java
1 package org.argeo.slc.services.impl.test;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.argeo.slc.core.test.tree.TreeTestResultCollection;
6 import org.argeo.slc.dao.process.SlcExecutionDao;
7 import org.argeo.slc.dao.test.TestRunDescriptorDao;
8 import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao;
9 import org.argeo.slc.dao.test.tree.TreeTestResultDao;
10 import org.argeo.slc.process.SlcExecution;
11 import org.argeo.slc.services.test.TestManagerService;
12 import org.argeo.slc.test.TestRunDescriptor;
13
14 /** Implementation of complex operations impacting the underlying data. */
15 public class TestManagerServiceImpl implements TestManagerService {
16 private Log log = LogFactory.getLog(getClass());
17
18 private final TreeTestResultDao treeTestResultDao;
19 private final TestRunDescriptorDao testRunDescriptorDao;
20 private final SlcExecutionDao slcExecutionDao;
21 private final TreeTestResultCollectionDao treeTestResultCollectionDao;
22
23 public TestManagerServiceImpl(TreeTestResultDao treeTestResultDao,
24 TestRunDescriptorDao testRunDescriptorDao,
25 SlcExecutionDao slcExecutionDao,
26 TreeTestResultCollectionDao treeTestResultCollectionDao) {
27 this.treeTestResultDao = treeTestResultDao;
28 this.testRunDescriptorDao = testRunDescriptorDao;
29 this.slcExecutionDao = slcExecutionDao;
30 this.treeTestResultCollectionDao = treeTestResultCollectionDao;
31 }
32
33 public void registerTestRunDescriptor(TestRunDescriptor testRunDescriptor) {
34 if (testRunDescriptor != null) {
35 testRunDescriptorDao.saveOrUpdate(testRunDescriptor);
36
37 // Update tree test result collection
38 // TODO: optimize
39
40 if (testRunDescriptor.getSlcExecutionUuid() != null) {
41 SlcExecution slcExecution = slcExecutionDao
42 .getSlcExecution(testRunDescriptor
43 .getSlcExecutionUuid());
44 if (slcExecution != null) {
45 String collectionId = slcExecution.getUser() != null ? slcExecution
46 .getUser()
47 : "default";
48 addResultToCollection(collectionId, testRunDescriptor
49 .getTestResultUuid());
50 }
51 }
52 }
53 }
54
55 public void addResultToCollection(String collectionId, String resultUuid) {
56 TreeTestResultCollection ttrc = treeTestResultCollectionDao
57 .getTestResultCollection(collectionId);
58 if (ttrc == null) {
59 ttrc = new TreeTestResultCollection(collectionId);
60 treeTestResultCollectionDao.create(ttrc);
61 }
62 treeTestResultCollectionDao.addResultToCollection(ttrc, resultUuid);
63 }
64
65 public void removeResultFromCollection(String collectionId,
66 String resultUuid) {
67 TreeTestResultCollection ttrc = treeTestResultCollectionDao
68 .getTestResultCollection(collectionId);
69 if (ttrc != null) {
70 treeTestResultCollectionDao.removeResultFromCollection(ttrc,
71 resultUuid);
72 }
73
74 // Delete collection if empty
75 // see https://www.argeo.org/bugzilla/show_bug.cgi?id=74
76 if (ttrc.getResults().size() == 0) {
77 treeTestResultCollectionDao.delete(ttrc);
78 }
79 }
80
81 }