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 import org.apache.commons.lang.StringUtils;
24
25 import de.smartics.exceptions.code.NumberCode;
26 import de.smartics.exceptions.core.Code;
27 import de.smartics.exceptions.report.data.ExceptionCodeReportItem;
28 import de.smartics.exceptions.report.data.StoredExceptionCodesReport;
29 import de.smartics.exceptions.report.sort.MixedComponentCodeComparator;
30 import de.smartics.maven.exceptions.AbstractSinkReportGenerator;
31
32
33
34
35
36 public class ComponentCodeSortedSinkReportGenerator extends
37 AbstractSinkReportGenerator
38 {
39
40
41
42
43
44
45
46
47
48
49
50
51
52 public ComponentCodeSortedSinkReportGenerator()
53 {
54 }
55
56
57
58
59
60
61
62
63
64
65
66 @Override
67 protected List<ExceptionCodeReportItem> getItems(
68 final StoredExceptionCodesReport report)
69 {
70 final List<ExceptionCodeReportItem> items =
71 new ArrayList<ExceptionCodeReportItem>(report.getItems());
72 Collections.sort(items, new MixedComponentCodeComparator());
73 return items;
74 }
75
76 @Override
77 protected String getCurrentSelection(final ExceptionCodeReportItem item)
78 {
79 final Code code = item.getCode();
80
81 if (code instanceof NumberCode)
82 {
83 final NumberCode numberCode = (NumberCode) code;
84 final String codeMajorNumber =
85 String.valueOf(numberCode.getMajorNumber());
86 return codeMajorNumber;
87 }
88
89 return code.getComponentId();
90 }
91
92 @Override
93 protected boolean hasSectionChanged(String currentSection,
94 final ExceptionCodeReportItem item)
95 {
96 final Code code = item.getCode();
97
98 boolean headerChanged;
99 if (code instanceof NumberCode)
100 {
101 final NumberCode numberCode = (NumberCode) code;
102 final String codeMajorNumber =
103 String.valueOf(numberCode.getMajorNumber());
104 headerChanged = !ObjectUtils.equals(currentSection, codeMajorNumber);
105 }
106 else
107 {
108 final String componentId = code.getComponentId();
109 headerChanged = !ObjectUtils.equals(currentSection, componentId);
110 }
111
112 return headerChanged;
113 }
114
115 @Override
116 protected String getCodeTitle(final String headLine,
117 final ExceptionCodeReportItem item)
118 {
119 final String title;
120 if (headLine != null)
121 {
122 title = headLine;
123 }
124 else
125 {
126 final String componentId = item.getCode().getComponentId();
127 if (StringUtils.isNotBlank(componentId))
128 {
129 title = componentId;
130 }
131 else
132 {
133 final String code = item.getCode().getCode();
134 title = code;
135 }
136 }
137
138 return title;
139 }
140
141
142
143 }