1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
package org.kuali.student.common.validator; |
10 |
|
|
11 |
|
import java.lang.reflect.InvocationTargetException; |
12 |
|
import java.util.ArrayList; |
13 |
|
import java.util.Collection; |
14 |
|
import java.util.Date; |
15 |
|
import java.util.HashMap; |
16 |
|
import java.util.Iterator; |
17 |
|
import java.util.List; |
18 |
|
import java.util.Map; |
19 |
|
import java.util.Stack; |
20 |
|
|
21 |
|
import org.apache.commons.beanutils.PropertyUtils; |
22 |
|
import org.apache.log4j.Logger; |
23 |
|
import org.kuali.student.common.dictionary.dto.CaseConstraint; |
24 |
|
import org.kuali.student.common.dictionary.dto.CommonLookupParam; |
25 |
|
import org.kuali.student.common.dictionary.dto.Constraint; |
26 |
|
import org.kuali.student.common.dictionary.dto.DataType; |
27 |
|
import org.kuali.student.common.dictionary.dto.FieldDefinition; |
28 |
|
import org.kuali.student.common.dictionary.dto.LookupConstraint; |
29 |
|
import org.kuali.student.common.dictionary.dto.MustOccurConstraint; |
30 |
|
import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition; |
31 |
|
import org.kuali.student.common.dictionary.dto.RequiredConstraint; |
32 |
|
import org.kuali.student.common.dictionary.dto.ValidCharsConstraint; |
33 |
|
import org.kuali.student.common.dictionary.dto.WhenConstraint; |
34 |
|
import org.kuali.student.common.messages.dto.Message; |
35 |
|
import org.kuali.student.common.messages.service.MessageService; |
36 |
|
import org.kuali.student.common.search.dto.SearchParam; |
37 |
|
import org.kuali.student.common.search.dto.SearchRequest; |
38 |
|
import org.kuali.student.common.search.dto.SearchResult; |
39 |
|
import org.kuali.student.common.search.service.SearchDispatcher; |
40 |
|
import org.kuali.student.common.util.MessageUtils; |
41 |
|
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
42 |
|
import org.kuali.student.common.validation.dto.ValidationResultInfo.ErrorLevel; |
43 |
|
|
|
|
| 66.6% |
Uncovered Elements: 275 (823) |
Complexity: 261 |
Complexity Density: 0.55 |
|
44 |
|
public class DefaultValidatorImpl extends BaseAbstractValidator { |
45 |
|
final static Logger LOG = Logger.getLogger(DefaultValidatorImpl.class); |
46 |
|
|
47 |
|
private MessageService messageService = null; |
48 |
|
|
49 |
|
private SearchDispatcher searchDispatcher; |
50 |
|
|
51 |
|
private String messageLocaleKey = "en"; |
52 |
|
|
53 |
|
private String messageGroupKey = "validation"; |
54 |
|
|
55 |
|
private DateParser dateParser = new ServerDateParser(); |
56 |
|
|
57 |
|
private boolean serverSide = true; |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
0
|
public MessageService getMessageService() {... |
60 |
0
|
return messageService; |
61 |
|
} |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
9
|
public void setMessageService(MessageService messageService) {... |
64 |
9
|
this.messageService = messageService; |
65 |
|
} |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
0
|
public String getMessageLocaleKey() {... |
68 |
0
|
return messageLocaleKey; |
69 |
|
} |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
0
|
public void setMessageLocaleKey(String messageLocaleKey) {... |
72 |
0
|
this.messageLocaleKey = messageLocaleKey; |
73 |
|
} |
74 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
0
|
public String getMessageGroupKey() {... |
76 |
0
|
return messageGroupKey; |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0
|
public void setMessageGroupKey(String messageGroupKey) {... |
80 |
0
|
this.messageGroupKey = messageGroupKey; |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
19
|
public void setDateParser(DateParser dateParser) {... |
84 |
19
|
this.dateParser = dateParser; |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
|
@return |
89 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
90 |
0
|
public boolean isServerSide() {... |
91 |
0
|
return serverSide; |
92 |
|
} |
93 |
|
|
94 |
|
|
95 |
|
@param |
96 |
|
|
97 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
0
|
public void setServerSide(boolean serverSide) {... |
99 |
0
|
this.serverSide = serverSide; |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
|
@return |
104 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
0
|
public DateParser getDateParser() {... |
106 |
0
|
return dateParser; |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
@param |
113 |
|
@param |
114 |
|
@return |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
116 |
129
|
public List<ValidationResultInfo> validateObject(Object data, ObjectStructureDefinition objStructure) {... |
117 |
|
|
118 |
129
|
List<ValidationResultInfo> results = new ArrayList<ValidationResultInfo>(); |
119 |
129
|
Stack<String> elementStack = new Stack<String>(); |
120 |
|
|
121 |
129
|
validateObject(results, data, objStructure, elementStack, data, objStructure, true); |
122 |
|
|
123 |
128
|
return results; |
124 |
|
} |
125 |
|
|
|
|
| 74.1% |
Uncovered Elements: 7 (27) |
Complexity: 10 |
Complexity Density: 0.59 |
|
126 |
836
|
private void validateObject(List<ValidationResultInfo> results, Object data, ObjectStructureDefinition objStructure, Stack<String> elementStack, Object rootData, ObjectStructureDefinition rootObjStructure, boolean isRoot) {... |
127 |
|
|
128 |
836
|
ConstraintDataProvider dataProvider = new BeanConstraintDataProvider(); |
129 |
836
|
dataProvider.initialize(data); |
130 |
|
|
131 |
|
|
132 |
836
|
StringBuilder objXPathElement = new StringBuilder(dataProvider.getPath()); |
133 |
|
|
134 |
836
|
if(!isRoot && !objXPathElement.toString().isEmpty()){ |
135 |
0
|
elementStack.push(objXPathElement.toString()); |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
836
|
if (null == objStructure) { |
143 |
25
|
return; |
144 |
|
} |
145 |
|
|
146 |
811
|
for (FieldDefinition f : objStructure.getAttributes()) { |
147 |
4676
|
validateField(results, f, objStructure, dataProvider, elementStack, rootData, rootObjStructure); |
148 |
|
|
149 |
|
|
150 |
4676
|
if (f.getCustomValidatorClass() != null || f.isServerSide() && serverSide) { |
151 |
1
|
Validator customValidator = validatorFactory.getValidator(f.getCustomValidatorClass()); |
152 |
1
|
if(customValidator==null){ |
153 |
1
|
throw new RuntimeException("Custom Validator "+f.getCustomValidatorClass()+" was not configured in this context"); |
154 |
|
} |
155 |
0
|
List<ValidationResultInfo> l = customValidator.validateObject(f,data, objStructure,elementStack); |
156 |
0
|
results.addAll(l); |
157 |
|
} |
158 |
|
} |
159 |
810
|
if(!isRoot && !objXPathElement.toString().isEmpty()){ |
160 |
0
|
elementStack.pop(); |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
} |
173 |
|
|
|
|
| 71.4% |
Uncovered Elements: 24 (84) |
Complexity: 20 |
Complexity Density: 0.34 |
|
174 |
4676
|
public void validateField(List<ValidationResultInfo> results, FieldDefinition field, ObjectStructureDefinition objStruct, ConstraintDataProvider dataProvider, Stack<String> elementStack, Object rootData, ObjectStructureDefinition rootObjectStructure) {... |
175 |
|
|
176 |
4676
|
Object value = dataProvider.getValue(field.getName()); |
177 |
|
|
178 |
|
|
179 |
4676
|
if (value == null || "".equals(value.toString().trim())) { |
180 |
945
|
processConstraint(results, field, objStruct, value, dataProvider, elementStack, rootData, rootObjectStructure); |
181 |
945
|
return; |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
3731
|
if (DataType.COMPLEX.equals(field.getDataType())) { |
188 |
606
|
ObjectStructureDefinition nestedObjStruct = null; |
189 |
|
|
190 |
606
|
if (null != field.getDataObjectStructure()) { |
191 |
606
|
nestedObjStruct = field.getDataObjectStructure(); |
192 |
|
} |
193 |
|
|
194 |
606
|
elementStack.push(field.getName()); |
195 |
|
|
196 |
|
|
197 |
606
|
if (value instanceof Collection) { |
198 |
|
|
199 |
232
|
String xPathForCollection = getElementXpath(elementStack) + "/*"; |
200 |
|
|
201 |
232
|
int i=0; |
202 |
232
|
for (Object o : (Collection<?>) value) { |
203 |
333
|
elementStack.push(Integer.toString(i)); |
204 |
|
|
205 |
333
|
processNestedObjectStructure(results, o, nestedObjStruct, field, elementStack, rootData, rootObjectStructure); |
206 |
|
|
207 |
|
|
208 |
333
|
elementStack.pop(); |
209 |
333
|
i++; |
210 |
|
} |
211 |
232
|
if (field.getMinOccurs() != null && field.getMinOccurs() > ((Collection<?>) value).size()) { |
212 |
0
|
ValidationResultInfo valRes = new ValidationResultInfo(xPathForCollection, value); |
213 |
0
|
valRes.setError(MessageUtils.interpolate(getMessage("validation.minOccurs"), toMap(field))); |
214 |
0
|
results.add(valRes); |
215 |
|
} |
216 |
|
|
217 |
232
|
Integer maxOccurs = tryParse(field.getMaxOccurs()); |
218 |
232
|
if (maxOccurs != null && maxOccurs < ((Collection<?>) value).size()) { |
219 |
0
|
ValidationResultInfo valRes = new ValidationResultInfo(xPathForCollection, value); |
220 |
0
|
valRes.setError(MessageUtils.interpolate(getMessage("validation.maxOccurs"), toMap(field))); |
221 |
0
|
results.add(valRes); |
222 |
|
} |
223 |
|
} else { |
224 |
374
|
if (null != value) { |
225 |
374
|
processNestedObjectStructure(results, value, nestedObjStruct, field, elementStack, rootData, rootObjectStructure); |
226 |
|
} else { |
227 |
0
|
if (field.getMinOccurs() != null && field.getMinOccurs() > 0) { |
228 |
0
|
ValidationResultInfo val = new ValidationResultInfo(getElementXpath(elementStack), value); |
229 |
0
|
if(field.getLabelKey()!=null){ |
230 |
0
|
val.setError(getMessage(field.getLabelKey())); |
231 |
|
} else { |
232 |
0
|
val.setError(getMessage("validation.required")); |
233 |
|
} |
234 |
0
|
results.add(val); |
235 |
|
} |
236 |
|
} |
237 |
|
} |
238 |
|
|
239 |
|
|
240 |
606
|
elementStack.pop(); |
241 |
|
|
242 |
|
} else { |
243 |
|
|
244 |
3125
|
if (value instanceof Collection) { |
245 |
|
|
246 |
176
|
if(((Collection<?>)value).isEmpty()){ |
247 |
95
|
processConstraint(results, field, objStruct, "", dataProvider, elementStack, rootData, rootObjectStructure); |
248 |
|
} |
249 |
|
|
250 |
176
|
int i = 0; |
251 |
176
|
for (Object o : (Collection<?>) value) { |
252 |
|
|
253 |
168
|
String oldFieldName = field.getName(); |
254 |
168
|
elementStack.push(oldFieldName); |
255 |
168
|
field.setName(Integer.toBinaryString(i)); |
256 |
|
|
257 |
168
|
processConstraint(results, field, objStruct, o, dataProvider, elementStack, rootData, rootObjectStructure); |
258 |
|
|
259 |
168
|
elementStack.pop(); |
260 |
168
|
field.setName(oldFieldName); |
261 |
168
|
i++; |
262 |
|
} |
263 |
|
|
264 |
176
|
String xPath = getElementXpath(elementStack) + "/" + field.getName() + "/*"; |
265 |
176
|
if (field.getMinOccurs() != null && field.getMinOccurs() > ((Collection<?>) value).size()) { |
266 |
0
|
ValidationResultInfo valRes = new ValidationResultInfo(xPath, value); |
267 |
0
|
valRes.setError(MessageUtils.interpolate(getMessage("validation.minOccurs"), toMap(field))); |
268 |
0
|
results.add(valRes); |
269 |
|
} |
270 |
|
|
271 |
176
|
Integer maxOccurs = tryParse(field.getMaxOccurs()); |
272 |
176
|
if (maxOccurs != null && maxOccurs < ((Collection<?>) value).size()) { |
273 |
2
|
ValidationResultInfo valRes = new ValidationResultInfo(xPath, value); |
274 |
2
|
valRes.setError(MessageUtils.interpolate(getMessage("validation.maxOccurs"), toMap(field))); |
275 |
2
|
results.add(valRes); |
276 |
|
} |
277 |
|
} else { |
278 |
2949
|
processConstraint(results, field, objStruct, value, dataProvider, elementStack, rootData, rootObjectStructure); |
279 |
|
} |
280 |
|
|
281 |
|
} |
282 |
|
} |
283 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
284 |
2866
|
protected Integer tryParse(String s) {... |
285 |
2866
|
Integer result = null; |
286 |
2866
|
if (s != null) { |
287 |
2838
|
try { |
288 |
2838
|
result = Integer.valueOf(s); |
289 |
|
} catch (NumberFormatException e) { |
290 |
|
|
291 |
|
} |
292 |
|
} |
293 |
2866
|
return result; |
294 |
|
} |
295 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
296 |
707
|
protected void processNestedObjectStructure(List<ValidationResultInfo> results, Object value, ObjectStructureDefinition nestedObjStruct, FieldDefinition field, Stack<String> elementStack, Object rootData, ObjectStructureDefinition rootObjStructure) {... |
297 |
707
|
validateObject(results, value, nestedObjStruct, elementStack, rootData, rootObjStructure, false); |
298 |
|
} |
299 |
|
|
|
|
| 81.8% |
Uncovered Elements: 8 (44) |
Complexity: 15 |
Complexity Density: 0.62 |
|
300 |
4157
|
protected void processConstraint(List<ValidationResultInfo> valResults, FieldDefinition field, ObjectStructureDefinition objStructure, Object value, ConstraintDataProvider dataProvider, Stack<String> elementStack, Object rootData, ObjectStructureDefinition rootObjStructure) {... |
301 |
|
|
302 |
|
|
303 |
|
|
304 |
4157
|
Constraint caseConstraint = processCaseConstraint(valResults, field.getCaseConstraint(), objStructure, value, dataProvider, elementStack, rootData, rootObjStructure); |
305 |
|
|
306 |
4157
|
Constraint constraint = (null != caseConstraint) ? caseConstraint : field; |
307 |
|
|
308 |
4157
|
processBaseConstraints(valResults, constraint, field, value, elementStack); |
309 |
|
|
310 |
|
|
311 |
4157
|
if (value == null || "".equals(value.toString().trim())) { |
312 |
1040
|
return; |
313 |
|
} |
314 |
|
|
315 |
3117
|
String elementPath = getElementXpath(elementStack) + "/" + field.getName(); |
316 |
|
|
317 |
|
|
318 |
3117
|
if (null != constraint.getValidChars()) { |
319 |
1192
|
ValidationResultInfo val = processValidCharConstraint(elementPath, constraint.getValidChars(), dataProvider, value); |
320 |
1192
|
if (null != val) { |
321 |
14
|
valResults.add(val); |
322 |
|
} |
323 |
|
} |
324 |
|
|
325 |
|
|
326 |
3117
|
if (value != null && !"".equals(value.toString().trim())) { |
327 |
3117
|
if (null != constraint.getRequireConstraint() && constraint.getRequireConstraint().size() > 0) { |
328 |
37
|
for (RequiredConstraint rc : constraint.getRequireConstraint()) { |
329 |
37
|
ValidationResultInfo val = processRequireConstraint(elementPath, rc, field, objStructure, dataProvider); |
330 |
37
|
if (null != val) { |
331 |
2
|
valResults.add(val); |
332 |
|
|
333 |
2
|
processCrossFieldWarning(valResults, rc, val.getErrorLevel(), field.getName()); |
334 |
|
} |
335 |
|
} |
336 |
|
} |
337 |
|
} |
338 |
|
|
339 |
|
|
340 |
3117
|
if (null != constraint.getOccursConstraint() && constraint.getOccursConstraint().size() > 0) { |
341 |
0
|
for (MustOccurConstraint oc : constraint.getOccursConstraint()) { |
342 |
0
|
ValidationResultInfo val = processOccursConstraint(elementPath, oc, field, objStructure, dataProvider); |
343 |
0
|
if (null != val) { |
344 |
0
|
valResults.add(val); |
345 |
|
} |
346 |
|
} |
347 |
|
} |
348 |
|
|
349 |
|
|
350 |
3117
|
if (null != constraint.getLookupDefinition()) { |
351 |
159
|
processLookupConstraint(valResults, constraint.getLookupDefinition(), field, elementStack, dataProvider,objStructure, rootData, rootObjStructure, value); |
352 |
|
} |
353 |
|
} |
354 |
|
|
|
|
| 88% |
Uncovered Elements: 3 (25) |
Complexity: 5 |
Complexity Density: 0.29 |
|
355 |
37
|
protected ValidationResultInfo processRequireConstraint(String element, RequiredConstraint constraint, FieldDefinition field, ObjectStructureDefinition objStructure, ConstraintDataProvider dataProvider) {... |
356 |
|
|
357 |
37
|
ValidationResultInfo val = null; |
358 |
|
|
359 |
37
|
String fieldName = constraint.getFieldPath(); |
360 |
37
|
Object fieldValue = dataProvider.getValue(fieldName); |
361 |
|
|
362 |
37
|
boolean result = true; |
363 |
|
|
364 |
37
|
if (fieldValue instanceof java.lang.String) { |
365 |
36
|
result = hasText((String) fieldValue); |
366 |
1
|
} else if (fieldValue instanceof Collection) { |
367 |
0
|
result = (((Collection<?>) fieldValue).size() > 0); |
368 |
|
} else { |
369 |
1
|
result = (null != fieldValue) ? true : false; |
370 |
|
} |
371 |
|
|
372 |
37
|
if (!result) { |
373 |
2
|
Map<String, Object> rMap = new HashMap<String, Object>(); |
374 |
2
|
rMap.put("field1", field.getName()); |
375 |
2
|
rMap.put("field2", fieldName); |
376 |
2
|
val = new ValidationResultInfo(element, fieldValue); |
377 |
2
|
val.setMessage(MessageUtils.interpolate(getMessage("validation.requiresField"), rMap)); |
378 |
2
|
val.setLevel(constraint.getErrorLevel()); |
379 |
|
} |
380 |
|
|
381 |
37
|
return val; |
382 |
|
} |
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
@param |
388 |
|
@param |
389 |
|
@param |
390 |
|
|
|
|
| 72.7% |
Uncovered Elements: 21 (77) |
Complexity: 25 |
Complexity Density: 0.56 |
|
391 |
4165
|
protected Constraint processCaseConstraint(List<ValidationResultInfo> valResults, CaseConstraint caseConstraint, ObjectStructureDefinition objStructure, Object value, ConstraintDataProvider dataProvider, Stack<String> elementStack, Object rootData, ObjectStructureDefinition rootObjStructure) {... |
392 |
|
|
393 |
4165
|
if (null == caseConstraint) { |
394 |
3991
|
return null; |
395 |
|
} |
396 |
|
|
397 |
174
|
String operator = (hasText(caseConstraint.getOperator())) ? caseConstraint.getOperator() : "EQUALS"; |
398 |
174
|
FieldDefinition caseField = null; |
399 |
174
|
boolean absolutePath = false; |
400 |
174
|
if(hasText(caseConstraint.getFieldPath())){ |
401 |
174
|
if(caseConstraint.getFieldPath().startsWith("/")){ |
402 |
8
|
absolutePath = true; |
403 |
8
|
caseField = ValidatorUtils.getField(caseConstraint.getFieldPath().substring(1), rootObjStructure); |
404 |
|
}else{ |
405 |
166
|
caseField = ValidatorUtils.getField(caseConstraint.getFieldPath(), objStructure); |
406 |
|
} |
407 |
|
} |
408 |
|
|
409 |
|
|
410 |
174
|
Object fieldValue = value; |
411 |
174
|
if(caseField!=null){ |
412 |
156
|
if(absolutePath){ |
413 |
8
|
try { |
414 |
8
|
if(caseField.isDynamic()){ |
415 |
|
|
416 |
|
|
417 |
|
|
418 |
2
|
Map<String,String> attributes = (Map<String,String>) PropertyUtils.getNestedProperty(rootData, "attributes"); |
419 |
2
|
if(attributes!=null){ |
420 |
2
|
fieldValue = attributes.get(caseConstraint.getFieldPath().substring(1)); |
421 |
|
} |
422 |
|
}else{ |
423 |
6
|
fieldValue = PropertyUtils.getNestedProperty(rootData, caseConstraint.getFieldPath().substring(1)); |
424 |
|
} |
425 |
|
} catch (IllegalAccessException e) { |
426 |
|
} catch (InvocationTargetException e) { |
427 |
|
} catch (NoSuchMethodException e) { |
428 |
|
} |
429 |
|
}else{ |
430 |
148
|
fieldValue = dataProvider.getValue(caseField.getName()); |
431 |
|
} |
432 |
|
} |
433 |
174
|
DataType fieldDataType = (null != caseField ? caseField.getDataType():null); |
434 |
|
|
435 |
|
|
436 |
174
|
if(null == fieldValue) { |
437 |
36
|
return null; |
438 |
|
} |
439 |
|
|
440 |
|
|
441 |
138
|
for (WhenConstraint wc : caseConstraint.getWhenConstraint()) { |
442 |
|
|
443 |
187
|
if(hasText(wc.getValuePath())){ |
444 |
0
|
Object whenValue = null; |
445 |
0
|
if(wc.getValuePath().startsWith("/")){ |
446 |
0
|
try { |
447 |
0
|
whenValue = PropertyUtils.getNestedProperty(rootData, wc.getValuePath().substring(1)); |
448 |
|
} catch (IllegalAccessException e) { |
449 |
|
} catch (InvocationTargetException e) { |
450 |
|
} catch (NoSuchMethodException e) { |
451 |
|
} |
452 |
|
}else{ |
453 |
0
|
whenValue = dataProvider.getValue(wc.getValuePath()); |
454 |
|
} |
455 |
0
|
if (ValidatorUtils.compareValues(fieldValue, whenValue, fieldDataType, operator, caseConstraint.isCaseSensitive(), dateParser) && null != wc.getConstraint()) { |
456 |
0
|
Constraint constraint = wc.getConstraint(); |
457 |
0
|
if (constraint.getCaseConstraint() != null){ |
458 |
0
|
return processCaseConstraint(valResults, constraint.getCaseConstraint(), objStructure, value, dataProvider, elementStack, rootData, rootObjStructure); |
459 |
|
} else { |
460 |
0
|
processCrossFieldWarning(valResults, caseConstraint, constraint, value, constraint.getErrorLevel()); |
461 |
0
|
return constraint; |
462 |
|
} |
463 |
|
} |
464 |
|
}else{ |
465 |
187
|
List<Object> whenValueList = wc.getValues(); |
466 |
|
|
467 |
187
|
for (Object whenValue : whenValueList) { |
468 |
413
|
if (ValidatorUtils.compareValues(fieldValue, whenValue, fieldDataType, operator, caseConstraint.isCaseSensitive(), dateParser) && null != wc.getConstraint()) { |
469 |
21
|
Constraint constraint = wc.getConstraint(); |
470 |
21
|
if (constraint.getCaseConstraint() != null){ |
471 |
8
|
return processCaseConstraint(valResults, constraint.getCaseConstraint(), objStructure, value, dataProvider, elementStack, rootData, rootObjStructure); |
472 |
|
} else { |
473 |
13
|
processCrossFieldWarning(valResults, caseConstraint, constraint, value, constraint.getErrorLevel()); |
474 |
13
|
return constraint; |
475 |
|
} |
476 |
|
} |
477 |
|
} |
478 |
|
} |
479 |
|
} |
480 |
|
|
481 |
117
|
return null; |
482 |
|
} |
483 |
|
|
|
|
| 88% |
Uncovered Elements: 3 (25) |
Complexity: 6 |
Complexity Density: 0.35 |
|
484 |
1454
|
public ValidationResultInfo processValidCharConstraint(String element, ValidCharsConstraint vcConstraint, ConstraintDataProvider dataProvider, Object value) {... |
485 |
|
|
486 |
1454
|
ValidationResultInfo val = null; |
487 |
|
|
488 |
1454
|
StringBuilder fieldValue = new StringBuilder(); |
489 |
1454
|
String validChars = vcConstraint.getValue(); |
490 |
|
|
491 |
1454
|
fieldValue.append(ValidatorUtils.getString(value)); |
492 |
|
|
493 |
1454
|
int typIdx = validChars.indexOf(":"); |
494 |
1454
|
String processorType = "regex"; |
495 |
1454
|
if (-1 == typIdx) { |
496 |
0
|
validChars = "[" + validChars + "]*"; |
497 |
|
} else { |
498 |
1454
|
processorType = validChars.substring(0, typIdx); |
499 |
1454
|
validChars = validChars.substring(typIdx + 1); |
500 |
|
} |
501 |
|
|
502 |
1454
|
if ("regex".equalsIgnoreCase(processorType)) { |
503 |
1454
|
if (fieldValue == null || !fieldValue.toString().matches(validChars)) { |
504 |
127
|
val = new ValidationResultInfo(element, fieldValue); |
505 |
127
|
if(vcConstraint.getLabelKey()!=null){ |
506 |
87
|
val.setError(getMessage(vcConstraint.getLabelKey())); |
507 |
|
}else{ |
508 |
40
|
val.setError(getMessage("validation.validCharsFailed")); |
509 |
|
} |
510 |
|
} |
511 |
|
} |
512 |
|
|
513 |
1454
|
return val; |
514 |
|
} |
515 |
|
|
516 |
|
|
517 |
|
|
518 |
|
|
519 |
|
@param |
520 |
|
@param |
521 |
|
@param |
522 |
|
@param |
523 |
|
@param |
524 |
|
@param |
525 |
|
@param |
526 |
|
@return |
527 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 6 |
Complexity Density: 0.46 |
|
528 |
0
|
protected ValidationResultInfo processOccursConstraint(String element, MustOccurConstraint constraint, FieldDefinition field, ObjectStructureDefinition objStructure, ConstraintDataProvider dataProvider) {... |
529 |
|
|
530 |
0
|
boolean result = false; |
531 |
0
|
int trueCount = 0; |
532 |
|
|
533 |
0
|
ValidationResultInfo val = null; |
534 |
|
|
535 |
0
|
for (RequiredConstraint rc : constraint.getRequiredFields()) { |
536 |
0
|
trueCount += (processRequireConstraint("", rc, field, objStructure, dataProvider) != null) ? 1 : 0; |
537 |
|
} |
538 |
|
|
539 |
0
|
for (MustOccurConstraint oc : constraint.getOccurs()) { |
540 |
0
|
trueCount += (processOccursConstraint("", oc, field, objStructure, dataProvider) != null) ? 1 : 0; |
541 |
|
} |
542 |
|
|
543 |
0
|
result = (trueCount >= constraint.getMin() && trueCount <= constraint.getMax()) ? true : false; |
544 |
|
|
545 |
0
|
if (!result) { |
546 |
|
|
547 |
0
|
val = new ValidationResultInfo(element, null); |
548 |
0
|
val.setMessage(getMessage("validation.occurs")); |
549 |
0
|
val.setLevel(constraint.getErrorLevel()); |
550 |
|
} |
551 |
|
|
552 |
0
|
return val; |
553 |
|
} |
554 |
|
|
555 |
|
|
|
|
| 81.3% |
Uncovered Elements: 17 (91) |
Complexity: 25 |
Complexity Density: 0.42 |
|
556 |
159
|
protected void processLookupConstraint(List<ValidationResultInfo> valResults, LookupConstraint lookupConstraint, FieldDefinition field, Stack<String> elementStack, ConstraintDataProvider dataProvider, ObjectStructureDefinition objStructure, Object rootData, ObjectStructureDefinition rootObjStructure, Object value) {... |
557 |
159
|
if (lookupConstraint == null) { |
558 |
0
|
return; |
559 |
|
} |
560 |
|
|
561 |
|
|
562 |
159
|
List<SearchParam> params = new ArrayList<SearchParam>(); |
563 |
|
|
564 |
159
|
for (CommonLookupParam paramMapping : lookupConstraint.getParams()) { |
565 |
|
|
566 |
337
|
if(lookupConstraint.getSearchParamIdKey()!=null&&lookupConstraint.getSearchParamIdKey().equals(paramMapping.getKey())){ |
567 |
68
|
continue; |
568 |
|
} |
569 |
|
|
570 |
269
|
SearchParam param = new SearchParam(); |
571 |
|
|
572 |
269
|
param.setKey(paramMapping.getKey()); |
573 |
|
|
574 |
|
|
575 |
269
|
if (paramMapping.getFieldPath() != null && !paramMapping.getFieldPath().isEmpty()) { |
576 |
72
|
FieldDefinition lookupField = null; |
577 |
72
|
boolean absolutePath = false; |
578 |
72
|
if(hasText(paramMapping.getFieldPath())){ |
579 |
72
|
if(paramMapping.getFieldPath().startsWith("/")){ |
580 |
50
|
absolutePath = true; |
581 |
50
|
lookupField = ValidatorUtils.getField(paramMapping.getFieldPath().substring(1), rootObjStructure); |
582 |
|
}else{ |
583 |
22
|
lookupField = ValidatorUtils.getField(paramMapping.getFieldPath(), objStructure); |
584 |
|
} |
585 |
|
} |
586 |
72
|
Object fieldValue = null; |
587 |
72
|
if(lookupField!=null){ |
588 |
72
|
if(absolutePath){ |
589 |
50
|
try { |
590 |
50
|
if(lookupField.isDynamic()){ |
591 |
|
|
592 |
|
|
593 |
0
|
Map<String,String> attributes = (Map<String,String>) PropertyUtils.getNestedProperty(rootData, "attributes"); |
594 |
0
|
if(attributes!=null){ |
595 |
0
|
fieldValue = attributes.get(paramMapping.getFieldPath().substring(1)); |
596 |
|
} |
597 |
|
}else{ |
598 |
50
|
fieldValue = PropertyUtils.getNestedProperty(rootData, paramMapping.getFieldPath().substring(1)); |
599 |
|
} |
600 |
|
} catch (IllegalAccessException e) { |
601 |
|
} catch (InvocationTargetException e) { |
602 |
|
} catch (NoSuchMethodException e) { |
603 |
|
} |
604 |
|
}else{ |
605 |
22
|
fieldValue = dataProvider.getValue(lookupField.getName()); |
606 |
|
} |
607 |
|
}else{ |
608 |
0
|
fieldValue = dataProvider.getValue(paramMapping.getFieldPath()); |
609 |
|
} |
610 |
|
|
611 |
72
|
if (fieldValue instanceof String) { |
612 |
14
|
param.setValue((String) fieldValue); |
613 |
58
|
} else if (fieldValue instanceof List<?>) { |
614 |
58
|
param.setValue((List<String>) fieldValue); |
615 |
|
} |
616 |
197
|
} else if (paramMapping.getDefaultValueString() != null) { |
617 |
47
|
param.setValue(paramMapping.getDefaultValueString()); |
618 |
|
} else { |
619 |
150
|
param.setValue(paramMapping.getDefaultValueList()); |
620 |
|
} |
621 |
269
|
params.add(param); |
622 |
|
} |
623 |
|
|
624 |
159
|
if(lookupConstraint.getSearchParamIdKey()!=null){ |
625 |
155
|
SearchParam param = new SearchParam(); |
626 |
155
|
param.setKey(lookupConstraint.getSearchParamIdKey()); |
627 |
155
|
if (value instanceof String) { |
628 |
155
|
param.setValue((String) value); |
629 |
0
|
} else if (value instanceof List<?>) { |
630 |
0
|
param.setValue((List<String>) value); |
631 |
|
} |
632 |
155
|
params.add(param); |
633 |
|
} |
634 |
|
|
635 |
159
|
SearchRequest searchRequest = new SearchRequest(); |
636 |
159
|
searchRequest.setMaxResults(1); |
637 |
159
|
searchRequest.setStartAt(0); |
638 |
159
|
searchRequest.setNeededTotalResults(false); |
639 |
159
|
searchRequest.setSearchKey(lookupConstraint.getSearchTypeId()); |
640 |
159
|
searchRequest.setParams(params); |
641 |
|
|
642 |
159
|
SearchResult searchResult = null; |
643 |
159
|
try { |
644 |
159
|
searchResult = searchDispatcher.dispatchSearch(searchRequest); |
645 |
|
} catch (Exception e) { |
646 |
2
|
LOG.info("Error calling Search", e); |
647 |
|
} |
648 |
|
|
649 |
159
|
if (searchResult == null || searchResult.getRows() == null || searchResult.getRows().isEmpty()) { |
650 |
4
|
ValidationResultInfo val = new ValidationResultInfo(getElementXpath(elementStack) + "/" + field.getName(), value); |
651 |
4
|
val.setLevel(lookupConstraint.getErrorLevel()); |
652 |
4
|
val.setMessage(getMessage("validation.lookup")); |
653 |
4
|
valResults.add(val); |
654 |
4
|
processCrossFieldWarning(valResults, lookupConstraint, lookupConstraint.getErrorLevel()); |
655 |
|
} |
656 |
|
} |
657 |
|
|
|
|
| 89.1% |
Uncovered Elements: 5 (46) |
Complexity: 13 |
Complexity Density: 0.5 |
|
658 |
4157
|
protected void processBaseConstraints(List<ValidationResultInfo> valResults, Constraint constraint, FieldDefinition field, Object value, Stack<String> elementStack) {... |
659 |
4157
|
DataType dataType = field.getDataType(); |
660 |
4157
|
String name = field.getName(); |
661 |
|
|
662 |
4157
|
if (value == null || "".equals(value.toString().trim())) { |
663 |
1040
|
if (constraint.getMinOccurs() != null && constraint.getMinOccurs() > 0) { |
664 |
44
|
ValidationResultInfo val = new ValidationResultInfo(getElementXpath(elementStack) + "/" + name, value); |
665 |
44
|
if(constraint.getLabelKey()!=null){ |
666 |
0
|
val.setError(getMessage(constraint.getLabelKey())); |
667 |
|
} else { |
668 |
44
|
val.setMessage(getMessage("validation.required")); |
669 |
|
} |
670 |
44
|
val.setLevel(constraint.getErrorLevel()); |
671 |
44
|
valResults.add(val); |
672 |
|
} |
673 |
1040
|
return; |
674 |
|
} |
675 |
|
|
676 |
3117
|
String elementPath = getElementXpath(elementStack) + "/" + name; |
677 |
|
|
678 |
3117
|
if (DataType.STRING.equals(dataType)) { |
679 |
2458
|
validateString(value, constraint, elementPath, valResults); |
680 |
659
|
} else if (DataType.INTEGER.equals(dataType)) { |
681 |
47
|
validateInteger(value, constraint, elementPath, valResults); |
682 |
612
|
} else if (DataType.LONG.equals(dataType)) { |
683 |
31
|
validateLong(value, constraint, elementPath, valResults); |
684 |
581
|
} else if (DataType.DOUBLE.equals(dataType)) { |
685 |
1
|
validateDouble(value, constraint, elementPath, valResults); |
686 |
580
|
} else if (DataType.FLOAT.equals(dataType)) { |
687 |
0
|
validateFloat(value, constraint, elementPath, valResults); |
688 |
580
|
} else if (DataType.BOOLEAN.equals(dataType)) { |
689 |
65
|
validateBoolean(value, constraint, elementPath, valResults); |
690 |
515
|
} else if (DataType.DATE.equals(dataType)) { |
691 |
515
|
validateDate(value, constraint, elementPath, valResults, dateParser); |
692 |
|
} |
693 |
|
} |
694 |
|
|
695 |
|
|
696 |
|
|
697 |
|
|
698 |
|
@param |
699 |
|
@param |
700 |
|
@param |
701 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 8 |
Complexity Density: 1.6 |
|
702 |
13
|
protected void processCrossFieldWarning(List<ValidationResultInfo> valResults, CaseConstraint crossConstraint, Constraint constraint, Object value, ErrorLevel errorLevel){... |
703 |
13
|
if ((ErrorLevel.WARN == errorLevel || ErrorLevel.ERROR == errorLevel) && (value == null || "".equals(value.toString().trim()))) { |
704 |
1
|
if (constraint.getMinOccurs() != null && constraint.getMinOccurs() > 0) { |
705 |
|
|
706 |
1
|
String crossFieldPath = crossConstraint.getFieldPath(); |
707 |
1
|
String crossFieldMessageId = crossConstraint.getFieldPathMessageId() == null ? |
708 |
|
"validation.required":crossConstraint.getFieldPathMessageId(); |
709 |
1
|
addCrossFieldWarning(valResults, crossFieldPath, getMessage(crossFieldMessageId), errorLevel); |
710 |
|
} |
711 |
|
} |
712 |
|
} |
713 |
|
|
714 |
|
|
715 |
|
|
716 |
|
|
717 |
|
@param |
718 |
|
@param |
719 |
|
@param |
720 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 5 |
Complexity Density: 1.25 |
|
721 |
2
|
protected void processCrossFieldWarning(List<ValidationResultInfo> valResults, RequiredConstraint requiredConstraint, ErrorLevel errorLevel, String field){... |
722 |
2
|
if ((ErrorLevel.WARN == errorLevel || ErrorLevel.ERROR == errorLevel) && requiredConstraint != null){ |
723 |
2
|
String crossFieldPath = requiredConstraint.getFieldPath(); |
724 |
2
|
String crossFieldMessageId = requiredConstraint.getFieldPathMessageId() == null ? |
725 |
|
"validation.required":requiredConstraint.getFieldPathMessageId(); |
726 |
2
|
addCrossFieldWarning(valResults, crossFieldPath, getMessage(crossFieldMessageId), errorLevel); |
727 |
|
} |
728 |
|
} |
729 |
|
|
730 |
|
|
731 |
|
|
732 |
|
|
733 |
|
@param |
734 |
|
@param |
735 |
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 7 |
Complexity Density: 1.17 |
|
736 |
4
|
protected void processCrossFieldWarning(List<ValidationResultInfo> valResults, LookupConstraint lookupConstraint, ErrorLevel errorLevel){... |
737 |
4
|
if ((ErrorLevel.WARN == errorLevel || ErrorLevel.ERROR == errorLevel) && lookupConstraint != null){ |
738 |
4
|
for(CommonLookupParam param:lookupConstraint.getParams()){ |
739 |
8
|
if(param.getFieldPath()!=null && !param.getFieldPath().isEmpty()){ |
740 |
4
|
String crossFieldPath = param.getFieldPath(); |
741 |
4
|
String crossFieldMessageId = param.getFieldPathMessageId() == null ? |
742 |
|
"validation.lookup.cause":param.getFieldPathMessageId(); |
743 |
4
|
addCrossFieldWarning(valResults, crossFieldPath, getMessage(crossFieldMessageId), errorLevel); |
744 |
|
} |
745 |
|
} |
746 |
|
} |
747 |
|
} |
748 |
|
|
|
|
| 76.9% |
Uncovered Elements: 3 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
749 |
7
|
protected void addCrossFieldWarning(List<ValidationResultInfo> valResults, String crossFieldPath, String message, ErrorLevel errorLevel){... |
750 |
|
|
751 |
7
|
boolean warnAlreadyExists = false; |
752 |
7
|
for (ValidationResultInfo vr:valResults){ |
753 |
13
|
if (vr.getElement().equals(crossFieldPath) && vr.getMessage().equals(message)){ |
754 |
0
|
warnAlreadyExists = true; |
755 |
|
} |
756 |
|
} |
757 |
|
|
758 |
|
|
759 |
7
|
if (!warnAlreadyExists){ |
760 |
7
|
ValidationResultInfo val = new ValidationResultInfo(crossFieldPath, null); |
761 |
7
|
val.setMessage(message); |
762 |
7
|
val.setLevel(errorLevel); |
763 |
7
|
valResults.add(val); |
764 |
|
} |
765 |
|
} |
766 |
|
|
|
|
| 25% |
Uncovered Elements: 6 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
767 |
65
|
protected void validateBoolean(Object value, Constraint constraint, String element, List<ValidationResultInfo> results) {... |
768 |
65
|
if (!(value instanceof Boolean)) { |
769 |
0
|
try { |
770 |
0
|
Boolean.valueOf(value.toString()); |
771 |
|
} catch (Exception e) { |
772 |
0
|
ValidationResultInfo val = new ValidationResultInfo(element, value); |
773 |
0
|
val.setError(getMessage("validation.mustBeBoolean")); |
774 |
0
|
results.add(val); |
775 |
|
} |
776 |
|
} |
777 |
|
} |
778 |
|
|
|
|
| 43.6% |
Uncovered Elements: 22 (39) |
Complexity: 13 |
Complexity Density: 0.62 |
|
779 |
1
|
protected void validateDouble(Object value, Constraint constraint, String element, List<ValidationResultInfo> results) {... |
780 |
1
|
Double v = null; |
781 |
|
|
782 |
1
|
ValidationResultInfo val = new ValidationResultInfo(element, value); |
783 |
|
|
784 |
1
|
if (value instanceof Number) { |
785 |
1
|
v = ((Number) value).doubleValue(); |
786 |
|
} else { |
787 |
0
|
try { |
788 |
0
|
v = Double.valueOf(value.toString()); |
789 |
|
} catch (Exception e) { |
790 |
0
|
val.setError(getMessage("validation.mustBeDouble")); |
791 |
|
} |
792 |
|
} |
793 |
|
|
794 |
1
|
if (val.isOk()) { |
795 |
1
|
Double maxValue = ValidatorUtils.getDouble(constraint.getInclusiveMax()); |
796 |
1
|
Double minValue = ValidatorUtils.getDouble(constraint.getExclusiveMin()); |
797 |
|
|
798 |
1
|
if (maxValue != null && minValue != null) { |
799 |
|
|
800 |
1
|
if (v > maxValue || v < minValue) { |
801 |
1
|
val.setError(MessageUtils.interpolate(getMessage("validation.outOfRange"), toMap(constraint))); |
802 |
|
} |
803 |
0
|
} else if (maxValue != null) { |
804 |
0
|
if (v > maxValue) { |
805 |
0
|
val.setError(MessageUtils.interpolate(getMessage("validation.maxValueFailed"), toMap(constraint))); |
806 |
|
} |
807 |
0
|
} else if (minValue != null) { |
808 |
0
|
if (v < minValue) { |
809 |
0
|
val.setError(MessageUtils.interpolate(getMessage("validation.minValueFailed"), toMap(constraint))); |
810 |
|
} |
811 |
|
} |
812 |
|
} |
813 |
|
|
814 |
1
|
if (!val.isOk()) { |
815 |
1
|
results.add(val); |
816 |
|
} |
817 |
|
} |
818 |
|
|
|
|
| 0% |
Uncovered Elements: 39 (39) |
Complexity: 13 |
Complexity Density: 0.62 |
|
819 |
0
|
protected void validateFloat(Object value, Constraint constraint, String element, List<ValidationResultInfo> results) {... |
820 |
0
|
Float v = null; |
821 |
|
|
822 |
0
|
ValidationResultInfo val = new ValidationResultInfo(element, value); |
823 |
0
|
if (value instanceof Number) { |
824 |
0
|
v = ((Number) value).floatValue(); |
825 |
|
} else { |
826 |
0
|
try { |
827 |
0
|
v = Float.valueOf(value.toString()); |
828 |
|
} catch (Exception e) { |
829 |
0
|
val.setError(getMessage("validation.mustBeFloat")); |
830 |
|
} |
831 |
|
} |
832 |
|
|
833 |
0
|
if (val.isOk()) { |
834 |
0
|
Float maxValue = ValidatorUtils.getFloat(constraint.getInclusiveMax()); |
835 |
0
|
Float minValue = ValidatorUtils.getFloat(constraint.getExclusiveMin()); |
836 |
|
|
837 |
0
|
if (maxValue != null && minValue != null) { |
838 |
|
|
839 |
0
|
if (v > maxValue || v < minValue) { |
840 |
0
|
val.setError(MessageUtils.interpolate(getMessage("validation.outOfRange"), toMap(constraint))); |
841 |
|
} |
842 |
0
|
} else if (maxValue != null) { |
843 |
0
|
if (v > maxValue) { |
844 |
0
|
val.setError(MessageUtils.interpolate(getMessage("validation.maxValueFailed"), toMap(constraint))); |
845 |
|
} |
846 |
0
|
} else if (minValue != null) { |
847 |
0
|
if (v < minValue) { |
848 |
0
|
val.setError(MessageUtils.interpolate(getMessage("validation.minValueFailed"), toMap(constraint))); |
849 |
|
} |
850 |
|
} |
851 |
|
} |
852 |
|
|
853 |
0
|
if (!val.isOk()) { |
854 |
0
|
results.add(val); |
855 |
|
} |
856 |
|
} |
857 |
|
|
|
|
| 43.6% |
Uncovered Elements: 22 (39) |
Complexity: 13 |
Complexity Density: 0.62 |
|
858 |
31
|
protected void validateLong(Object value, Constraint constraint, String element, List<ValidationResultInfo> results) {... |
859 |
31
|
Long v = null; |
860 |
|
|
861 |
31
|
ValidationResultInfo val = new ValidationResultInfo(element, value); |
862 |
31
|
if (value instanceof Number) { |
863 |
31
|
v = ((Number) value).longValue(); |
864 |
|
} else { |
865 |
0
|
try { |
866 |
0
|
v = Long.valueOf(value.toString()); |
867 |
|
} catch (Exception e) { |
868 |
0
|
val.setError(getMessage("validation.mustBeLong")); |
869 |
|
} |
870 |
|
} |
871 |
|
|
872 |
31
|
if (val.isOk()) { |
873 |
31
|
Long maxValue = ValidatorUtils.getLong(constraint.getInclusiveMax()); |
874 |
31
|
Long minValue = ValidatorUtils.getLong(constraint.getExclusiveMin()); |
875 |
|
|
876 |
31
|
if (maxValue != null && minValue != null) { |
877 |
|
|
878 |
0
|
if (v > maxValue || v < minValue) { |
879 |
0
|
val.setError(MessageUtils.interpolate(getMessage("validation.outOfRange"), toMap(constraint))); |
880 |
|
} |
881 |
31
|
} else if (maxValue != null) { |
882 |
0
|
if (v > maxValue) { |
883 |
0
|
val.setError(MessageUtils.interpolate(getMessage("validation.maxValueFailed"), toMap(constraint))); |
884 |
|
} |
885 |
31
|
} else if (minValue != null) { |
886 |
0
|
if (v < minValue) { |
887 |
0
|
val.setError(MessageUtils.interpolate(getMessage("validation.minValueFailed"), toMap(constraint))); |
888 |
|
} |
889 |
|
} |
890 |
|
} |
891 |
|
|
892 |
31
|
if (!val.isOk()) { |
893 |
0
|
results.add(val); |
894 |
|
} |
895 |
|
|
896 |
|
} |
897 |
|
|
|
|
| 43.6% |
Uncovered Elements: 22 (39) |
Complexity: 13 |
Complexity Density: 0.62 |
|
898 |
47
|
protected void validateInteger(Object value, Constraint constraint, String element, List<ValidationResultInfo> results) {... |
899 |
47
|
Integer v = null; |
900 |
|
|
901 |
47
|
ValidationResultInfo val = new ValidationResultInfo(element, value); |
902 |
|
|
903 |
47
|
if (value instanceof Number) { |
904 |
47
|
v = ((Number) value).intValue(); |
905 |
|
} else { |
906 |
0
|
try { |
907 |
0
|
v = Integer.valueOf(value.toString()); |
908 |
|
} catch (Exception e) { |
909 |
0
|
val.setError(getMessage("validation.mustBeInteger")); |
910 |
|
} |
911 |
|
} |
912 |
|
|
913 |
47
|
if (val.isOk()) { |
914 |
47
|
Integer maxValue = ValidatorUtils.getInteger(constraint.getInclusiveMax()); |
915 |
47
|
Integer minValue = ValidatorUtils.getInteger(constraint.getExclusiveMin()); |
916 |
|
|
917 |
47
|
if (maxValue != null && minValue != null) { |
918 |
|
|
919 |
0
|
if (v > maxValue || v < minValue) { |
920 |
0
|
val.setError(MessageUtils.interpolate(getMessage("validation.outOfRange"), toMap(constraint))); |
921 |
|
} |
922 |
47
|
} else if (maxValue != null) { |
923 |
0
|
if (v > maxValue) { |
924 |
0
|
val.setError(MessageUtils.interpolate(getMessage("validation.maxValueFailed"), toMap(constraint))); |
925 |
|
} |
926 |
47
|
} else if (minValue != null) { |
927 |
0
|
if (v < minValue) { |
928 |
0
|
val.setError(MessageUtils.interpolate(getMessage("validation.minValueFailed"), toMap(constraint))); |
929 |
|
} |
930 |
|
} |
931 |
|
} |
932 |
|
|
933 |
47
|
if (!val.isOk()) { |
934 |
0
|
results.add(val); |
935 |
|
} |
936 |
|
} |
937 |
|
|
|
|
| 61.5% |
Uncovered Elements: 15 (39) |
Complexity: 13 |
Complexity Density: 0.62 |
|
938 |
515
|
protected void validateDate(Object value, Constraint constraint, String element, List<ValidationResultInfo> results, DateParser dateParser) {... |
939 |
515
|
ValidationResultInfo val = new ValidationResultInfo(element, value); |
940 |
|
|
941 |
515
|
Date v = null; |
942 |
|
|
943 |
515
|
if (value instanceof Date) { |
944 |
515
|
v = (Date) value; |
945 |
|
} else { |
946 |
0
|
try { |
947 |
0
|
v = dateParser.parseDate(value.toString()); |
948 |
|
} catch (Exception e) { |
949 |
0
|
val.setError(getMessage("validation.mustBeDate")); |
950 |
|
} |
951 |
|
} |
952 |
|
|
953 |
515
|
if (val.isOk()) { |
954 |
515
|
Date maxValue = ValidatorUtils.getDate(constraint.getInclusiveMax(), dateParser); |
955 |
515
|
Date minValue = ValidatorUtils.getDate(constraint.getExclusiveMin(), dateParser); |
956 |
|
|
957 |
515
|
if (maxValue != null && minValue != null) { |
958 |
|
|
959 |
0
|
if (v.getTime() > maxValue.getTime() || v.getTime() < minValue.getTime()) { |
960 |
0
|
val.setError(MessageUtils.interpolate(getMessage("validation.outOfRange"), toMap(constraint))); |
961 |
|
} |
962 |
515
|
} else if (maxValue != null) { |
963 |
0
|
if (v.getTime() > maxValue.getTime()) { |
964 |
0
|
val.setError(MessageUtils.interpolate(getMessage("validation.maxValueFailed"), toMap(constraint))); |
965 |
|
} |
966 |
515
|
} else if (minValue != null) { |
967 |
7
|
if (v.getTime() < minValue.getTime()) { |
968 |
1
|
val.setError(MessageUtils.interpolate(getMessage("validation.minValueFailed"), toMap(constraint))); |
969 |
|
} |
970 |
|
} |
971 |
|
} |
972 |
|
|
973 |
515
|
if (!val.isOk()) { |
974 |
1
|
results.add(val); |
975 |
|
} |
976 |
|
} |
977 |
|
|
|
|
| 90.6% |
Uncovered Elements: 3 (32) |
Complexity: 13 |
Complexity Density: 0.81 |
|
978 |
2458
|
protected void validateString(Object value, Constraint constraint, String element, List<ValidationResultInfo> results) {... |
979 |
|
|
980 |
2458
|
if (value == null) { |
981 |
0
|
value = ""; |
982 |
|
} |
983 |
2458
|
String s = value.toString().trim(); |
984 |
|
|
985 |
2458
|
ValidationResultInfo val = new ValidationResultInfo(element, value); |
986 |
|
|
987 |
2458
|
Integer maxLength = tryParse(constraint.getMaxLength()); |
988 |
2458
|
if (maxLength != null && constraint.getMinLength() != null && constraint.getMinLength() > 0) { |
989 |
1554
|
if (s.length() > maxLength || s.length() < constraint.getMinLength()) { |
990 |
13
|
val.setError(MessageUtils.interpolate(getMessage("validation.lengthOutOfRange"), toMap(constraint))); |
991 |
|
} |
992 |
904
|
} else if (maxLength != null) { |
993 |
881
|
if (s.length() > Integer.parseInt(constraint.getMaxLength())) { |
994 |
1
|
val.setError(MessageUtils.interpolate(getMessage("validation.maxLengthFailed"), toMap(constraint))); |
995 |
|
} |
996 |
23
|
} else if (constraint.getMinLength() != null && constraint.getMinLength() > 0) { |
997 |
1
|
if (s.length() < constraint.getMinLength()) { |
998 |
1
|
val.setError(MessageUtils.interpolate(getMessage("validation.minLengthFailed"), toMap(constraint))); |
999 |
|
} |
1000 |
|
} |
1001 |
|
|
1002 |
2458
|
if (!val.isOk()) { |
1003 |
15
|
results.add(val); |
1004 |
|
} |
1005 |
|
} |
1006 |
|
|
|
|
| 50% |
Uncovered Elements: 3 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
1007 |
203
|
protected String getMessage(String messageId) {... |
1008 |
203
|
if (null == messageService) { |
1009 |
203
|
return messageId; |
1010 |
|
} |
1011 |
|
|
1012 |
0
|
Message msg = messageService.getMessage(messageLocaleKey, messageGroupKey, messageId); |
1013 |
|
|
1014 |
0
|
return msg.getValue(); |
1015 |
|
} |
1016 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
1017 |
6690
|
protected String getElementXpath(Stack<String> elementStack) {... |
1018 |
6690
|
StringBuilder xPath = new StringBuilder(); |
1019 |
6690
|
Iterator<String> itr = elementStack.iterator(); |
1020 |
36734
|
while (itr.hasNext()) { |
1021 |
30044
|
xPath.append(itr.next()); |
1022 |
30044
|
if(itr.hasNext()){ |
1023 |
24529
|
xPath.append("/"); |
1024 |
|
} |
1025 |
|
} |
1026 |
|
|
1027 |
6690
|
return xPath.toString(); |
1028 |
|
} |
1029 |
|
|
1030 |
|
|
1031 |
|
|
1032 |
|
|
|
|
| 78.6% |
Uncovered Elements: 3 (14) |
Complexity: 7 |
Complexity Density: 0.88 |
|
1033 |
643
|
protected boolean hasText(String string) {... |
1034 |
|
|
1035 |
643
|
if (string == null || string.length() < 1) { |
1036 |
188
|
return false; |
1037 |
|
} |
1038 |
455
|
int stringLength = string.length(); |
1039 |
|
|
1040 |
455
|
for (int i = 0; i < stringLength; i++) { |
1041 |
455
|
char currentChar = string.charAt(i); |
1042 |
455
|
if (' ' != currentChar || '\t' != currentChar || '\n' != currentChar) { |
1043 |
455
|
return true; |
1044 |
|
} |
1045 |
|
} |
1046 |
|
|
1047 |
0
|
return false; |
1048 |
|
} |
1049 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
1050 |
19
|
protected Map<String, Object> toMap(Constraint c) {... |
1051 |
19
|
Map<String, Object> result = new HashMap<String, Object>(); |
1052 |
19
|
result.put("minOccurs", c.getMinOccurs()); |
1053 |
19
|
result.put("maxOccurs", c.getMaxOccurs()); |
1054 |
19
|
result.put("minLength", c.getMinLength()); |
1055 |
19
|
result.put("maxLength", c.getMaxLength()); |
1056 |
19
|
result.put("minValue", c.getExclusiveMin()); |
1057 |
19
|
result.put("maxValue", c.getInclusiveMax()); |
1058 |
|
|
1059 |
|
|
1060 |
19
|
return result; |
1061 |
|
} |
1062 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1063 |
0
|
public SearchDispatcher getSearchDispatcher() {... |
1064 |
0
|
return searchDispatcher; |
1065 |
|
} |
1066 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1067 |
12
|
public void setSearchDispatcher(SearchDispatcher searchDispatcher) {... |
1068 |
12
|
this.searchDispatcher = searchDispatcher; |
1069 |
|
} |
1070 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1071 |
0
|
@Override... |
1072 |
|
public List<ValidationResultInfo> validateObject(FieldDefinition field, |
1073 |
|
Object o, ObjectStructureDefinition objStructure,Stack<String> elementStack) { |
1074 |
0
|
return null; |
1075 |
|
} |
1076 |
|
} |