1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.maven.exceptions.report;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21
22 import org.apache.commons.lang.ObjectUtils;
23
24 import de.smartics.exceptions.code.NumberCode;
25 import de.smartics.exceptions.core.Code;
26 import de.smartics.exceptions.report.data.ExceptionCodeReportItem;
27 import de.smartics.exceptions.report.data.StoredExceptionCodesReport;
28 import de.smartics.exceptions.report.sort.MixedCodeComparator;
29 import de.smartics.maven.exceptions.AbstractSinkReportGenerator;
30
31
32
33
34
35
36 public class CodeSortedSinkReportGenerator extends AbstractSinkReportGenerator
37 {
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public CodeSortedSinkReportGenerator()
52 {
53 }
54
55
56
57
58
59
60
61
62
63
64
65 @Override
66 protected List<ExceptionCodeReportItem> getItems(
67 final StoredExceptionCodesReport report)
68 {
69 final List<ExceptionCodeReportItem> items =
70 new ArrayList<ExceptionCodeReportItem>(report.getItems());
71 Collections.sort(items, new MixedCodeComparator());
72 return items;
73 }
74
75 @Override
76 protected String getCurrentSelection(final ExceptionCodeReportItem item)
77 {
78 final Code code = item.getCode();
79
80 if (code instanceof NumberCode)
81 {
82 final NumberCode numberCode = (NumberCode) code;
83 final String codeMajorNumber =
84 String.valueOf(numberCode.getMajorNumber());
85 return codeMajorNumber;
86 }
87
88 return code.getComponentId();
89 }
90
91 @Override
92 protected boolean hasSectionChanged(String currentSection,
93 final ExceptionCodeReportItem item)
94 {
95 final Code code = item.getCode();
96
97 boolean headerChanged;
98 if (code instanceof NumberCode)
99 {
100 final NumberCode numberCode = (NumberCode) code;
101 final String codeMajorNumber =
102 String.valueOf(numberCode.getMajorNumber());
103 headerChanged = !ObjectUtils.equals(currentSection, codeMajorNumber);
104 }
105 else
106 {
107 final String componentId = code.getComponentId();
108 headerChanged = !ObjectUtils.equals(currentSection, componentId);
109 }
110
111 return headerChanged;
112 }
113
114 @Override
115 protected String getCodeTitle(final String headLine,
116 final ExceptionCodeReportItem item)
117 {
118 final String title;
119 if (headLine != null)
120 {
121 title = headLine;
122 }
123 else
124 {
125 final String code = item.getCode().getCode();
126 title = code;
127 }
128
129 return title;
130 }
131
132
133
134 }