X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Ftest%2Ftree%2FTreeTestResult.java;h=3124b055fcb3339c3aff75c241faa58cd6dfcd91;hb=ed93fb9db5f9008a78d9ab892806ae398ed65b85;hp=3134e1aaad2cec82cd7a21587edd694a1d479ef1;hpb=7756b44bff90cc8cb20e16e426c39f82ba89705e;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java b/org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java index 3134e1aaa..3124b055f 100644 --- a/org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java +++ b/org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java @@ -1,76 +1,151 @@ package org.argeo.slc.core.test.tree; +import java.util.Date; import java.util.List; import java.util.SortedMap; import java.util.TreeMap; import java.util.Vector; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.argeo.slc.core.SlcException; import org.argeo.slc.core.structure.StructureAware; import org.argeo.slc.core.structure.StructurePath; import org.argeo.slc.core.structure.StructureRegistry; import org.argeo.slc.core.structure.tree.TreeSPath; +import org.argeo.slc.core.test.NumericTRId; import org.argeo.slc.core.test.TestResult; import org.argeo.slc.core.test.TestResultId; import org.argeo.slc.core.test.TestResultListener; import org.argeo.slc.core.test.TestResultPart; +/** + * Complex implementation of a test result compatible with a tree based + * structure. + */ public class TreeTestResult implements TestResult, StructureAware { - private TestResultId testResultId; - private List listeners; + private Log log = LogFactory.getLog(TreeTestResult.class); + /** For ORM */ + private Long tid; + + private NumericTRId testResultId; + private List listeners = new Vector(); private TreeSPath currentPath; - private SortedMap> resultParts = new TreeMap>(); + private Date closeDate; + + private boolean isClosed = false; + + private SortedMap resultParts = new TreeMap(); + + private StructureRegistry registry; public TestResultId getTestResultId() { return testResultId; } - public void setTestResultId(TestResultId testResultId) { + /** + * Use of a NumericTRId is required by Hibernate. It may + * change in the future. + */ + public NumericTRId getNumericResultId() { + return testResultId; + } + + /** Sets the test result id as a numeric test result id. */ + public void setNumericResultId(NumericTRId testResultId) { this.testResultId = testResultId; } + /** Sets the list of listeners. */ public void setListeners(List listeners) { this.listeners = listeners; } - + public void addResultPart(TestResultPart part) { - if(currentPath==null){ + if (currentPath == null) { throw new SlcException("No current path set."); } - List list = resultParts.get(currentPath); - if(list == null){ - list = new Vector(); - resultParts.put(currentPath, list); + PartSubList subList = resultParts.get(currentPath); + if (subList == null) { + subList = new PartSubList(); + resultParts.put(currentPath, subList); } - list.add(part); - - // notify listeners - for(TestResultListener listener: listeners){ - listener.resultPartAdded(this, part); - } - } + subList.getParts().add(part); - public List listResultParts() { - List all = new Vector(); - for(TreeSPath path:resultParts.keySet()){ - all.addAll(resultParts.get(path)); + // notify listeners + synchronized (listeners) { + for (TestResultListener listener : listeners) { + listener.resultPartAdded(this, part); + } } - return all; } public void notifyCurrentPath(StructureRegistry registry, StructurePath path) { currentPath = (TreeSPath) path; + this.registry = registry; } + /** Gets the current path. */ public TreeSPath getCurrentPath() { return currentPath; } - public SortedMap> getResultParts() { + /** Gets all the results structured as a map of PartSubLists. */ + public SortedMap getResultParts() { return resultParts; } - + /** Used by ORM systems. */ + void setResultParts(SortedMap resultParts) { + this.resultParts = resultParts; + } + + public void close() { + if (isClosed) { + throw new SlcException("Test Result #" + getTestResultId() + + " alredy closed."); + } + closeDate = new Date(); + + synchronized (listeners) { + for (TestResultListener listener : listeners) { + listener.close(this); + } + listeners.clear(); + } + isClosed = true; + + log.info("Test Result #" + getTestResultId() + " closed."); + } + + Long getTid() { + return tid; + } + + void setTid(Long tid) { + this.tid = tid; + } + + /** Gets the related registry (can be null). */ + public StructureRegistry getRegistry() { + return registry; + } + + /** Sets the related registry. */ + public void setRegistry(StructureRegistry registry) { + this.registry = registry; + } + + public Date getCloseDate() { + return closeDate; + } + + /** Sets the close date (for ORM) */ + public void setCloseDate(Date closeDate) { + this.closeDate = closeDate; + } + }