| 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.beans.BeanInfo; |
| 19 |
|
import java.beans.IntrospectionException; |
| 20 |
|
import java.beans.Introspector; |
| 21 |
|
import java.beans.PropertyDescriptor; |
| 22 |
|
import java.util.HashMap; |
| 23 |
|
import java.util.Map; |
| 24 |
|
|
| 25 |
|
import org.apache.log4j.Logger; |
| 26 |
|
|
|
|
|
| 71.4% |
Uncovered Elements: 10 (35) |
Complexity: 12 |
Complexity Density: 0.5 |
|
| 27 |
|
public class BeanConstraintDataProvider implements ConstraintDataProvider { |
| 28 |
|
final static Logger LOG = Logger.getLogger(BeanConstraintDataProvider.class); |
| 29 |
|
|
| 30 |
|
private static final String DYNAMIC_ATTRIBUTE = "attributes"; |
| 31 |
|
|
| 32 |
|
Map<String, Object> dataMap = null; |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 38 |
13
|
public BeanConstraintDataProvider() {... |
| 39 |
|
|
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 43 |
13
|
public String getPath(){... |
| 44 |
13
|
return ""; |
| 45 |
|
} |
| 46 |
|
|
|
|
|
| 76.9% |
Uncovered Elements: 3 (13) |
Complexity: 3 |
Complexity Density: 0.27 |
|
| 47 |
13
|
@SuppressWarnings("unchecked")... |
| 48 |
|
@Override |
| 49 |
|
public void initialize(Object o) { |
| 50 |
|
|
| 51 |
13
|
dataMap = new HashMap<String, Object>(); |
| 52 |
|
|
| 53 |
13
|
Map<String, PropertyDescriptor> beanInfo = getBeanInfo(o.getClass()); |
| 54 |
|
|
| 55 |
13
|
for (String propName : beanInfo.keySet()) { |
| 56 |
|
|
| 57 |
133
|
PropertyDescriptor pd = beanInfo.get(propName); |
| 58 |
133
|
Object value = null; |
| 59 |
133
|
try { |
| 60 |
133
|
value = pd.getReadMethod().invoke(o); |
| 61 |
|
} catch (Exception e) { |
| 62 |
0
|
LOG.warn("Method invokation failed",e); |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
|
| 66 |
133
|
if(DYNAMIC_ATTRIBUTE.equals(propName)) { |
| 67 |
0
|
dataMap.putAll((Map<String, String>)value); |
| 68 |
|
} else { |
| 69 |
133
|
dataMap.put(propName, value); |
| 70 |
|
} |
| 71 |
|
} |
| 72 |
|
} |
| 73 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
| 74 |
0
|
@Override... |
| 75 |
|
public String getObjectId() { |
| 76 |
0
|
return (dataMap.containsKey("id") && null != dataMap.get("id")) ? dataMap.get("id").toString() : null; |
| 77 |
|
} |
| 78 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 79 |
63
|
@Override... |
| 80 |
|
public Object getValue(String fieldKey) { |
| 81 |
63
|
return dataMap.get(fieldKey); |
| 82 |
|
} |
| 83 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 84 |
0
|
@Override... |
| 85 |
|
public Boolean hasField(String fieldKey) { |
| 86 |
0
|
return dataMap.containsKey(fieldKey); |
| 87 |
|
} |
| 88 |
|
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 89 |
13
|
private Map<String, PropertyDescriptor> getBeanInfo(Class<?> clazz) {... |
| 90 |
13
|
Map<String, PropertyDescriptor> properties = new HashMap<String, PropertyDescriptor>(); |
| 91 |
13
|
BeanInfo beanInfo = null; |
| 92 |
13
|
try { |
| 93 |
13
|
beanInfo = Introspector.getBeanInfo(clazz); |
| 94 |
|
} catch (IntrospectionException e) { |
| 95 |
0
|
throw new RuntimeException(e); |
| 96 |
|
} |
| 97 |
13
|
PropertyDescriptor[] propertyDescriptors = beanInfo |
| 98 |
|
.getPropertyDescriptors(); |
| 99 |
13
|
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { |
| 100 |
133
|
properties.put(propertyDescriptor.getName(), propertyDescriptor); |
| 101 |
|
} |
| 102 |
13
|
return properties; |
| 103 |
|
} |
| 104 |
|
} |