1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.internal.macro.chart.source; |
21 |
|
|
22 |
|
import java.util.Map; |
23 |
|
|
24 |
|
import org.jfree.data.general.Dataset; |
25 |
|
import org.xwiki.chart.dataset.DatasetType; |
26 |
|
import org.xwiki.chart.model.ChartModel; |
27 |
|
import org.xwiki.chart.plot.PlotType; |
28 |
|
import org.xwiki.rendering.macro.MacroExecutionException; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
@version |
36 |
|
@since |
37 |
|
|
|
|
| 86.7% |
Uncovered Elements: 8 (60) |
Complexity: 19 |
Complexity Density: 0.58 |
|
38 |
|
public abstract class AbstractDataSource implements DataSource |
39 |
|
{ |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
public static final String DATASET_PARAM = "dataset"; |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
public static final String PLOT_TYPE_PARAM = "type"; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
private DatasetType datasetType; |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
private PlotType plotType; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
private SimpleChartModel chartModel; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
private LocaleConfiguration localeConfiguration = new LocaleConfiguration(); |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
private AxisConfigurator axisConfigurator = new AxisConfigurator(localeConfiguration); |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
@param |
79 |
|
@throws |
80 |
|
|
|
|
| 87.9% |
Uncovered Elements: 4 (33) |
Complexity: 7 |
Complexity Density: 0.33 |
|
81 |
21 |
protected void validateParameters(Map<String, String> parameters) throws MacroExecutionException... |
82 |
|
{ |
83 |
21 |
for (String key : parameters.keySet()) { |
84 |
170 |
if (DATASET_PARAM.equals(key)) { |
85 |
5 |
datasetType = DatasetType.forName(parameters.get(key)); |
86 |
5 |
if (datasetType == null) { |
87 |
0 |
invalidParameterValue(DATASET_PARAM, parameters.get(key)); |
88 |
|
} |
89 |
5 |
continue; |
90 |
|
} |
91 |
165 |
if (PLOT_TYPE_PARAM.equals(key)) { |
92 |
21 |
plotType = PlotType.forName(parameters.get(key)); |
93 |
21 |
if (plotType == null) { |
94 |
0 |
invalidParameterValue(PLOT_TYPE_PARAM, parameters.get(key)); |
95 |
|
} |
96 |
21 |
continue; |
97 |
|
} |
98 |
144 |
if (localeConfiguration.setParameter(key, parameters.get(key))) { |
99 |
7 |
continue; |
100 |
|
} |
101 |
137 |
if (axisConfigurator.setParameter(key, parameters.get(key))) { |
102 |
14 |
continue; |
103 |
|
} |
104 |
123 |
setParameter(key, parameters.get(key)); |
105 |
|
} |
106 |
|
|
107 |
21 |
localeConfiguration.validateParameters(); |
108 |
|
|
109 |
21 |
axisConfigurator.validateParameters(); |
110 |
|
|
111 |
21 |
validatePlotType(); |
112 |
|
|
113 |
21 |
validateDatasetType(); |
114 |
|
|
115 |
21 |
validateParameters(); |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
@param |
124 |
|
@param |
125 |
|
@return |
126 |
|
@throws |
127 |
|
|
128 |
|
protected abstract boolean setParameter(String key, String value) throws MacroExecutionException; |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
@throws |
134 |
|
|
135 |
|
protected abstract void validateParameters() throws MacroExecutionException; |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
@throws |
141 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
142 |
21 |
protected void validateDatasetType() throws MacroExecutionException... |
143 |
|
{ |
144 |
21 |
if (getDatasetType() == null) { |
145 |
16 |
setDatasetType(plotType.getDefaultDatasetType()); |
146 |
|
} |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
@throws |
153 |
|
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
154 |
21 |
protected void validatePlotType() throws MacroExecutionException... |
155 |
|
{ |
156 |
21 |
if (plotType == null) { |
157 |
0 |
throw new MacroExecutionException(String.format("The parameter [%s] is mandatory!", PLOT_TYPE_PARAM)); |
158 |
|
} |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
@throws |
165 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
166 |
21 |
protected void setAxes() throws MacroExecutionException... |
167 |
|
{ |
168 |
21 |
axisConfigurator.setAxes(plotType, chartModel); |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
@return |
173 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
174 |
73 |
public DatasetType getDatasetType()... |
175 |
|
{ |
176 |
73 |
return this.datasetType; |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
|
@param |
181 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
182 |
16 |
public void setDatasetType(DatasetType datasetType)... |
183 |
|
{ |
184 |
16 |
this.datasetType = datasetType; |
185 |
|
} |
186 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
187 |
21 |
@Override... |
188 |
|
public ChartModel getChartModel() |
189 |
|
{ |
190 |
21 |
return chartModel; |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
@param |
197 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
198 |
21 |
protected void setChartModel(SimpleChartModel chartModel)... |
199 |
|
{ |
200 |
21 |
this.chartModel = chartModel; |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
|
@param |
205 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
206 |
21 |
protected void setDataset(Dataset dataset)... |
207 |
|
{ |
208 |
21 |
chartModel.setDataset(dataset); |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
@param |
215 |
|
@param |
216 |
|
@throws |
217 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
218 |
0 |
protected void invalidParameterValue(String parameterName, String value) throws MacroExecutionException... |
219 |
|
{ |
220 |
0 |
throw new MacroExecutionException(String.format("Invalid value for parameter [%s]: [%s]", |
221 |
|
parameterName, value)); |
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
|
@return |
226 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
227 |
21 |
protected LocaleConfiguration getLocaleConfiguration()... |
228 |
|
{ |
229 |
21 |
return localeConfiguration; |
230 |
|
} |
231 |
|
} |