1 package org
.argeo
.slc
.web
.mvc
.result
;
3 import java
.util
.SortedMap
;
4 import java
.util
.TreeMap
;
6 import javax
.servlet
.http
.HttpServletRequest
;
7 import javax
.servlet
.http
.HttpServletResponse
;
9 import org
.springframework
.web
.servlet
.ModelAndView
;
10 import org
.springframework
.web
.servlet
.mvc
.ParameterizableViewController
;
12 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
13 import org
.argeo
.slc
.core
.test
.tree
.PartSubList
;
14 import org
.argeo
.slc
.core
.test
.tree
.TreeTestResult
;
15 import org
.argeo
.slc
.dao
.test
.tree
.TreeTestResultDao
;
16 import org
.argeo
.slc
.structure
.StructureElement
;
17 import org
.argeo
.slc
.test
.TestResultPart
;
18 import org
.argeo
.slc
.test
.TestStatus
;
20 public class ResultViewController
extends ParameterizableViewController
{
21 public final static String MODELKEY_RESULT
= "result";
23 private final TreeTestResultDao testResultDao
;
25 public ResultViewController(TreeTestResultDao testResultDao
) {
26 this.testResultDao
= testResultDao
;
30 protected ModelAndView
handleRequestInternal(HttpServletRequest request
,
31 HttpServletResponse response
) throws Exception
{
33 String uuid
= request
.getParameter("uuid");
34 TreeTestResult result
= testResultDao
.getTestResult(uuid
);
36 SortedMap
<TreeSPath
, String
> toc
= generateToc(result
);
38 SortedMap
<TreeSPath
, String
> describedPaths
= new TreeMap
<TreeSPath
, String
>();
39 for (TreeSPath path
: toc
.keySet()) {
40 describedPaths
.put(path
, describedPath(path
, result
));
43 SortedMap
<TreeSPath
, String
> anchors
= new TreeMap
<TreeSPath
, String
>();
44 for (TreeSPath path
: toc
.keySet()) {
45 anchors
.put(path
, anchor(path
));
48 ModelAndView modelAndView
= new ModelAndView();
50 modelAndView
.addObject(MODELKEY_RESULT
, result
);
51 modelAndView
.addObject("toc", toc
);
52 modelAndView
.addObject("describedPaths", describedPaths
);
53 modelAndView
.addObject("anchors", anchors
);
54 modelAndView
.setViewName(getViewName());
58 private SortedMap
<TreeSPath
, String
> generateToc(TreeTestResult result
) {
59 SortedMap
<TreeSPath
, String
> toc
= new TreeMap
<TreeSPath
, String
>();
60 for (TreeSPath path
: result
.getResultParts().keySet()) {
61 PartSubList subList
= (PartSubList
) result
.getResultParts().get(
63 boolean isFailed
= false;
64 for (TestResultPart part
: subList
.getParts()) {
65 if (!part
.getStatus().equals(TestStatus
.PASSED
)) {
70 fillToc(toc
, path
, isFailed
);
75 private void fillToc(SortedMap
<TreeSPath
, String
> toc
, TreeSPath path
,
78 toc
.put(path
, "failed");
80 if (!toc
.containsKey(path
)) {
81 toc
.put(path
, "passed");
85 if (path
.getParent() != null) {
86 fillToc(toc
, path
.getParent(), isFailed
);
90 private static String
anchor(TreeSPath path
) {
91 return path
.getAsUniqueString().replace(path
.getSeparator(), '_');
94 private static String
describedPath(TreeSPath path
, TreeTestResult ttr
) {
95 StringBuffer buf
= new StringBuffer("");
96 // TODO :optimize with hierarchy
97 describedPath(path
, buf
, ttr
);
98 return buf
.toString();
101 private static void describedPath(TreeSPath path
, StringBuffer buf
,
102 TreeTestResult ttr
) {
103 if (path
.getParent() != null) {
104 describedPath(path
.getParent(), buf
, ttr
);
106 String description
= path
.getName();
107 StructureElement element
= ttr
.getElements().get(path
);
108 if (element
!= null) {
109 description
= element
.getLabel();
111 buf
.append('/').append(description
);