2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org
.argeo
.slc
.services
.impl
;
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
;
36 * Implementation of complex operations impacting the underlying data.
38 public class TestManagerServiceImpl
implements TestManagerService
{
39 private Log log
= LogFactory
.getLog(getClass());
41 private final TreeTestResultDao treeTestResultDao
;
42 private final TestRunDescriptorDao testRunDescriptorDao
;
43 private final SlcExecutionDao slcExecutionDao
;
44 private final TreeTestResultCollectionDao treeTestResultCollectionDao
;
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
;
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
);
63 // Update tree test result collection
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
74 addResultToCollection(collectionId
, testRunDescriptor
75 .getTestResultUuid());
78 if (log
.isTraceEnabled())
79 log
.trace("ResultUUID="
80 + testRunDescriptor
.getTestResultUuid());
81 addResultToCollection("default", testRunDescriptor
82 .getTestResultUuid());
87 public void addResultToCollection(String collectionId
, String resultUuid
) {
88 // TODO: improve collections
89 TreeTestResultCollection ttrc
= treeTestResultCollectionDao
90 .getTestResultCollection(collectionId
);
92 ttrc
= new TreeTestResultCollection(collectionId
);
93 treeTestResultCollectionDao
.create(ttrc
);
95 treeTestResultCollectionDao
.addResultToCollection(ttrc
, resultUuid
);
98 public void removeResultFromCollection(String collectionId
,
100 TreeTestResultCollection ttrc
= treeTestResultCollectionDao
101 .getTestResultCollection(collectionId
);
103 treeTestResultCollectionDao
.removeResultFromCollection(ttrc
,
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
);
114 public void createTreeTestResult(CreateTreeTestResultRequest msg
) {
115 TreeTestResult treeTestResult
= msg
.getTreeTestResult();
117 if (log
.isTraceEnabled())
118 log
.trace("Creating result #" + treeTestResult
.getUuid());
119 treeTestResultDao
.create(treeTestResult
);
121 registerTestRunDescriptor(msg
.getTestRunDescriptor());
123 // FIXME: temporary hack before better collection management is found
124 if (msg
.getTestRunDescriptor() == null) {
125 addResultToCollection("default", treeTestResult
.getUuid());
129 public void addResultPart(ResultPartRequest msg
) {
130 // registerTestRunDescriptor(msg.getTestRunDescriptor());
132 if (log
.isTraceEnabled())
133 log
.trace("Adding result part to test result #"
134 + msg
.getResultUuid());
136 treeTestResultDao
.addResultPart(msg
.getResultUuid(), msg
.getPath(), msg
137 .getResultPart(), msg
.getRelatedElements());
138 // treeTestResultDao.updateAttributes(msg.getResultUuid(), msg
139 // .getAttributes());
142 public void closeTreeTestResult(CloseTreeTestResultRequest msg
) {
143 if (log
.isTraceEnabled())
144 log
.trace("Closing result #" + msg
.getResultUuid() + " at date "
145 + msg
.getCloseDate());
147 treeTestResultDao
.close(msg
.getResultUuid(), msg
.getCloseDate());
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