]> 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
Use persistent tree, do not call empty on each view pane any more, this is done by...
[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.TreeTestResult;
6 import org.argeo.slc.core.test.tree.TreeTestResultCollection;
7 import org.argeo.slc.dao.process.SlcExecutionDao;
8 import org.argeo.slc.dao.test.TestRunDescriptorDao;
9 import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao;
10 import org.argeo.slc.dao.test.tree.TreeTestResultDao;
11 import org.argeo.slc.msg.test.tree.AddTreeTestResultAttachmentRequest;
12 import org.argeo.slc.msg.test.tree.CloseTreeTestResultRequest;
13 import org.argeo.slc.msg.test.tree.CreateTreeTestResultRequest;
14 import org.argeo.slc.msg.test.tree.ResultPartRequest;
15 import org.argeo.slc.process.SlcExecution;
16 import org.argeo.slc.services.test.TestManagerService;
17 import org.argeo.slc.test.TestRunDescriptor;
18
19 /**
20 * Implementation of complex operations impacting the underlying data.
21 */
22 public class TestManagerServiceImpl implements TestManagerService {
23 private Log log = LogFactory.getLog(getClass());
24
25 private final TreeTestResultDao treeTestResultDao;
26 private final TestRunDescriptorDao testRunDescriptorDao;
27 private final SlcExecutionDao slcExecutionDao;
28 private final TreeTestResultCollectionDao treeTestResultCollectionDao;
29
30 public TestManagerServiceImpl(TreeTestResultDao treeTestResultDao,
31 TestRunDescriptorDao testRunDescriptorDao,
32 SlcExecutionDao slcExecutionDao,
33 TreeTestResultCollectionDao treeTestResultCollectionDao) {
34 this.treeTestResultDao = treeTestResultDao;
35 this.testRunDescriptorDao = testRunDescriptorDao;
36 this.slcExecutionDao = slcExecutionDao;
37 this.treeTestResultCollectionDao = treeTestResultCollectionDao;
38 }
39
40 public void registerTestRunDescriptor(TestRunDescriptor testRunDescriptor) {
41 if (testRunDescriptor != null) {
42 if (log.isTraceEnabled())
43 log.trace("Registering test run descriptor #"
44 + testRunDescriptor.getTestRunUuid());
45 testRunDescriptorDao.saveOrUpdate(testRunDescriptor);
46
47 // Update tree test result collection
48 // TODO: optimize
49
50 if (testRunDescriptor.getSlcExecutionUuid() != null) {
51 SlcExecution slcExecution = slcExecutionDao
52 .getSlcExecution(testRunDescriptor
53 .getSlcExecutionUuid());
54 if (slcExecution != null) {
55 String collectionId = slcExecution.getUser() != null ? slcExecution
56 .getUser()
57 : "default";
58 addResultToCollection(collectionId, testRunDescriptor
59 .getTestResultUuid());
60 }
61 } else {
62 if (log.isTraceEnabled())
63 log.trace("ResultUUID="
64 + testRunDescriptor.getTestResultUuid());
65 addResultToCollection("default", testRunDescriptor
66 .getTestResultUuid());
67 }
68 }
69 }
70
71 public void addResultToCollection(String collectionId, String resultUuid) {
72 // TODO: improve collections
73 TreeTestResultCollection ttrc = treeTestResultCollectionDao
74 .getTestResultCollection(collectionId);
75 if (ttrc == null) {
76 ttrc = new TreeTestResultCollection(collectionId);
77 treeTestResultCollectionDao.create(ttrc);
78 }
79 treeTestResultCollectionDao.addResultToCollection(ttrc, resultUuid);
80 }
81
82 public void removeResultFromCollection(String collectionId,
83 String resultUuid) {
84 TreeTestResultCollection ttrc = treeTestResultCollectionDao
85 .getTestResultCollection(collectionId);
86 if (ttrc != null) {
87 treeTestResultCollectionDao.removeResultFromCollection(ttrc,
88 resultUuid);
89 }
90
91 // Delete collection if empty
92 // see https://www.argeo.org/bugzilla/show_bug.cgi?id=74
93 if (ttrc.getResults().size() == 0) {
94 treeTestResultCollectionDao.delete(ttrc);
95 }
96 }
97
98 public void createTreeTestResult(CreateTreeTestResultRequest msg) {
99 TreeTestResult treeTestResult = msg.getTreeTestResult();
100
101 if (log.isTraceEnabled())
102 log.trace("Creating result #" + treeTestResult.getUuid());
103 treeTestResultDao.create(treeTestResult);
104
105 registerTestRunDescriptor(msg.getTestRunDescriptor());
106
107 // FIXME: temporary hack before better collection management is found
108 if (msg.getTestRunDescriptor() == null) {
109 addResultToCollection("default", treeTestResult.getUuid());
110 }
111 }
112
113 public void addResultPart(ResultPartRequest msg) {
114 // registerTestRunDescriptor(msg.getTestRunDescriptor());
115
116 if (log.isTraceEnabled())
117 log.trace("Adding result part to test result #"
118 + msg.getResultUuid());
119
120 treeTestResultDao.addResultPart(msg.getResultUuid(), msg.getPath(), msg
121 .getResultPart(), msg.getRelatedElements());
122 // treeTestResultDao.updateAttributes(msg.getResultUuid(), msg
123 // .getAttributes());
124 }
125
126 public void closeTreeTestResult(CloseTreeTestResultRequest msg) {
127 if (log.isTraceEnabled())
128 log.trace("Closing result #" + msg.getResultUuid() + " at date "
129 + msg.getCloseDate());
130
131 treeTestResultDao.close(msg.getResultUuid(), msg.getCloseDate());
132 }
133
134 public void addAttachment(AddTreeTestResultAttachmentRequest msg) {
135 if (log.isTraceEnabled())
136 log.trace("Adding attachment " + msg.getAttachment()
137 + " to result #" + msg.getResultUuid());
138 treeTestResultDao.addAttachment(msg.getResultUuid(), msg
139 .getAttachment());
140
141 }
142
143 }