]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/impl/TestManagerServiceImpl.java
Improve logging
[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 private String defaultCollectionId = "default";
47
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;
56 }
57
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);
64
65 // Update tree test result collection
66 // TODO: optimize
67
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
75 .getHost()
76 : defaultCollectionId;
77 addResultToCollection(collectionId, testRunDescriptor
78 .getTestResultUuid());
79 }
80 } else {
81 if (log.isTraceEnabled())
82 log.trace("ResultUUID="
83 + testRunDescriptor.getTestResultUuid());
84 addResultToCollection(defaultCollectionId, testRunDescriptor
85 .getTestResultUuid());
86 }
87 }
88 }
89
90 public void addResultToCollection(String collectionId, String resultUuid) {
91 // TODO: improve collections
92 TreeTestResultCollection ttrc = treeTestResultCollectionDao
93 .getTestResultCollection(collectionId);
94 if (ttrc == null) {
95 ttrc = new TreeTestResultCollection(collectionId);
96 treeTestResultCollectionDao.create(ttrc);
97 }
98 treeTestResultCollectionDao.addResultToCollection(ttrc, resultUuid);
99 }
100
101 public void removeResultFromCollection(String collectionId,
102 String resultUuid) {
103 TreeTestResultCollection ttrc = treeTestResultCollectionDao
104 .getTestResultCollection(collectionId);
105 if (ttrc != null) {
106 treeTestResultCollectionDao.removeResultFromCollection(ttrc,
107 resultUuid);
108 }
109
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);
114 }
115 }
116
117 public void createTreeTestResult(CreateTreeTestResultRequest msg) {
118 TreeTestResult treeTestResult = msg.getTreeTestResult();
119
120 if (log.isTraceEnabled())
121 log.trace("Creating result #" + treeTestResult.getUuid());
122 treeTestResultDao.create(treeTestResult);
123
124 registerTestRunDescriptor(msg.getTestRunDescriptor());
125
126 // FIXME: temporary hack before better collection management is found
127 if (msg.getTestRunDescriptor() == null) {
128 addResultToCollection("default", treeTestResult.getUuid());
129 }
130 }
131
132 public void addResultPart(ResultPartRequest msg) {
133 // registerTestRunDescriptor(msg.getTestRunDescriptor());
134
135 if (log.isTraceEnabled())
136 log.trace("Adding result part to test result #"
137 + msg.getResultUuid());
138
139 treeTestResultDao.addResultPart(msg.getResultUuid(), msg.getPath(), msg
140 .getResultPart(), msg.getRelatedElements());
141 // treeTestResultDao.updateAttributes(msg.getResultUuid(), msg
142 // .getAttributes());
143 }
144
145 public void closeTreeTestResult(CloseTreeTestResultRequest msg) {
146 if (log.isTraceEnabled())
147 log.trace("Closing result #" + msg.getResultUuid() + " at date "
148 + msg.getCloseDate());
149
150 treeTestResultDao.close(msg.getResultUuid(), msg.getCloseDate());
151 }
152
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
158 .getAttachment());
159
160 }
161
162 public void setDefaultCollectionId(String defaultCollectionId) {
163 this.defaultCollectionId = defaultCollectionId;
164 }
165
166 }