]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java
Introduce nested tasks
[gpl/argeo-slc.git] / org.argeo.slc / src / main / java / org / argeo / slc / core / test / tree / TreeTestResult.java
1 package org.argeo.slc.core.test.tree;
2
3 import java.util.List;
4 import java.util.SortedMap;
5 import java.util.TreeMap;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9
10 import org.argeo.slc.core.SlcException;
11 import org.argeo.slc.core.structure.StructureAware;
12 import org.argeo.slc.core.structure.StructurePath;
13 import org.argeo.slc.core.structure.StructureRegistry;
14 import org.argeo.slc.core.structure.tree.TreeSPath;
15 import org.argeo.slc.core.test.NumericTRId;
16 import org.argeo.slc.core.test.TestResult;
17 import org.argeo.slc.core.test.TestResultId;
18 import org.argeo.slc.core.test.TestResultListener;
19 import org.argeo.slc.core.test.TestResultPart;
20
21 public class TreeTestResult implements TestResult, StructureAware {
22 private Log log = LogFactory.getLog(TreeTestResult.class);
23 /** For ORM */
24 private Long tid;
25
26 private NumericTRId testResultId;
27 private List<TestResultListener> listeners;
28
29 private TreeSPath currentPath;
30
31 private boolean isClosed = false;
32
33 private SortedMap<TreeSPath, PartSubList> resultParts = new TreeMap<TreeSPath, PartSubList>();
34
35 public TestResultId getTestResultId() {
36 return testResultId;
37 }
38
39 public NumericTRId getNumericResultId() {
40 return testResultId;
41 }
42
43 public void setNumericResultId(NumericTRId testResultId) {
44 this.testResultId = testResultId;
45 }
46
47 public void setListeners(List<TestResultListener> listeners) {
48 this.listeners = listeners;
49 }
50
51 public void addResultPart(TestResultPart part) {
52 if (currentPath == null) {
53 throw new SlcException("No current path set.");
54 }
55 PartSubList subList = resultParts.get(currentPath);
56 if (subList == null) {
57 subList = new PartSubList();
58 resultParts.put(currentPath, subList);
59 }
60 subList.getParts().add(part);
61
62 // notify listeners
63 synchronized (listeners) {
64 for (TestResultListener listener : listeners) {
65 listener.resultPartAdded(this, part);
66 }
67 }
68 }
69
70 public void notifyCurrentPath(StructureRegistry registry, StructurePath path) {
71 currentPath = (TreeSPath) path;
72 }
73
74 public TreeSPath getCurrentPath() {
75 return currentPath;
76 }
77
78 public SortedMap<TreeSPath, PartSubList> getResultParts() {
79 return resultParts;
80 }
81
82 void setResultParts(SortedMap<TreeSPath, PartSubList> resultParts) {
83 this.resultParts = resultParts;
84 }
85
86 public void close() {
87 if(isClosed){
88 throw new SlcException("Test Result #"+getTestResultId()+" alredy closed.");
89 }
90
91 synchronized (listeners) {
92 for (TestResultListener listener : listeners) {
93 listener.close();
94 }
95 listeners.clear();
96 }
97 isClosed = true;
98 log.info("Test Result #"+getTestResultId()+" closed.");
99 }
100
101 Long getTid() {
102 return tid;
103 }
104
105 void setTid(Long tid) {
106 this.tid = tid;
107 }
108
109 }