Clover Coverage Report - KS Contract Documentation Generator 0.0.1-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
39   118   15   4.88
14   86   0.38   8
8     1.88  
1    
 
  DictionaryModelValidator       Line # 35 39 0% 15 61 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2009 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.osedu.org/licenses/ECL-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
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    * Validates the entire spreadsheet model
33    * @author nwright
34    */
 
35    public class DictionaryModelValidator implements ModelValidator {
36   
37    private DictionaryModel model;
38    private ModelFinder finder;
39   
 
40  0 toggle public DictionaryModelValidator(DictionaryModel model) {
41  0 this.model = model;
42  0 this.finder = new ModelFinder(model);
43    }
44    List<String> errors;
45   
 
46  0 toggle @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   
 
57  0 toggle 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   
 
67  0 toggle 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   
 
77  0 toggle 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   
 
87  0 toggle 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   
 
98  0 toggle 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   
 
112  0 toggle 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    }