]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/result/ResultViewController.java
Improve auto-detection of Spring beans.
[gpl/argeo-slc.git] / org.argeo.slc.server / src / main / java / org / argeo / slc / web / mvc / result / ResultViewController.java
1 package org.argeo.slc.web.mvc.result;
2
3 import java.util.SortedMap;
4 import java.util.TreeMap;
5
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import org.springframework.web.servlet.ModelAndView;
10 import org.springframework.web.servlet.mvc.ParameterizableViewController;
11
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;
19
20 public class ResultViewController extends ParameterizableViewController {
21 private final TreeTestResultDao testResultDao;
22
23 public ResultViewController(TreeTestResultDao testResultDao) {
24 this.testResultDao = testResultDao;
25 }
26
27 @Override
28 protected ModelAndView handleRequestInternal(HttpServletRequest request,
29 HttpServletResponse response) throws Exception {
30
31 String uuid = request.getParameter("uuid");
32 TreeTestResult result = testResultDao.getTestResult(uuid);
33
34 SortedMap<TreeSPath, String> toc = generateToc(result);
35
36 SortedMap<TreeSPath, String> describedPaths = new TreeMap<TreeSPath, String>();
37 for (TreeSPath path : toc.keySet()) {
38 describedPaths.put(path, describedPath(path, result));
39 }
40
41 SortedMap<TreeSPath, String> anchors = new TreeMap<TreeSPath, String>();
42 for (TreeSPath path : toc.keySet()) {
43 anchors.put(path, anchor(path));
44 }
45
46 ModelAndView modelAndView = new ModelAndView();
47
48 modelAndView.addObject("result", result);
49 modelAndView.addObject("toc", toc);
50 modelAndView.addObject("describedPaths", describedPaths);
51 modelAndView.addObject("anchors", anchors);
52 modelAndView.setViewName(getViewName());
53 return modelAndView;
54 }
55
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(
60 path);
61 boolean isFailed = false;
62 for (TestResultPart part : subList.getParts()) {
63 if (!part.getStatus().equals(TestStatus.PASSED)) {
64 isFailed = true;
65 break;
66 }
67 }
68 fillToc(toc, path, isFailed);
69 }
70 return toc;
71 }
72
73 private void fillToc(SortedMap<TreeSPath, String> toc, TreeSPath path,
74 boolean isFailed) {
75 if (isFailed) {
76 toc.put(path, "failed");
77 } else {
78 if (!toc.containsKey(path)) {
79 toc.put(path, "passed");
80 }
81 }
82
83 if (path.getParent() != null) {
84 fillToc(toc, path.getParent(), isFailed);
85 }
86 }
87
88 private static String anchor(TreeSPath path) {
89 return path.getAsUniqueString().replace(path.getSeparator(), '_');
90 }
91
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();
97 }
98
99 private static void describedPath(TreeSPath path, StringBuffer buf,
100 TreeTestResult ttr) {
101 if (path.getParent() != null) {
102 describedPath(path.getParent(), buf, ttr);
103 }
104 String description = path.getName();
105 StructureElement element = ttr.getElements().get(path);
106 if (element != null) {
107 description = element.getLabel();
108 }
109 buf.append('/').append(description);
110 }
111
112 }