Clover Coverage Report - Kuali Student 1.1-SNAPSHOT (Aggregated)
Coverage timestamp: Thu Mar 3 2011 04:02:59 EST
../../../../../img/srcFileCovDistChart0.png 49% of files have more coverage
27   82   8   4.5
4   60   0.3   6
6     1.33  
1    
 
  SampCustomValidator       Line # 22 27 0% 8 37 0% 0.0
 
No Tests
 
1    package org.kuali.student.common.validator;
2   
3    import java.util.ArrayList;
4    import java.util.HashMap;
5    import java.util.Iterator;
6    import java.util.List;
7    import java.util.Map;
8    import java.util.Stack;
9   
10    import org.kuali.student.common.util.MessageUtils;
11    import org.kuali.student.core.dictionary.dto.Constraint;
12    import org.kuali.student.core.dictionary.dto.FieldDefinition;
13    import org.kuali.student.core.dictionary.dto.ObjectStructureDefinition;
14    import org.kuali.student.core.validation.dto.ValidationResultInfo;
15   
16    /**
17    * This is a sample Validator used for customized validation. Inject this validator into ValidatorFactory.
18    *
19    * @author Neerav Agrawal
20    *
21    */
 
22    public class SampCustomValidator implements Validator {
23   
24    private ObjectStructureDefinition objStructure;
25   
 
26  0 toggle @Override
27    public List<ValidationResultInfo> validateObject(Object o,
28    ObjectStructureDefinition objStructure) {
29  0 return null;
30    }
31   
 
32  0 toggle public ObjectStructureDefinition getObjStructure() {
33  0 return objStructure;
34    }
35   
 
36  0 toggle public void setObjStructure(ObjectStructureDefinition objStructure) {
37  0 this.objStructure = objStructure;
38    }
39   
 
40  0 toggle @Override
41    public List<ValidationResultInfo> validateObject(FieldDefinition field,
42    Object o, ObjectStructureDefinition objStructure,Stack<String> elementStack) {
43  0 List<ValidationResultInfo> results = new ArrayList<ValidationResultInfo>();
44  0 ConstraintDataProvider dataProvider = new BeanConstraintDataProvider();
45  0 dataProvider.initialize(o);
46  0 String xPath= getElementXpath(elementStack) + field.getName() ;
47  0 Object value = dataProvider.getValue(field.getName());
48  0 if(value==null){
49   
50  0 ValidationResultInfo valRes = new ValidationResultInfo(xPath);
51  0 valRes.setError(MessageUtils.interpolate("Validation Error Sample", toMap(field)));
52  0 results.add(valRes);
53    }
54   
55   
56  0 return results;
57    }
58   
 
59  0 toggle private String getElementXpath(Stack<String> elementStack) {
60  0 StringBuilder xPath = new StringBuilder();
61  0 xPath.append("/");
62  0 Iterator<String> itr = elementStack.iterator();
63  0 while (itr.hasNext()) {
64  0 xPath.append(itr.next() + "/");
65    }
66   
67  0 return xPath.toString();
68    }
69   
 
70  0 toggle private Map<String, Object> toMap(Constraint c) {
71  0 Map<String, Object> result = new HashMap<String, Object>();
72  0 result.put("minOccurs", c.getMinOccurs());
73  0 result.put("maxOccurs", c.getMaxOccurs());
74  0 result.put("minLength", c.getMinLength());
75  0 result.put("maxLength", c.getMaxLength());
76  0 result.put("minValue", c.getExclusiveMin());
77  0 result.put("maxValue", c.getInclusiveMax());
78    // result.put("dataType", c.getDataType());
79   
80  0 return result;
81    }
82    }