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
.StructureElement
;
13 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
14 import org
.argeo
.slc
.core
.test
.TestResultPart
;
15 import org
.argeo
.slc
.core
.test
.TestStatus
;
16 import org
.argeo
.slc
.core
.test
.tree
.PartSubList
;
17 import org
.argeo
.slc
.core
.test
.tree
.TreeTestResult
;
18 import org
.argeo
.slc
.dao
.test
.tree
.TreeTestResultDao
;
20 public class ResultViewController
extends ParameterizableViewController
{
21 private final TreeTestResultDao testResultDao
;
23 public ResultViewController(TreeTestResultDao testResultDao
) {
24 this.testResultDao
= testResultDao
;
28 protected ModelAndView
handleRequestInternal(HttpServletRequest request
,
29 HttpServletResponse response
) throws Exception
{
31 String uuid
= request
.getParameter("uuid");
32 TreeTestResult result
= testResultDao
.getTestResult(uuid
);
34 SortedMap
<TreeSPath
, String
> toc
= generateToc(result
);
36 SortedMap
<TreeSPath
, String
> describedPaths
= new TreeMap
<TreeSPath
, String
>();
37 for (TreeSPath path
: toc
.keySet()) {
38 describedPaths
.put(path
, describedPath(path
, result
));
41 SortedMap
<TreeSPath
, String
> anchors
= new TreeMap
<TreeSPath
, String
>();
42 for (TreeSPath path
: toc
.keySet()) {
43 anchors
.put(path
, anchor(path
));
46 ModelAndView modelAndView
= new ModelAndView();
48 modelAndView
.addObject("result", result
);
49 modelAndView
.addObject("toc", toc
);
50 modelAndView
.addObject("describedPaths", describedPaths
);
51 modelAndView
.addObject("anchors", anchors
);
52 modelAndView
.setViewName(getViewName());
56 private SortedMap
<TreeSPath
, String
> generateToc(TreeTestResult result
) {
57 SortedMap
<TreeSPath
, String
> toc
= new TreeMap
<TreeSPath
, String
>();
58 for (TreeSPath path
: result
.getResultParts().keySet()) {
59 PartSubList subList
= (PartSubList
) result
.getResultParts().get(
61 boolean isFailed
= false;
62 for (TestResultPart part
: subList
.getParts()) {
63 if (!part
.getStatus().equals(TestStatus
.PASSED
)) {
68 fillToc(toc
, path
, isFailed
);
73 private void fillToc(SortedMap
<TreeSPath
, String
> toc
, TreeSPath path
,
76 toc
.put(path
, "failed");
78 if (!toc
.containsKey(path
)) {
79 toc
.put(path
, "passed");
83 if (path
.getParent() != null) {
84 fillToc(toc
, path
.getParent(), isFailed
);
88 private static String
anchor(TreeSPath path
) {
89 return path
.getAsUniqueString().replace(path
.getSeparator(), '_');
92 private static String
describedPath(TreeSPath path
, TreeTestResult ttr
) {
93 StringBuffer buf
= new StringBuffer("");
94 // TODO :optimize with hierarichy
95 describedPath(path
, buf
, ttr
);
96 return buf
.toString();
99 private static void describedPath(TreeSPath path
, StringBuffer buf
,
100 TreeTestResult ttr
) {
101 if (path
.getParent() != null) {
102 describedPath(path
.getParent(), buf
, ttr
);
104 String description
= path
.getName();
105 StructureElement element
= ttr
.getElements().get(path
);
106 if (element
!= null) {
107 description
= element
.getLabel();
109 buf
.append('/').append(description
);