| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.student.common.validator; |
| 17 |
|
|
| 18 |
|
import java.util.Collection; |
| 19 |
|
import java.util.Date; |
| 20 |
|
|
| 21 |
|
import org.kuali.student.core.dictionary.dto.DataType; |
| 22 |
|
import org.kuali.student.core.dictionary.dto.FieldDefinition; |
| 23 |
|
import org.kuali.student.core.dictionary.dto.ObjectStructureDefinition; |
| 24 |
|
|
|
|
|
| 23.3% |
Uncovered Elements: 171 (223) |
Complexity: 69 |
Complexity Density: 0.55 |
|
| 25 |
|
public class ValidatorUtils { |
| 26 |
|
|
|
|
|
| 11.2% |
Uncovered Elements: 71 (80) |
Complexity: 25 |
Complexity Density: 0.52 |
|
| 27 |
9
|
public static boolean compareValues(Object value1, Object value2,... |
| 28 |
|
DataType dataType, String operator, boolean isCaseSensitive, DateParser dateParser) { |
| 29 |
|
|
| 30 |
9
|
boolean result = false; |
| 31 |
9
|
Integer compareResult = null; |
| 32 |
9
|
if("has_value".equalsIgnoreCase(operator)){ |
| 33 |
0
|
if(value1==null){ |
| 34 |
0
|
return "false".equals(value2.toString().toLowerCase()); |
| 35 |
|
} |
| 36 |
0
|
if(value1 instanceof Collection && ((Collection<?>) value1).isEmpty()){ |
| 37 |
0
|
return "false".equals(value2.toString().toLowerCase()); |
| 38 |
|
} |
| 39 |
0
|
return "true".equals(value2.toString().toLowerCase()); |
| 40 |
|
} |
| 41 |
|
|
| 42 |
9
|
if (null != dataType) { |
| 43 |
0
|
if (DataType.STRING.equals(dataType)) { |
| 44 |
0
|
String v1 = getString(value1); |
| 45 |
0
|
String v2 = getString(value2); |
| 46 |
|
|
| 47 |
0
|
if(!isCaseSensitive) { |
| 48 |
0
|
v1 = v1.toUpperCase(); |
| 49 |
0
|
v2 = v2.toUpperCase(); |
| 50 |
|
} |
| 51 |
|
|
| 52 |
0
|
compareResult = v1.compareTo(v2); |
| 53 |
0
|
} else if (DataType.INTEGER.equals(dataType)) { |
| 54 |
0
|
Integer v1 = getInteger(value1); |
| 55 |
0
|
Integer v2 = getInteger(value2); |
| 56 |
0
|
compareResult = v1.compareTo(v2); |
| 57 |
0
|
} else if (DataType.LONG.equals(dataType)) { |
| 58 |
0
|
Long v1 = getLong(value1); |
| 59 |
0
|
Long v2 = getLong(value2); |
| 60 |
0
|
compareResult = v1.compareTo(v2); |
| 61 |
0
|
} else if (DataType.DOUBLE.equals(dataType)) { |
| 62 |
0
|
Double v1 = getDouble(value1); |
| 63 |
0
|
Double v2 = getDouble(value2); |
| 64 |
0
|
compareResult = v1.compareTo(v2); |
| 65 |
0
|
} else if (DataType.FLOAT.equals(dataType)) { |
| 66 |
0
|
Float v1 = getFloat(value1); |
| 67 |
0
|
Float v2 = getFloat(value2); |
| 68 |
0
|
compareResult = v1.compareTo(v2); |
| 69 |
0
|
} else if (DataType.BOOLEAN.equals(dataType)) { |
| 70 |
0
|
Boolean v1 = getBoolean(value1); |
| 71 |
0
|
Boolean v2 = getBoolean(value2); |
| 72 |
0
|
compareResult = v1.compareTo(v2); |
| 73 |
0
|
} else if (DataType.DATE.equals(dataType)) { |
| 74 |
0
|
Date v1 = getDate(value1, dateParser); |
| 75 |
0
|
Date v2 = getDate(value2, dateParser); |
| 76 |
0
|
compareResult = v1.compareTo(v2); |
| 77 |
|
} |
| 78 |
|
} |
| 79 |
|
|
| 80 |
9
|
if (null != compareResult) { |
| 81 |
0
|
if (("equals".equalsIgnoreCase(operator) |
| 82 |
|
|| "greater_than_equal".equalsIgnoreCase(operator) || "less_than_equal" |
| 83 |
|
.equalsIgnoreCase(operator)) |
| 84 |
|
&& 0 == compareResult) { |
| 85 |
0
|
result = true; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
0
|
if (("not_equal".equalsIgnoreCase (operator) |
| 89 |
|
|| "greater_than".equalsIgnoreCase(operator)) && compareResult >= 1) { |
| 90 |
0
|
result = true; |
| 91 |
|
} |
| 92 |
|
|
| 93 |
0
|
if (("not_equal".equalsIgnoreCase (operator) |
| 94 |
|
|| "less_than".equalsIgnoreCase(operator)) && compareResult <= -1) { |
| 95 |
0
|
result = true; |
| 96 |
|
} |
| 97 |
|
} |
| 98 |
|
|
| 99 |
9
|
return result; |
| 100 |
|
} |
| 101 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0.55 |
|
| 102 |
0
|
public static Integer getInteger(Object o) {... |
| 103 |
0
|
Integer result = null; |
| 104 |
0
|
if (o instanceof Integer) |
| 105 |
0
|
return (Integer) o; |
| 106 |
0
|
if (o == null) |
| 107 |
0
|
return null; |
| 108 |
0
|
if (o instanceof Number) |
| 109 |
0
|
return ((Number) o).intValue(); |
| 110 |
0
|
String s = o.toString(); |
| 111 |
0
|
if (s != null && s.trim().length() > 0) { |
| 112 |
0
|
result = Integer.valueOf(s.trim()); |
| 113 |
|
} |
| 114 |
0
|
return result; |
| 115 |
|
} |
| 116 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0.55 |
|
| 117 |
0
|
public static Long getLong(Object o) {... |
| 118 |
0
|
Long result = null; |
| 119 |
0
|
if (o instanceof Long) |
| 120 |
0
|
return (Long) o; |
| 121 |
0
|
if (o == null) |
| 122 |
0
|
return null; |
| 123 |
0
|
if (o instanceof Number) |
| 124 |
0
|
return ((Number) o).longValue(); |
| 125 |
0
|
String s = o.toString(); |
| 126 |
0
|
if (s != null && s.trim().length() > 0) { |
| 127 |
0
|
result = Long.valueOf(s.trim()); |
| 128 |
|
} |
| 129 |
0
|
return result; |
| 130 |
|
} |
| 131 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0.55 |
|
| 132 |
0
|
public static Float getFloat(Object o) {... |
| 133 |
0
|
Float result = null; |
| 134 |
0
|
if (o instanceof Float) |
| 135 |
0
|
return (Float) o; |
| 136 |
0
|
if (o == null) |
| 137 |
0
|
return null; |
| 138 |
0
|
if (o instanceof Number) |
| 139 |
0
|
return ((Number) o).floatValue(); |
| 140 |
0
|
String s = o.toString(); |
| 141 |
0
|
if (s != null && s.trim().length() > 0) { |
| 142 |
0
|
result = Float.valueOf(s.trim()); |
| 143 |
|
} |
| 144 |
0
|
return result; |
| 145 |
|
} |
| 146 |
|
|
|
|
|
| 63.2% |
Uncovered Elements: 7 (19) |
Complexity: 6 |
Complexity Density: 0.55 |
|
| 147 |
2
|
public static Double getDouble(Object o) {... |
| 148 |
2
|
Double result = null; |
| 149 |
2
|
if (o instanceof Double) |
| 150 |
0
|
return (Double) o; |
| 151 |
2
|
if (o == null) |
| 152 |
0
|
return null; |
| 153 |
2
|
if (o instanceof Number) |
| 154 |
0
|
return ((Number) o).doubleValue(); |
| 155 |
2
|
String s = o.toString(); |
| 156 |
2
|
if (s != null && s.trim().length() > 0) { |
| 157 |
2
|
result = Double.valueOf(s.trim()); |
| 158 |
|
} |
| 159 |
2
|
return result; |
| 160 |
|
} |
| 161 |
|
|
|
|
|
| 80% |
Uncovered Elements: 3 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
| 162 |
10
|
public static Date getDate(Object o, DateParser dateParser) {... |
| 163 |
10
|
Date result = null; |
| 164 |
10
|
if (o instanceof Date) |
| 165 |
0
|
return (Date) o; |
| 166 |
10
|
if (o == null) |
| 167 |
5
|
return null; |
| 168 |
5
|
String s = o.toString(); |
| 169 |
5
|
if (s != null && s.trim().length() > 0) { |
| 170 |
5
|
result = dateParser.parseDate(s.trim()); |
| 171 |
|
} |
| 172 |
5
|
return result; |
| 173 |
|
} |
| 174 |
|
|
|
|
|
| 33.3% |
Uncovered Elements: 6 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 175 |
15
|
public static String getString(Object o) {... |
| 176 |
15
|
if (o instanceof String) |
| 177 |
15
|
return (String) o; |
| 178 |
0
|
if (o == null) |
| 179 |
0
|
return null; |
| 180 |
0
|
return o.toString(); |
| 181 |
|
} |
| 182 |
|
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
| 183 |
0
|
public static Boolean getBoolean(Object o) {... |
| 184 |
0
|
Boolean result = null; |
| 185 |
0
|
if (o instanceof Boolean) |
| 186 |
0
|
return (Boolean) o; |
| 187 |
0
|
if (o == null) |
| 188 |
0
|
return null; |
| 189 |
0
|
String s = o.toString(); |
| 190 |
0
|
if (s != null && s.trim().length() > 0) { |
| 191 |
0
|
result = Boolean.parseBoolean(s.trim()); |
| 192 |
|
} |
| 193 |
0
|
return result; |
| 194 |
|
} |
| 195 |
|
|
| 196 |
|
|
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 200 |
|
|
| 201 |
|
|
| 202 |
|
|
| 203 |
|
|
| 204 |
|
|
| 205 |
|
@param |
| 206 |
|
@param |
| 207 |
|
@param |
| 208 |
|
@param |
| 209 |
|
@return |
| 210 |
|
|
|
|
|
| 53.3% |
Uncovered Elements: 7 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 211 |
13
|
public static FieldDefinition getField(String key, ObjectStructureDefinition objStructure) {... |
| 212 |
13
|
String[] lookupPathTokens = getPathTokens(key); |
| 213 |
26
|
for(int i = 0; i < lookupPathTokens.length; i++) { |
| 214 |
13
|
for (FieldDefinition f : objStructure.getAttributes()) { |
| 215 |
58
|
if (f.getName().equals(lookupPathTokens[i])) { |
| 216 |
0
|
if(i==lookupPathTokens.length-1){ |
| 217 |
0
|
return f; |
| 218 |
|
} |
| 219 |
|
else{ |
| 220 |
0
|
objStructure = f.getDataObjectStructure(); |
| 221 |
0
|
break; |
| 222 |
|
} |
| 223 |
|
|
| 224 |
|
} |
| 225 |
|
} |
| 226 |
|
} |
| 227 |
13
|
return null; |
| 228 |
|
} |
| 229 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
| 230 |
13
|
private static String[] getPathTokens(String fieldPath) {... |
| 231 |
13
|
return (fieldPath != null && fieldPath.contains(".") ? fieldPath.split("\\.") : new String[]{fieldPath}); |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
} |
| 235 |
|
|