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.Dictionary; |
20 |
|
import org.kuali.student.contract.model.DictionaryModel; |
21 |
|
import org.kuali.student.contract.model.Field; |
22 |
|
import org.kuali.student.contract.model.XmlType; |
23 |
|
import org.kuali.student.contract.model.util.ModelFinder; |
24 |
|
|
25 |
|
import java.util.ArrayList; |
26 |
|
import java.util.Collection; |
27 |
|
import java.util.HashSet; |
28 |
|
import java.util.List; |
29 |
|
import java.util.Set; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
@author |
34 |
|
|
|
|
| 0% |
Uncovered Elements: 61 (61) |
Complexity: 15 |
Complexity Density: 0.38 |
|
35 |
|
public class DictionaryModelValidator implements ModelValidator { |
36 |
|
|
37 |
|
private DictionaryModel model; |
38 |
|
private ModelFinder finder; |
39 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
40 |
0
|
public DictionaryModelValidator(DictionaryModel model) {... |
41 |
0
|
this.model = model; |
42 |
0
|
this.finder = new ModelFinder(model); |
43 |
|
} |
44 |
|
List<String> errors; |
45 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
46 |
0
|
@Override... |
47 |
|
public Collection<String> validate() { |
48 |
0
|
errors = new ArrayList(); |
49 |
0
|
validateConstraints(); |
50 |
0
|
validateFields(); |
51 |
0
|
validateDefaultDictionary(); |
52 |
0
|
validateStateOverrideDictionary(); |
53 |
0
|
checkForDuplicateDictionaryEntries(); |
54 |
0
|
return errors; |
55 |
|
} |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
57 |
0
|
private void validateConstraints() {... |
58 |
0
|
if (model.getConstraints().size() == 0) { |
59 |
0
|
addError("No constraints found"); |
60 |
|
} |
61 |
0
|
for (Constraint cons : model.getConstraints()) { |
62 |
0
|
ConstraintValidator cv = new ConstraintValidator(cons); |
63 |
0
|
errors.addAll(cv.validate()); |
64 |
|
} |
65 |
|
} |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
67 |
0
|
private void validateFields() {... |
68 |
0
|
if (model.getFields().size() == 0) { |
69 |
0
|
addError("No fields found"); |
70 |
|
} |
71 |
0
|
for (Field field : model.getFields()) { |
72 |
0
|
FieldValidator fv = new FieldValidator(field, model); |
73 |
0
|
errors.addAll(fv.validate()); |
74 |
|
} |
75 |
|
} |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
77 |
0
|
private void validateDefaultDictionary() {... |
78 |
0
|
if (finder.findDefaultDictionary().size() == 0) { |
79 |
0
|
addError("No dictionary entries for the (default) state found"); |
80 |
|
} |
81 |
0
|
for (Dictionary dict : finder.findDefaultDictionary()) { |
82 |
0
|
DictionaryValidator dv = new DictionaryValidator(dict, model); |
83 |
0
|
errors.addAll(dv.validate()); |
84 |
|
} |
85 |
|
} |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
87 |
0
|
private void validateStateOverrideDictionary() {... |
88 |
|
|
89 |
0
|
if (finder.findStateOverrideDictionary().size() == 0) { |
90 |
0
|
addError("No dictionary entries that override for the (default) state found"); |
91 |
|
} |
92 |
0
|
for (Dictionary dict : finder.findStateOverrideDictionary()) { |
93 |
0
|
DictionaryValidator dv = new DictionaryValidator(dict, model); |
94 |
0
|
errors.addAll(dv.validate()); |
95 |
|
} |
96 |
|
} |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
98 |
0
|
private void checkForDuplicateDictionaryEntries() {... |
99 |
0
|
Set dups = new HashSet(); |
100 |
0
|
for (Dictionary dict : finder.findDefaultDictionary()) { |
101 |
0
|
if (!dups.add(dict.getId())) { |
102 |
0
|
addError("Duplicate ID's found in dictionary: " + dict.getId()); |
103 |
|
} |
104 |
|
} |
105 |
0
|
for (Dictionary dict : finder.findStateOverrideDictionary()) { |
106 |
0
|
if (!dups.add(dict.getId())) { |
107 |
0
|
addError("Duplicate ID's found in dictionary: " + dict.getId()); |
108 |
|
} |
109 |
|
} |
110 |
|
} |
111 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
112 |
0
|
private void addError(String msg) {... |
113 |
0
|
String error = "Error in overall spreadsheet: " + msg; |
114 |
0
|
if (!errors.contains(error)) { |
115 |
0
|
errors.add(error); |
116 |
|
} |
117 |
|
} |
118 |
|
} |