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
31   95   15   6.2
20   67   0.48   5
5     3  
1    
 
  FieldValidator       Line # 30 31 0% 15 56 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.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    * This validates a single field definition
28    * @author nwright
29    */
 
30    public class FieldValidator implements ModelValidator {
31   
32    private Field field;
33    private DictionaryModel model;
34   
 
35  0 toggle public FieldValidator(Field field, DictionaryModel sheet) {
36  0 this.field = field;
37  0 this.model = sheet;
38    }
39    private Collection errors;
40   
 
41  0 toggle @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   
 
58  0 toggle 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   
 
68  0 toggle 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   
 
89  0 toggle 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    }