]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/result/ResultPdfView.java
Change some url in the ria package to fit the new controller strategy
[gpl/argeo-slc.git] / runtime / org.argeo.slc.server / src / main / java / org / argeo / slc / web / mvc / result / 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.result;
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.argeo.slc.core.structure.tree.TreeSPath;
26 import org.argeo.slc.core.test.SlcTestUtils;
27 import org.argeo.slc.core.test.tree.PartSubList;
28 import org.argeo.slc.core.test.tree.TreeTestResult;
29 import org.argeo.slc.test.TestResultPart;
30 import org.argeo.slc.test.TestStatus;
31 import org.springframework.web.servlet.view.document.AbstractPdfView;
32
33 import com.lowagie.text.Cell;
34 import com.lowagie.text.Document;
35 import com.lowagie.text.Paragraph;
36 import com.lowagie.text.Table;
37 import com.lowagie.text.pdf.PdfWriter;
38
39 public class ResultPdfView extends AbstractPdfView {
40 public final static String MODELKEY_RESULT = "result";
41
42 @Override
43 @SuppressWarnings(value = { "unchecked" })
44 protected void buildPdfDocument(Map model, Document document,
45 PdfWriter writer, HttpServletRequest request,
46 HttpServletResponse response) throws Exception {
47 TreeTestResult ttr = (TreeTestResult) model.get(MODELKEY_RESULT);
48
49 document.addTitle("Result " + ttr.getUuid());
50 document.add(new Paragraph("Result " + ttr.getUuid()));
51
52 for (TreeSPath path : ttr.getResultParts().keySet()) {
53 PartSubList lst = ttr.getResultParts().get(path);
54 document.add(new Paragraph("Path " + path));
55 Table table = new Table(2, lst.getParts().size());
56 for (TestResultPart part : lst.getParts()) {
57 Integer status = part.getStatus();
58 Cell statusCell = new Cell(SlcTestUtils.statusToString(status));
59 final Color color;
60 if (status.equals(TestStatus.PASSED))
61 color = Color.GREEN;
62 else if (status.equals(TestStatus.FAILED))
63 color = Color.RED;
64 else
65 color = Color.MAGENTA;
66
67 statusCell.setBackgroundColor(color);
68 table.addCell(statusCell);
69 table.addCell(part.getMessage());
70 }
71 document.add(table);
72 }
73
74 }
75
76 }