]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/impl/TestManagerServiceImpl.java
remove a warning
[gpl/argeo-slc.git] / runtime / org.argeo.slc.server / src / main / java / org / argeo / slc / services / impl / TestManagerServiceImpl.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.services.impl;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.argeo.slc.core.test.tree.TreeTestResult;
22 import org.argeo.slc.core.test.tree.TreeTestResultCollection;
23 import org.argeo.slc.dao.process.SlcExecutionDao;
24 import org.argeo.slc.dao.test.TestRunDescriptorDao;
25 import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao;
26 import org.argeo.slc.dao.test.tree.TreeTestResultDao;
27 import org.argeo.slc.msg.test.tree.AddTreeTestResultAttachmentRequest;
28 import org.argeo.slc.msg.test.tree.CloseTreeTestResultRequest;
29 import org.argeo.slc.msg.test.tree.CreateTreeTestResultRequest;
30 import org.argeo.slc.msg.test.tree.ResultPartRequest;
31 import org.argeo.slc.process.SlcExecution;
32 import org.argeo.slc.services.TestManagerService;
33 import org.argeo.slc.test.TestRunDescriptor;
34
35 /**
36 * Implementation of complex operations impacting the underlying data.
37 */
38 public class TestManagerServiceImpl implements TestManagerService {
39 private Log log = LogFactory.getLog(getClass());
40
41 private final TreeTestResultDao treeTestResultDao;
42 private final TestRunDescriptorDao testRunDescriptorDao;
43 private final SlcExecutionDao slcExecutionDao;
44 private final TreeTestResultCollectionDao treeTestResultCollectionDao;
45
46 public TestManagerServiceImpl(TreeTestResultDao treeTestResultDao,
47 TestRunDescriptorDao testRunDescriptorDao,
48 SlcExecutionDao slcExecutionDao,
49 TreeTestResultCollectionDao treeTestResultCollectionDao) {
50 this.treeTestResultDao = treeTestResultDao;
51 this.testRunDescriptorDao = testRunDescriptorDao;
52 this.slcExecutionDao = slcExecutionDao;
53 this.treeTestResultCollectionDao = treeTestResultCollectionDao;
54 }
55
56 public void registerTestRunDescriptor(TestRunDescriptor testRunDescriptor) {
57 if (testRunDescriptor != null) {
58 if (log.isTraceEnabled())
59 log.trace("Registering test run descriptor #"
60 + testRunDescriptor.getTestRunUuid());
61 testRunDescriptorDao.saveOrUpdate(testRunDescriptor);
62
63 // Update tree test result collection
64 // TODO: optimize
65
66 if (testRunDescriptor.getSlcExecutionUuid() != null) {
67 SlcExecution slcExecution = slcExecutionDao
68 .getSlcExecution(testRunDescriptor
69 .getSlcExecutionUuid());
70 if (slcExecution != null) {
71 String collectionId = slcExecution.getUser() != null ? slcExecution
72 .getUser()
73 : "default";
74 addResultToCollection(collectionId, testRunDescriptor
75 .getTestResultUuid());
76 }
77 } else {
78 if (log.isTraceEnabled())
79 log.trace("ResultUUID="
80 + testRunDescriptor.getTestResultUuid());
81 addResultToCollection("default", testRunDescriptor
82 .getTestResultUuid());
83 }
84 }
85 }
86
87 public void addResultToCollection(String collectionId, String resultUuid) {
88 // TODO: improve collections
89 TreeTestResultCollection ttrc = treeTestResultCollectionDao
90 .getTestResultCollection(collectionId);
91 if (ttrc == null) {
92 ttrc = new TreeTestResultCollection(collectionId);
93 treeTestResultCollectionDao.create(ttrc);
94 }
95 treeTestResultCollectionDao.addResultToCollection(ttrc, resultUuid);
96 }
97
98 public void removeResultFromCollection(String collectionId,
99 String resultUuid) {
100 TreeTestResultCollection ttrc = treeTestResultCollectionDao
101 .getTestResultCollection(collectionId);
102 if (ttrc != null) {
103 treeTestResultCollectionDao.removeResultFromCollection(ttrc,
104 resultUuid);
105 }
106
107 // Delete collection if empty
108 // see https://www.argeo.org/bugzilla/show_bug.cgi?id=74
109 if (ttrc.getResults().size() == 0) {
110 treeTestResultCollectionDao.delete(ttrc);
111 }
112 }
113
114 public void createTreeTestResult(CreateTreeTestResultRequest msg) {
115 TreeTestResult treeTestResult = msg.getTreeTestResult();
116
117 if (log.isTraceEnabled())
118 log.trace("Creating result #" + treeTestResult.getUuid());
119 treeTestResultDao.create(treeTestResult);
120
121 registerTestRunDescriptor(msg.getTestRunDescriptor());
122
123 // FIXME: temporary hack before better collection management is found
124 if (msg.getTestRunDescriptor() == null) {
125 addResultToCollection("default", treeTestResult.getUuid());
126 }
127 }
128
129 public void addResultPart(ResultPartRequest msg) {
130 // registerTestRunDescriptor(msg.getTestRunDescriptor());
131
132 if (log.isTraceEnabled())
133 log.trace("Adding result part to test result #"
134 + msg.getResultUuid());
135
136 treeTestResultDao.addResultPart(msg.getResultUuid(), msg.getPath(), msg
137 .getResultPart(), msg.getRelatedElements());
138 // treeTestResultDao.updateAttributes(msg.getResultUuid(), msg
139 // .getAttributes());
140 }
141
142 public void closeTreeTestResult(CloseTreeTestResultRequest msg) {
143 if (log.isTraceEnabled())
144 log.trace("Closing result #" + msg.getResultUuid() + " at date "
145 + msg.getCloseDate());
146
147 treeTestResultDao.close(msg.getResultUuid(), msg.getCloseDate());
148 }
149
150 public void addAttachment(AddTreeTestResultAttachmentRequest msg) {
151 if (log.isTraceEnabled())
152 log.trace("Adding attachment " + msg.getAttachment()
153 + " to result #" + msg.getResultUuid());
154 treeTestResultDao.addAttachment(msg.getResultUuid(), msg
155 .getAttachment());
156
157 }
158
159 }