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 private String defaultCollectionId
= "default";
48 public TestManagerServiceImpl(TreeTestResultDao treeTestResultDao
,
49 TestRunDescriptorDao testRunDescriptorDao
,
50 SlcExecutionDao slcExecutionDao
,
51 TreeTestResultCollectionDao treeTestResultCollectionDao
) {
52 this.treeTestResultDao
= treeTestResultDao
;
53 this.testRunDescriptorDao
= testRunDescriptorDao
;
54 this.slcExecutionDao
= slcExecutionDao
;
55 this.treeTestResultCollectionDao
= treeTestResultCollectionDao
;
58 public void registerTestRunDescriptor(TestRunDescriptor testRunDescriptor
) {
59 if (testRunDescriptor
!= null) {
60 if (log
.isTraceEnabled())
61 log
.trace("Registering test run descriptor #"
62 + testRunDescriptor
.getTestRunUuid());
63 testRunDescriptorDao
.saveOrUpdate(testRunDescriptor
);
65 // Update tree test result collection
68 if (testRunDescriptor
.getSlcExecutionUuid() != null) {
69 SlcExecution slcExecution
= slcExecutionDao
70 .getSlcExecution(testRunDescriptor
71 .getSlcExecutionUuid());
72 if (slcExecution
!= null) {
73 // Use Host as collection ID if host is available
74 String collectionId
= slcExecution
.getHost() != null ? slcExecution
76 : defaultCollectionId
;
77 addResultToCollection(collectionId
, testRunDescriptor
78 .getTestResultUuid());
81 if (log
.isTraceEnabled())
82 log
.trace("ResultUUID="
83 + testRunDescriptor
.getTestResultUuid());
84 addResultToCollection(defaultCollectionId
, testRunDescriptor
85 .getTestResultUuid());
90 public void addResultToCollection(String collectionId
, String resultUuid
) {
91 // TODO: improve collections
92 TreeTestResultCollection ttrc
= treeTestResultCollectionDao
93 .getTestResultCollection(collectionId
);
95 ttrc
= new TreeTestResultCollection(collectionId
);
96 treeTestResultCollectionDao
.create(ttrc
);
98 treeTestResultCollectionDao
.addResultToCollection(ttrc
, resultUuid
);
101 public void removeResultFromCollection(String collectionId
,
103 TreeTestResultCollection ttrc
= treeTestResultCollectionDao
104 .getTestResultCollection(collectionId
);
106 treeTestResultCollectionDao
.removeResultFromCollection(ttrc
,
110 // Delete collection if empty
111 // see https://www.argeo.org/bugzilla/show_bug.cgi?id=74
112 if (ttrc
.getResults().size() == 0) {
113 treeTestResultCollectionDao
.delete(ttrc
);
117 public void createTreeTestResult(CreateTreeTestResultRequest msg
) {
118 TreeTestResult treeTestResult
= msg
.getTreeTestResult();
120 if (log
.isTraceEnabled())
121 log
.trace("Creating result #" + treeTestResult
.getUuid());
122 treeTestResultDao
.create(treeTestResult
);
124 registerTestRunDescriptor(msg
.getTestRunDescriptor());
126 // FIXME: temporary hack before better collection management is found
127 if (msg
.getTestRunDescriptor() == null) {
128 addResultToCollection("default", treeTestResult
.getUuid());
132 public void addResultPart(ResultPartRequest msg
) {
133 // registerTestRunDescriptor(msg.getTestRunDescriptor());
135 if (log
.isTraceEnabled())
136 log
.trace("Adding result part to test result #"
137 + msg
.getResultUuid());
139 treeTestResultDao
.addResultPart(msg
.getResultUuid(), msg
.getPath(), msg
140 .getResultPart(), msg
.getRelatedElements());
141 // treeTestResultDao.updateAttributes(msg.getResultUuid(), msg
142 // .getAttributes());
145 public void closeTreeTestResult(CloseTreeTestResultRequest msg
) {
146 if (log
.isTraceEnabled())
147 log
.trace("Closing result #" + msg
.getResultUuid() + " at date "
148 + msg
.getCloseDate());
150 treeTestResultDao
.close(msg
.getResultUuid(), msg
.getCloseDate());
153 public void addAttachment(AddTreeTestResultAttachmentRequest msg
) {
154 if (log
.isTraceEnabled())
155 log
.trace("Adding attachment " + msg
.getAttachment()
156 + " to result #" + msg
.getResultUuid());
157 treeTestResultDao
.addAttachment(msg
.getResultUuid(), msg
162 public void setDefaultCollectionId(String defaultCollectionId
) {
163 this.defaultCollectionId
= defaultCollectionId
;