| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.student.contract.model.validation; |
| 17 |
|
|
| 18 |
|
import org.kuali.student.contract.model.Constraint; |
| 19 |
|
import org.kuali.student.contract.model.DictionaryModel; |
| 20 |
|
import org.kuali.student.contract.model.Field; |
| 21 |
|
import org.kuali.student.contract.model.XmlType; |
| 22 |
|
import org.kuali.student.contract.model.util.ModelFinder; |
| 23 |
|
|
| 24 |
|
import java.util.Collection; |
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
@author |
| 29 |
|
|
|
|
|
| 0% |
Uncovered Elements: 56 (56) |
Complexity: 15 |
Complexity Density: 0.48 |
|
| 30 |
|
public class FieldValidator implements ModelValidator { |
| 31 |
|
|
| 32 |
|
private Field field; |
| 33 |
|
private DictionaryModel model; |
| 34 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 35 |
0
|
public FieldValidator(Field field, DictionaryModel sheet) {... |
| 36 |
0
|
this.field = field; |
| 37 |
0
|
this.model = sheet; |
| 38 |
|
} |
| 39 |
|
private Collection errors; |
| 40 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 41 |
0
|
@Override... |
| 42 |
|
public Collection<String> validate() { |
| 43 |
0
|
ConstraintValidator cv = |
| 44 |
|
new ConstraintValidator(field.getInlineConstraint()); |
| 45 |
0
|
errors = cv.validate(); |
| 46 |
0
|
if (field.getPrimitive().equalsIgnoreCase(XmlType.COMPLEX)) { |
| 47 |
0
|
validateComplexConstraint(field.getInlineConstraint()); |
| 48 |
0
|
for (String id : field.getConstraintIds()) { |
| 49 |
0
|
Constraint cons = findConstraint(id); |
| 50 |
0
|
if (cons != null) { |
| 51 |
0
|
validateComplexConstraint(cons); |
| 52 |
|
} |
| 53 |
|
} |
| 54 |
|
} |
| 55 |
0
|
return errors; |
| 56 |
|
} |
| 57 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 58 |
0
|
private Constraint findConstraint(String id) {... |
| 59 |
0
|
Constraint cons = new ModelFinder(model).findConstraint(id); |
| 60 |
0
|
if (cons != null) { |
| 61 |
0
|
return cons; |
| 62 |
|
} |
| 63 |
0
|
addError("Field constraint id, " + id |
| 64 |
|
+ " is not defined in the bank of constraints"); |
| 65 |
0
|
return null; |
| 66 |
|
} |
| 67 |
|
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 7 |
Complexity Density: 0.58 |
|
| 68 |
0
|
private void validateComplexConstraint(Constraint cons) {... |
| 69 |
0
|
if (!cons.getMinLength().equals("")) { |
| 70 |
0
|
addError("A minLength is not allowed on a complex field"); |
| 71 |
|
} |
| 72 |
0
|
if (!cons.getMaxLength().equals("")) { |
| 73 |
0
|
addError("A maxLength is not allowed on a complex field"); |
| 74 |
|
} |
| 75 |
0
|
if (!cons.getMinValue().equals("")) { |
| 76 |
0
|
addError("A minValue is not allowed on a complex field"); |
| 77 |
|
} |
| 78 |
0
|
if (!cons.getMaxValue().equals("")) { |
| 79 |
0
|
addError("A maxValue is not allowed on a complex field"); |
| 80 |
|
} |
| 81 |
0
|
if (!cons.getValidChars().equals("")) { |
| 82 |
0
|
addError("A validChars is not allowed on a complex field"); |
| 83 |
|
} |
| 84 |
0
|
if (!cons.getLookup().equals("")) { |
| 85 |
0
|
addError("A lookup value is not allowed on a complex field"); |
| 86 |
|
} |
| 87 |
|
} |
| 88 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 89 |
0
|
private void addError(String msg) {... |
| 90 |
0
|
String error = "Error in field " + field.getId() + ": " + msg; |
| 91 |
0
|
if (!errors.contains(error)) { |
| 92 |
0
|
errors.add(error); |
| 93 |
|
} |
| 94 |
|
} |
| 95 |
|
} |