]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/test/impl/TestManagerServiceImpl.java
b9a3a7045b6a14e0dad8c8950b141443d365876a
[gpl/argeo-slc.git] / runtime / org.argeo.slc.server / src / main / java / org / argeo / slc / services / test / impl / TestManagerServiceImpl.java
1 package org.argeo.slc.services.test.impl;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.argeo.slc.core.process.SlcExecution;
6 import org.argeo.slc.core.test.TestRunDescriptor;
7 import org.argeo.slc.core.test.tree.TreeTestResultCollection;
8 import org.argeo.slc.dao.process.SlcExecutionDao;
9 import org.argeo.slc.dao.test.TestRunDescriptorDao;
10 import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao;
11 import org.argeo.slc.dao.test.tree.TreeTestResultDao;
12 import org.argeo.slc.services.test.TestManagerService;
13
14 public class TestManagerServiceImpl implements TestManagerService {
15 private Log log = LogFactory.getLog(getClass());
16
17 private final TreeTestResultDao treeTestResultDao;
18 private final TestRunDescriptorDao testRunDescriptorDao;
19 private final SlcExecutionDao slcExecutionDao;
20 private final TreeTestResultCollectionDao treeTestResultCollectionDao;
21
22 public TestManagerServiceImpl(TreeTestResultDao treeTestResultDao,
23 TestRunDescriptorDao testRunDescriptorDao,
24 SlcExecutionDao slcExecutionDao,
25 TreeTestResultCollectionDao treeTestResultCollectionDao) {
26 this.treeTestResultDao = treeTestResultDao;
27 this.testRunDescriptorDao = testRunDescriptorDao;
28 this.slcExecutionDao = slcExecutionDao;
29 this.treeTestResultCollectionDao = treeTestResultCollectionDao;
30 }
31
32 public void registerTestRunDescriptor(TestRunDescriptor testRunDescriptor) {
33 if (testRunDescriptor != null) {
34 testRunDescriptorDao.saveOrUpdate(testRunDescriptor);
35
36 // Update tree test result collection
37 // TODO: optimize
38
39 if (testRunDescriptor.getSlcExecutionUuid() != null) {
40 SlcExecution slcExecution = slcExecutionDao
41 .getSlcExecution(testRunDescriptor
42 .getSlcExecutionUuid());
43 if (slcExecution != null) {
44 String collectionId = slcExecution.getUser() != null ? slcExecution
45 .getUser()
46 : "default";
47 addResultToCollection(collectionId, testRunDescriptor
48 .getTestResultUuid());
49 }
50 }
51 }
52 }
53
54 public void addResultToCollection(String collectionId, String resultUuid) {
55 TreeTestResultCollection ttrc = treeTestResultCollectionDao
56 .getTestResultCollection(collectionId);
57 if (ttrc == null) {
58 ttrc = new TreeTestResultCollection(collectionId);
59 treeTestResultCollectionDao.create(ttrc);
60 }
61 treeTestResultCollectionDao.addResultToCollection(ttrc, resultUuid);
62 }
63
64 public void removeResultFromCollection(String collectionId,
65 String resultUuid) {
66 TreeTestResultCollection ttrc = treeTestResultCollectionDao
67 .getTestResultCollection(collectionId);
68 if (ttrc != null) {
69 treeTestResultCollectionDao.removeResultFromCollection(ttrc,
70 resultUuid);
71 }
72 }
73
74 }