1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common.assembly.data; |
17 |
|
|
18 |
|
import java.util.Date; |
19 |
|
import java.util.List; |
20 |
|
|
21 |
|
import org.kuali.student.common.validator.DateParser; |
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
@author |
26 |
|
|
|
|
| 15.6% |
Uncovered Elements: 282 (334) |
Complexity: 112 |
Complexity Density: 0.61 |
|
27 |
|
public class MetadataInterrogator { |
28 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
29 |
|
public enum ConstraintIds { |
30 |
|
MULTI_LINE_TEXT("multi.line.text"), RICH_TEXT("rich.text"); |
31 |
|
private final String id; |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
33 |
0
|
private ConstraintIds(final String id) {... |
34 |
0
|
this.id = id; |
35 |
|
} |
36 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
37 |
0
|
public String getId() {... |
38 |
0
|
return this.id; |
39 |
|
} |
40 |
|
} |
41 |
|
|
42 |
|
private Metadata meta; |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
44 |
25
|
public MetadataInterrogator(Metadata meta) {... |
45 |
25
|
this.meta = meta; |
46 |
|
} |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
51 |
0
|
public boolean hasConstraint(String id) {... |
52 |
0
|
return hasConstraint(meta, id); |
53 |
|
} |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
@return |
60 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
0
|
public boolean isRequired() {... |
62 |
0
|
return isRequired(meta); |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
@return |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
0
|
public Integer getLargestMinOccurs() {... |
71 |
0
|
return getLargestMinOccurs(meta); |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
@return |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0
|
public boolean isRepeating() {... |
80 |
0
|
return isRepeating(meta); |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
@return |
87 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
0
|
public Integer getSmallestMaxOccurs() {... |
89 |
0
|
return getSmallestMaxOccurs(meta); |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
@return |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
91
|
public Integer getLargestMinLength() {... |
98 |
91
|
return getLargestMinLength(meta); |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
69
|
public Integer getSmallestMaxLength() {... |
102 |
69
|
return getSmallestMaxLength(meta); |
103 |
|
} |
104 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
0
|
public boolean isMultilined() {... |
106 |
0
|
return isMultilined(meta); |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
113 |
0
|
public static boolean hasConstraint(Metadata meta, ConstraintIds id) {... |
114 |
0
|
return hasConstraint(meta, id.getId()); |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
119 |
0
|
public static boolean hasConstraint(Metadata meta, String id) {... |
120 |
0
|
boolean result = false; |
121 |
0
|
if (meta != null && meta.getConstraints() != null) { |
122 |
0
|
result = containsConstraint(meta.getConstraints(), id); |
123 |
|
} |
124 |
0
|
return result; |
125 |
|
} |
126 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 5 |
Complexity Density: 0.71 |
|
127 |
0
|
private static boolean containsConstraint(List<ConstraintMetadata> constraints,... |
128 |
|
String id) { |
129 |
0
|
boolean result = false; |
130 |
0
|
if (constraints != null) { |
131 |
0
|
for (ConstraintMetadata con : constraints) { |
132 |
0
|
if ((con.getId() != null && con.getId().equals(id)) |
133 |
|
|| containsConstraint(con.getChildConstraints(), id)) { |
134 |
0
|
result = true; |
135 |
0
|
break; |
136 |
|
} |
137 |
|
} |
138 |
|
} |
139 |
0
|
return result; |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
@return |
146 |
|
|
|
|
| 42.9% |
Uncovered Elements: 8 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
147 |
8
|
public static boolean isRequired(Metadata meta) {... |
148 |
8
|
if (meta == null) { |
149 |
0
|
return false; |
150 |
|
} |
151 |
8
|
Integer largestMinOccurs = getLargestMinOccurs(meta); |
152 |
|
|
153 |
8
|
if (largestMinOccurs == null) { |
154 |
8
|
return false; |
155 |
|
} |
156 |
0
|
if (largestMinOccurs >= 1) { |
157 |
0
|
return true; |
158 |
|
} |
159 |
0
|
return false; |
160 |
|
} |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
@param |
166 |
|
@return |
167 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
168 |
0
|
public static boolean isRequiredForNextState(Metadata meta){... |
169 |
0
|
boolean required = false; |
170 |
|
|
171 |
0
|
if(meta == null){ |
172 |
0
|
return false; |
173 |
|
} |
174 |
|
|
175 |
|
|
176 |
0
|
if (meta.getConstraints() != null && meta.getConstraints().size() == 1){ |
177 |
0
|
ConstraintMetadata constraint = meta.getConstraints().get(0); |
178 |
0
|
required = constraint.isRequiredForNextState(); |
179 |
|
} |
180 |
|
|
181 |
0
|
return required; |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
@param |
188 |
|
@return |
189 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
190 |
0
|
public static String getNextState(Metadata meta){... |
191 |
0
|
String state = null; |
192 |
|
|
193 |
0
|
if(meta == null){ |
194 |
0
|
return state; |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
0
|
if (meta.getConstraints() != null && meta.getConstraints().size() == 1){ |
199 |
0
|
ConstraintMetadata constraint = meta.getConstraints().get(0); |
200 |
0
|
state = constraint.getNextState(); |
201 |
|
} |
202 |
|
|
203 |
0
|
return state; |
204 |
|
} |
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
@return |
210 |
|
|
|
|
| 27.8% |
Uncovered Elements: 13 (18) |
Complexity: 5 |
Complexity Density: 0.5 |
|
211 |
11
|
public static Integer getLargestMinOccurs(Metadata meta) {... |
212 |
11
|
if (meta == null) { |
213 |
0
|
return null; |
214 |
|
} |
215 |
11
|
Integer largestMinOccurs = null; |
216 |
|
|
217 |
|
|
218 |
11
|
for (ConstraintMetadata cons : meta.getConstraints()) { |
219 |
0
|
if (cons.getMinOccurs() != null) { |
220 |
0
|
if (largestMinOccurs == null) { |
221 |
0
|
largestMinOccurs = cons.getMinOccurs(); |
222 |
0
|
} else if (cons.getMinOccurs() > largestMinOccurs) { |
223 |
0
|
largestMinOccurs = cons.getMinOccurs(); |
224 |
|
} |
225 |
|
} |
226 |
|
} |
227 |
11
|
return largestMinOccurs; |
228 |
|
} |
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
@return |
234 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 5 |
Complexity Density: 0.83 |
|
235 |
0
|
public static boolean isRepeating(Metadata meta) {... |
236 |
0
|
if (meta == null) { |
237 |
0
|
return false; |
238 |
|
} |
239 |
0
|
Integer smallestMaxOccurs = getSmallestMaxOccurs(meta); |
240 |
0
|
if (hasRepeatingConstraint(meta) || |
241 |
|
(smallestMaxOccurs != null && smallestMaxOccurs > 1)) { |
242 |
0
|
return true; |
243 |
|
} |
244 |
0
|
return false; |
245 |
|
} |
246 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
247 |
0
|
private static boolean hasRepeatingConstraint(Metadata meta) {... |
248 |
0
|
boolean isRepeating = false; |
249 |
|
|
250 |
0
|
for (ConstraintMetadata cons : meta.getConstraints()) { |
251 |
0
|
if ("repeating".equals(cons.getId())){ |
252 |
0
|
isRepeating = true; |
253 |
|
} |
254 |
|
} |
255 |
0
|
return isRepeating; |
256 |
|
} |
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
@return |
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
|
|
|
| 29.6% |
Uncovered Elements: 19 (27) |
Complexity: 8 |
Complexity Density: 0.53 |
|
267 |
3
|
public static Integer getSmallestMaxOccurs(Metadata meta) {... |
268 |
3
|
if (meta == null) { |
269 |
0
|
return null; |
270 |
|
} |
271 |
3
|
Integer smallestMaxOccurs = null; |
272 |
3
|
boolean isRepeating = false; |
273 |
|
|
274 |
3
|
for (ConstraintMetadata cons : meta.getConstraints()) { |
275 |
0
|
if ("repeating".equals(cons.getId())){ |
276 |
0
|
isRepeating = true; |
277 |
|
} |
278 |
0
|
if (cons.getMaxOccurs() != null) { |
279 |
0
|
if (smallestMaxOccurs == null) { |
280 |
0
|
smallestMaxOccurs = cons.getMaxOccurs(); |
281 |
0
|
} else if (cons.getMaxOccurs() < smallestMaxOccurs) { |
282 |
0
|
smallestMaxOccurs = cons.getMaxOccurs(); |
283 |
|
} |
284 |
|
} |
285 |
|
} |
286 |
|
|
287 |
3
|
if (isRepeating && smallestMaxOccurs == null){ |
288 |
0
|
smallestMaxOccurs = -1; |
289 |
|
} |
290 |
|
|
291 |
3
|
return smallestMaxOccurs; |
292 |
|
} |
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
|
@return |
298 |
|
|
|
|
| 61.1% |
Uncovered Elements: 7 (18) |
Complexity: 5 |
Complexity Density: 0.5 |
|
299 |
96
|
public static Integer getLargestMinLength(Metadata meta) {... |
300 |
96
|
if (meta == null) { |
301 |
0
|
return null; |
302 |
|
} |
303 |
96
|
Integer largestMinLength = null; |
304 |
|
|
305 |
|
|
306 |
96
|
for (ConstraintMetadata cons : meta.getConstraints()) { |
307 |
96
|
if (cons.getMinLength() != null) { |
308 |
93
|
if (largestMinLength == null) { |
309 |
93
|
largestMinLength = cons.getMinLength(); |
310 |
0
|
} else if (cons.getMinLength() > largestMinLength) { |
311 |
0
|
largestMinLength = cons.getMinLength(); |
312 |
|
} |
313 |
|
} |
314 |
|
} |
315 |
96
|
return largestMinLength; |
316 |
|
} |
317 |
|
|
|
|
| 61.1% |
Uncovered Elements: 7 (18) |
Complexity: 5 |
Complexity Density: 0.5 |
|
318 |
74
|
public static Integer getSmallestMaxLength(Metadata meta) {... |
319 |
74
|
if (meta == null) { |
320 |
0
|
return null; |
321 |
|
} |
322 |
74
|
Integer smallestMaxLength = null; |
323 |
|
|
324 |
|
|
325 |
74
|
for (ConstraintMetadata cons : meta.getConstraints()) { |
326 |
74
|
if (cons.getMaxLength() != null) { |
327 |
71
|
if (smallestMaxLength == null) { |
328 |
71
|
smallestMaxLength = cons.getMaxLength(); |
329 |
0
|
} else if (cons.getMaxLength() < smallestMaxLength) { |
330 |
0
|
smallestMaxLength = cons.getMaxLength(); |
331 |
|
} |
332 |
|
} |
333 |
|
} |
334 |
74
|
return smallestMaxLength; |
335 |
|
} |
336 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.56 |
|
337 |
0
|
public static boolean isMultilined(Metadata meta) {... |
338 |
0
|
if (meta == null) { |
339 |
0
|
return false; |
340 |
|
} |
341 |
|
|
342 |
0
|
boolean result = (hasConstraint(meta, "rich.text") || hasConstraint(meta, "multi.line.text")) |
343 |
|
&& !(hasConstraint(meta, "single.line.text") || hasConstraint(meta, "code") || hasConstraint(meta, "no.linefeeds")); |
344 |
|
|
345 |
|
|
346 |
0
|
if (!result) { |
347 |
0
|
Integer maxLength = getSmallestMaxLength(meta); |
348 |
0
|
if (maxLength != null) { |
349 |
0
|
if (maxLength > 150) { |
350 |
0
|
result = true; |
351 |
|
} |
352 |
|
} |
353 |
|
} |
354 |
0
|
return result; |
355 |
|
} |
356 |
|
|
357 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
358 |
0
|
public static Long getLargestMinValue(Metadata meta) {... |
359 |
0
|
if (meta == null) { |
360 |
0
|
return null; |
361 |
|
} |
362 |
0
|
Long result = null; |
363 |
0
|
for (ConstraintMetadata cons : meta.getConstraints()) { |
364 |
0
|
Long min = tryParseLong(cons.getMinValue()); |
365 |
0
|
if (min != null) { |
366 |
0
|
if (result == null || min > result) { |
367 |
0
|
result = min; |
368 |
|
} |
369 |
|
} |
370 |
|
} |
371 |
0
|
return result; |
372 |
|
} |
373 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
374 |
0
|
public static Long getSmallestMaxValue(Metadata meta) {... |
375 |
0
|
if (meta == null) { |
376 |
0
|
return null; |
377 |
|
} |
378 |
0
|
Long result = null; |
379 |
0
|
for (ConstraintMetadata cons : meta.getConstraints()) { |
380 |
0
|
Long max = tryParseLong(cons.getMaxValue()); |
381 |
0
|
if (max != null) { |
382 |
0
|
if (result == null || max < result) { |
383 |
0
|
result = max; |
384 |
|
} |
385 |
|
} |
386 |
|
} |
387 |
0
|
return result; |
388 |
|
} |
389 |
|
|
390 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
391 |
0
|
public static Double getLargestMinValueDouble(Metadata meta) {... |
392 |
0
|
if (meta == null) { |
393 |
0
|
return null; |
394 |
|
} |
395 |
0
|
Double result = null; |
396 |
0
|
for (ConstraintMetadata cons : meta.getConstraints()) { |
397 |
0
|
Double min = tryParseDouble(cons.getMinValue()); |
398 |
0
|
if (min != null) { |
399 |
0
|
if (result == null || min > result) { |
400 |
0
|
result = min; |
401 |
|
} |
402 |
|
} |
403 |
|
} |
404 |
0
|
return result; |
405 |
|
} |
406 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
407 |
0
|
public static Double getSmallestMaxValueDouble(Metadata meta) {... |
408 |
0
|
if (meta == null) { |
409 |
0
|
return null; |
410 |
|
} |
411 |
0
|
Double result = null; |
412 |
0
|
for (ConstraintMetadata cons : meta.getConstraints()) { |
413 |
0
|
Double max = tryParseDouble(cons.getMaxValue()); |
414 |
0
|
if (max != null) { |
415 |
0
|
if (result == null || max < result) { |
416 |
0
|
result = max; |
417 |
|
} |
418 |
|
} |
419 |
|
} |
420 |
0
|
return result; |
421 |
|
} |
422 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 9 |
Complexity Density: 0.75 |
|
423 |
0
|
public static Date getLargestMinValueDate(Metadata meta, DateParser parser, Object dataValue) {... |
424 |
0
|
if (meta == null) { |
425 |
0
|
return null; |
426 |
|
} |
427 |
0
|
Date result = null; |
428 |
0
|
for (ConstraintMetadata cons : meta.getConstraints()) { |
429 |
0
|
Date min = tryParseDate(cons.getMinValue(), parser); |
430 |
0
|
if (min != null) { |
431 |
0
|
if (result == null || min.getTime() > result.getTime()) { |
432 |
0
|
result = min; |
433 |
|
} |
434 |
|
} |
435 |
|
} |
436 |
0
|
if (dataValue != null && dataValue instanceof Date){ |
437 |
0
|
if (result == null || (((Date)dataValue).getTime() > result.getTime())){ |
438 |
0
|
result = (Date)dataValue; |
439 |
|
} |
440 |
|
} |
441 |
0
|
return result; |
442 |
|
} |
443 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 9 |
Complexity Density: 0.75 |
|
444 |
0
|
public static Date getSmallestMaxValueDate(Metadata meta, DateParser parser, Object dataValue) {... |
445 |
0
|
if (meta == null) { |
446 |
0
|
return null; |
447 |
|
} |
448 |
0
|
Date result = null; |
449 |
0
|
for (ConstraintMetadata cons : meta.getConstraints()) { |
450 |
0
|
Date max = tryParseDate(cons.getMaxValue(), parser); |
451 |
0
|
if (max != null) { |
452 |
0
|
if (result == null || max.getTime() < result.getTime()) { |
453 |
0
|
result = max; |
454 |
|
} |
455 |
|
} |
456 |
|
} |
457 |
0
|
if (dataValue != null && dataValue instanceof Date){ |
458 |
0
|
if (result==null || (((Date)dataValue).getTime() < result.getTime())){ |
459 |
0
|
result = (Date)dataValue; |
460 |
|
} |
461 |
|
} |
462 |
0
|
return result; |
463 |
|
} |
464 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
465 |
0
|
private static Long tryParseLong(String s) {... |
466 |
0
|
Long result = null; |
467 |
|
|
468 |
0
|
if (s != null) { |
469 |
0
|
try { |
470 |
0
|
result = Long.valueOf(s); |
471 |
|
} catch (Exception e) { |
472 |
|
|
473 |
|
} |
474 |
|
} |
475 |
|
|
476 |
0
|
return result; |
477 |
|
} |
478 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
479 |
0
|
private static Double tryParseDouble(String s) {... |
480 |
0
|
Double result = null; |
481 |
|
|
482 |
0
|
if (s != null) { |
483 |
0
|
try { |
484 |
0
|
result = Double.valueOf(s); |
485 |
|
} catch (Exception e) { |
486 |
|
|
487 |
|
} |
488 |
|
} |
489 |
|
|
490 |
0
|
return result; |
491 |
|
} |
492 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
493 |
0
|
private static Date tryParseDate(String s, DateParser parser) {... |
494 |
0
|
Date result = null; |
495 |
|
|
496 |
0
|
if (s != null) { |
497 |
0
|
try { |
498 |
0
|
result = parser.parseDate(s); |
499 |
|
} catch (Exception e) { |
500 |
|
|
501 |
|
} |
502 |
|
} |
503 |
|
|
504 |
0
|
return result; |
505 |
|
} |
506 |
|
} |