]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java
Basic reporting
[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.argeo.slc.core.SlcException;
8 import org.argeo.slc.core.structure.StructureAware;
9 import org.argeo.slc.core.structure.StructurePath;
10 import org.argeo.slc.core.structure.StructureRegistry;
11 import org.argeo.slc.core.structure.tree.TreeSPath;
12 import org.argeo.slc.core.test.NumericTRId;
13 import org.argeo.slc.core.test.TestResult;
14 import org.argeo.slc.core.test.TestResultId;
15 import org.argeo.slc.core.test.TestResultListener;
16 import org.argeo.slc.core.test.TestResultPart;
17
18 public class TreeTestResult implements TestResult, StructureAware {
19 /** For ORM */
20 private Long tid;
21
22 private NumericTRId testResultId;
23 private List<TestResultListener> listeners;
24
25 private TreeSPath currentPath;
26
27 private SortedMap<TreeSPath, PartSubList> resultParts = new TreeMap<TreeSPath, PartSubList>();
28
29 public TestResultId getTestResultId() {
30 return testResultId;
31 }
32
33 public NumericTRId getNumericResultId() {
34 return testResultId;
35 }
36
37 public void setNumericResultId(NumericTRId testResultId) {
38 this.testResultId = testResultId;
39 }
40
41 public void setListeners(List<TestResultListener> listeners) {
42 this.listeners = listeners;
43 }
44
45 public void addResultPart(TestResultPart part) {
46 if (currentPath == null) {
47 throw new SlcException("No current path set.");
48 }
49 PartSubList subList = resultParts.get(currentPath);
50 if (subList == null) {
51 subList = new PartSubList();
52 resultParts.put(currentPath, subList);
53 }
54 subList.getParts().add(part);
55
56 // notify listeners
57 synchronized (listeners) {
58 for (TestResultListener listener : listeners) {
59 listener.resultPartAdded(this, part);
60 }
61 }
62 }
63
64 public void notifyCurrentPath(StructureRegistry registry, StructurePath path) {
65 currentPath = (TreeSPath) path;
66 }
67
68 public TreeSPath getCurrentPath() {
69 return currentPath;
70 }
71
72 public SortedMap<TreeSPath, PartSubList> getResultParts() {
73 return resultParts;
74 }
75
76 void setResultParts(SortedMap<TreeSPath, PartSubList> resultParts) {
77 this.resultParts = resultParts;
78 }
79
80 public void close() {
81 synchronized (listeners) {
82 for (TestResultListener listener : listeners) {
83 listener.close();
84 }
85 listeners.clear();
86 }
87 }
88
89 Long getTid() {
90 return tid;
91 }
92
93 void setTid(Long tid) {
94 this.tid = tid;
95 }
96
97 }