Clover Coverage Report - Kuali Student 1.2 (Aggregated)
Coverage timestamp: Thu Oct 27 2011 21:38:40 UTC
../../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
115   220   59   12.78
78   165   0.51   9
9     6.56  
1    
 
  ValidatorUtils       Line # 26 115 0% 59 202 0% 0.0
 
No Tests
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15   
16    package org.kuali.student.common.validator.old;
17   
18    import java.util.Date;
19    import java.util.List;
20   
21    import org.kuali.student.common.dictionary.old.dto.Field;
22    import org.kuali.student.common.dictionary.old.dto.ObjectStructure;
23    import org.kuali.student.common.dictionary.old.dto.State;
24    import org.kuali.student.common.dictionary.old.dto.Type;
25   
 
26    public class ValidatorUtils {
27   
 
28  0 toggle public static boolean compareValues(Object value1, Object value2,
29    String dataType, String operator, DateParser dateParser) {
30   
31  0 boolean result = false;
32  0 Integer compareResult = null;
33   
34    // Convert objects into appropriate data types
35  0 if (null != dataType) {
36  0 if ("string".equalsIgnoreCase(dataType)) {
37  0 String v1 = getString(value1);
38  0 String v2 = getString(value2);
39  0 compareResult = v1.compareTo(v2);
40  0 } else if ("integer".equalsIgnoreCase(dataType)) {
41  0 Integer v1 = getInteger(value1);
42  0 Integer v2 = getInteger(value2);
43  0 compareResult = v1.compareTo(v2);
44  0 } else if ("long".equalsIgnoreCase(dataType)) {
45  0 Long v1 = getLong(value1);
46  0 Long v2 = getLong(value2);
47  0 compareResult = v1.compareTo(v2);
48  0 } else if ("double".equalsIgnoreCase(dataType)) {
49  0 Double v1 = getDouble(value1);
50  0 Double v2 = getDouble(value2);
51  0 compareResult = v1.compareTo(v2);
52  0 } else if ("float".equalsIgnoreCase(dataType)) {
53  0 Float v1 = getFloat(value1);
54  0 Float v2 = getFloat(value2);
55  0 compareResult = v1.compareTo(v2);
56  0 } else if ("boolean".equalsIgnoreCase(dataType)) {
57  0 Boolean v1 = getBoolean(value1);
58  0 Boolean v2 = getBoolean(value2);
59  0 compareResult = v1.compareTo(v2);
60  0 } else if ("date".equalsIgnoreCase(dataType)) {
61  0 Date v1 = getDate(value1, dateParser);
62  0 Date v2 = getDate(value2, dateParser);
63  0 compareResult = v1.compareTo(v2);
64    }
65    }
66   
67  0 if (null != compareResult) {
68  0 if (("equals".equalsIgnoreCase(operator)
69    || "greater_than_equal".equalsIgnoreCase(operator) || "less_than_equal"
70    .equalsIgnoreCase(operator))
71    && 0 == compareResult) {
72  0 result = true;
73    }
74   
75  0 if ("greater_than".equalsIgnoreCase(operator) && 1 == compareResult) {
76  0 result = true;
77    }
78   
79  0 if ("less_than".equalsIgnoreCase(operator) && -1 == compareResult) {
80  0 result = true;
81    }
82    }
83   
84  0 return result;
85    }
86   
 
87  0 toggle protected static Integer getInteger(Object o) {
88  0 if (o == null)
89  0 return null;
90   
91  0 Integer result = null;
92  0 if (o instanceof Integer)
93  0 return (Integer) o;
94  0 if (o instanceof Number)
95  0 return ((Number) o).intValue();
96  0 String s = o.toString();
97  0 if (s != null && s.trim().length() > 0) {
98  0 result = Integer.valueOf(s.trim());
99    }
100  0 return result;
101    }
102   
 
103  0 toggle protected static Long getLong(Object o) {
104  0 if (o == null)
105  0 return null;
106   
107  0 Long result = null;
108  0 if (o instanceof Long)
109  0 return (Long) o;
110  0 if (o instanceof Number)
111  0 return ((Number) o).longValue();
112  0 String s = o.toString();
113  0 if (s != null && s.trim().length() > 0) {
114  0 result = Long.valueOf(s.trim());
115    }
116  0 return result;
117    }
118   
 
119  0 toggle protected static Float getFloat(Object o) {
120  0 if (o == null)
121  0 return null;
122   
123  0 Float result = null;
124  0 if (o instanceof Float)
125  0 return (Float) o;
126  0 if (o instanceof Number)
127  0 return ((Number) o).floatValue();
128  0 String s = o.toString();
129  0 if (s != null && s.trim().length() > 0) {
130  0 result = Float.valueOf(s.trim());
131    }
132  0 return result;
133    }
134   
 
135  0 toggle protected static Double getDouble(Object o) {
136  0 if (o == null)
137  0 return null;
138   
139  0 Double result = null;
140  0 if (o instanceof Double)
141  0 return (Double) o;
142  0 if (o instanceof Number)
143  0 return ((Number) o).doubleValue();
144  0 String s = o.toString();
145  0 if (s != null && s.trim().length() > 0) {
146  0 result = Double.valueOf(s.trim());
147    }
148  0 return result;
149    }
150   
 
151  0 toggle protected static Date getDate(Object o, DateParser dateParser) {
152  0 if (o == null)
153  0 return null;
154   
155  0 Date result = null;
156  0 if (o instanceof Date)
157  0 return (Date) o;
158  0 String s = o.toString();
159  0 if (s != null && s.trim().length() > 0) {
160  0 result = dateParser.parseDate(s.trim());
161    }
162  0 return result;
163    }
164   
 
165  0 toggle protected static String getString(Object o) {
166  0 if (o == null)
167  0 return null;
168   
169  0 if (o instanceof String)
170  0 return (String) o;
171  0 return o.toString();
172    }
173   
 
174  0 toggle private static Boolean getBoolean(Object o) {
175  0 if (o == null)
176  0 return null;
177   
178  0 Boolean result = null;
179  0 if (o instanceof Boolean)
180  0 return (Boolean) o;
181  0 String s = o.toString();
182  0 if (s != null && s.trim().length() > 0) {
183  0 result = Boolean.parseBoolean(s.trim());
184    }
185  0 return result;
186    }
187   
188    /**
189    * Traverses the dictionary ObjectStructure to find the field with the match
190    * key, type and state
191    *
192    * @param key
193    * @param type
194    * @param state
195    * @param objStructure
196    * @return
197    */
 
198  0 toggle protected static Field getField(String key, ObjectStructure objStructure,
199    String type, String state) {
200  0 List<Type> typeList = objStructure.getType();
201   
202  0 for (Type t : typeList) {
203  0 if (t.getKey().equalsIgnoreCase(type)) {
204  0 for (State s : t.getState()) {
205  0 if (s.getKey().equalsIgnoreCase(state)) {
206  0 for (Field f : s.getField()) {
207  0 if (f.getKey().equals(key)) {
208  0 return f;
209    }
210    }
211    }
212    }
213    }
214    }
215   
216  0 return null;
217    }
218   
219    }
220