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 |
|
|
|
|
| 61.5% |
Uncovered Elements: 10 (26) |
Complexity: 11 |
Complexity Density: 0.69 |
|
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 |
17
|
public BeanConstraintDataProvider() {... |
39 |
|
|
40 |
|
} |
41 |
|
|
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
43 |
17
|
public String getPath(){... |
44 |
17
|
return ""; |
45 |
|
} |
46 |
|
|
|
|
| 71.4% |
Uncovered Elements: 4 (14) |
Complexity: 4 |
Complexity Density: 0.33 |
|
47 |
17
|
@SuppressWarnings("unchecked")... |
48 |
|
@Override |
49 |
|
public void initialize(Object o) { |
50 |
|
|
51 |
17
|
dataMap = new HashMap<String, Object>(); |
52 |
|
|
53 |
17
|
try { |
54 |
17
|
BeanInfo beanInfo = Introspector.getBeanInfo(o.getClass()); |
55 |
|
|
56 |
17
|
for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) { |
57 |
180
|
Object value = null; |
58 |
180
|
try { |
59 |
180
|
value = pd.getReadMethod().invoke(o); |
60 |
|
} catch (Exception e) { |
61 |
0
|
LOG.warn("Method invokation failed",e); |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
180
|
if(DYNAMIC_ATTRIBUTE.equals(pd.getName())) { |
66 |
0
|
dataMap.putAll((Map<String, String>)value); |
67 |
|
} else { |
68 |
180
|
dataMap.put(pd.getName(), value); |
69 |
|
} |
70 |
|
} |
71 |
|
} catch (IntrospectionException e) { |
72 |
0
|
throw new RuntimeException(e); |
73 |
|
} |
74 |
|
} |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
76 |
0
|
@Override... |
77 |
|
public String getObjectId() { |
78 |
0
|
return (dataMap.containsKey("id") && null != dataMap.get("id")) ? dataMap.get("id").toString() : null; |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
99
|
@Override... |
82 |
|
public Object getValue(String fieldKey) { |
83 |
99
|
return dataMap.get(fieldKey); |
84 |
|
} |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
0
|
@Override... |
87 |
|
public Boolean hasField(String fieldKey) { |
88 |
0
|
return dataMap.containsKey(fieldKey); |
89 |
|
} |
90 |
|
|
91 |
|
} |