]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/ResultPdfView.java
finish cleaning of controllers :
[gpl/argeo-slc.git] / runtime / org.argeo.slc.server / src / main / java / org / argeo / slc / web / mvc / ResultPdfView.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.web.mvc;
18
19 import java.awt.Color;
20 import java.util.Map;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.argeo.slc.core.structure.tree.TreeSPath;
28 import org.argeo.slc.core.test.SlcTestUtils;
29 import org.argeo.slc.core.test.tree.PartSubList;
30 import org.argeo.slc.core.test.tree.TreeTestResult;
31 import org.argeo.slc.test.TestResultPart;
32 import org.argeo.slc.test.TestStatus;
33 import org.springframework.web.servlet.view.document.AbstractPdfView;
34
35 import com.lowagie.text.Cell;
36 import com.lowagie.text.Document;
37 import com.lowagie.text.Paragraph;
38 import com.lowagie.text.Table;
39 import com.lowagie.text.pdf.PdfWriter;
40
41 public class ResultPdfView extends AbstractPdfView {
42 private static final Log log = LogFactory.getLog(ResultPdfView.class);
43
44 public final static String MODELKEY_RESULT = "result";
45
46 @Override
47 @SuppressWarnings(value = { "unchecked" })
48 protected void buildPdfDocument(Map model, Document document,
49 PdfWriter writer, HttpServletRequest request,
50 HttpServletResponse response) throws Exception {
51 TreeTestResult ttr = (TreeTestResult) model.get(MODELKEY_RESULT);
52
53 document.addTitle("Result " + ttr.getUuid());
54 document.add(new Paragraph("Result " + ttr.getUuid()));
55
56 for (TreeSPath path : ttr.getResultParts().keySet()) {
57 PartSubList lst = ttr.getResultParts().get(path);
58 document.add(new Paragraph("Path " + path));
59 Table table = new Table(2, lst.getParts().size());
60 for (TestResultPart part : lst.getParts()) {
61 Integer status = part.getStatus();
62 Cell statusCell = new Cell(SlcTestUtils.statusToString(status));
63 final Color color;
64 if (status.equals(TestStatus.PASSED))
65 color = Color.GREEN;
66 else if (status.equals(TestStatus.FAILED))
67 color = Color.RED;
68 else
69 color = Color.MAGENTA;
70
71 statusCell.setBackgroundColor(color);
72 table.addCell(statusCell);
73 table.addCell(part.getMessage());
74 }
75 document.add(table);
76 }
77
78 }
79 }