| 1 |
|
package org.kuali.student.common.dictionary.service.impl; |
| 2 |
|
|
| 3 |
|
import java.util.ArrayList; |
| 4 |
|
import java.util.Arrays; |
| 5 |
|
import java.util.List; |
| 6 |
|
|
| 7 |
|
import org.kuali.student.common.dictionary.dto.FieldDefinition; |
| 8 |
|
import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition; |
| 9 |
|
|
|
|
|
| 95.4% |
Uncovered Elements: 4 (87) |
Complexity: 23 |
Complexity Density: 0.45 |
|
| 10 |
|
public class Dictionary2BeanComparer |
| 11 |
|
{ |
| 12 |
|
|
| 13 |
|
|
| 14 |
|
private String className; |
| 15 |
|
private ObjectStructureDefinition osDict; |
| 16 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 17 |
145
|
public Dictionary2BeanComparer (String className, ObjectStructureDefinition osDict)... |
| 18 |
|
{ |
| 19 |
145
|
this.className = className; |
| 20 |
145
|
this.osDict = osDict; |
| 21 |
|
} |
| 22 |
|
|
| 23 |
|
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 24 |
145
|
public List<String> compare ()... |
| 25 |
|
{ |
| 26 |
145
|
if (className == null) |
| 27 |
|
{ |
| 28 |
0
|
return Arrays.asList (osDict.getName () + " does not have a corresponding java class"); |
| 29 |
|
} |
| 30 |
145
|
Class<?> clazz = null; |
| 31 |
145
|
try |
| 32 |
|
{ |
| 33 |
145
|
clazz = Class.forName (className); |
| 34 |
|
} |
| 35 |
|
catch (ClassNotFoundException ex) |
| 36 |
|
{ |
| 37 |
32
|
return Arrays.asList (className + " does not have a corresponding java class"); |
| 38 |
|
} |
| 39 |
113
|
ObjectStructureDefinition osBean = new Bean2DictionaryConverter (clazz).convert (); |
| 40 |
113
|
return compare (osDict, osBean); |
| 41 |
|
|
| 42 |
|
} |
| 43 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 4 |
Complexity Density: 0.22 |
|
| 44 |
113
|
private List<String> compare (ObjectStructureDefinition osDict,... |
| 45 |
|
ObjectStructureDefinition osBean) |
| 46 |
|
{ |
| 47 |
113
|
List<String> discrepancies = new ArrayList (); |
| 48 |
113
|
compareAddDiscrepancy (discrepancies, "Java class name", osDict.getName (), osBean.getName ()); |
| 49 |
113
|
compareAddDiscrepancy (discrepancies, "Has meta data?", osDict.isHasMetaData (), osBean.isHasMetaData ()); |
| 50 |
113
|
compareAddDiscrepancy (discrepancies, "Business object class", osDict.getBusinessObjectClass (), osBean.getBusinessObjectClass ()); |
| 51 |
113
|
for (FieldDefinition fdDict : osDict.getAttributes ()) |
| 52 |
|
{ |
| 53 |
765
|
FieldDefinition fdBean = findField (fdDict.getName (), osBean); |
| 54 |
765
|
if (fdBean == null) |
| 55 |
|
{ |
| 56 |
34
|
if ( ! fdDict.isDynamic ()) |
| 57 |
|
{ |
| 58 |
8
|
discrepancies.add ("Field " + fdDict.getName () + " does not exist in the corresponding java class"); |
| 59 |
|
} |
| 60 |
34
|
continue; |
| 61 |
|
} |
| 62 |
731
|
compareAddDiscrepancy (discrepancies, fdDict.getName () + " dataType", fdDict.getDataType (), fdBean.getDataType ()); |
| 63 |
731
|
compareAddDiscrepancy (discrepancies, fdDict.getName () + " maxOccurs", fdDict.getMaxOccurs (), fdBean.getMaxOccurs ()); |
| 64 |
|
} |
| 65 |
113
|
for (FieldDefinition fdBean : osBean.getAttributes ()) |
| 66 |
|
{ |
| 67 |
751
|
FieldDefinition fdDict = findField (fdBean.getName (), osDict); |
| 68 |
751
|
if (fdDict == null) |
| 69 |
|
{ |
| 70 |
20
|
discrepancies.add ("Field " + fdBean.getName () + " missing from the dictictionary"); |
| 71 |
20
|
continue; |
| 72 |
|
} |
| 73 |
|
} |
| 74 |
113
|
return discrepancies; |
| 75 |
|
} |
| 76 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 77 |
1516
|
private FieldDefinition findField (String name, ObjectStructureDefinition os)... |
| 78 |
|
{ |
| 79 |
1516
|
for (FieldDefinition fd : os.getAttributes ()) |
| 80 |
|
{ |
| 81 |
13285
|
if (name.equals (fd.getName ())) |
| 82 |
|
{ |
| 83 |
1462
|
return fd; |
| 84 |
|
} |
| 85 |
|
} |
| 86 |
54
|
return null; |
| 87 |
|
} |
| 88 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 89 |
113
|
private void compareAddDiscrepancy (List<String> discrepancies, String field, boolean value1,... |
| 90 |
|
boolean value2) |
| 91 |
|
{ |
| 92 |
113
|
String discrep = compare (field, value1, value2); |
| 93 |
113
|
if (discrep != null) |
| 94 |
|
{ |
| 95 |
1
|
discrepancies.add (discrep); |
| 96 |
|
} |
| 97 |
|
} |
| 98 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 99 |
1688
|
private void compareAddDiscrepancy (List<String> discrepancies, String field, Object value1,... |
| 100 |
|
Object value2) |
| 101 |
|
{ |
| 102 |
1688
|
String discrep = compare (field, value1, value2); |
| 103 |
1688
|
if (discrep != null) |
| 104 |
|
{ |
| 105 |
1
|
discrepancies.add (discrep); |
| 106 |
|
} |
| 107 |
|
} |
| 108 |
|
|
|
|
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 5 |
Complexity Density: 0.71 |
|
| 109 |
113
|
private String compare (String field, boolean value1, boolean value2)... |
| 110 |
|
{ |
| 111 |
113
|
if (value1) |
| 112 |
|
{ |
| 113 |
51
|
if (value2) |
| 114 |
|
{ |
| 115 |
50
|
return null; |
| 116 |
|
} |
| 117 |
|
} |
| 118 |
63
|
if ( ! value1) |
| 119 |
|
{ |
| 120 |
62
|
if ( ! value2) |
| 121 |
|
{ |
| 122 |
62
|
return null; |
| 123 |
|
} |
| 124 |
|
} |
| 125 |
1
|
return field + " inconsistent: dictionary='" + value1 + "', java class='" + value2 + "'"; |
| 126 |
|
} |
| 127 |
|
|
|
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 128 |
1688
|
private String compare (String field, Object value1, Object value2)... |
| 129 |
|
{ |
| 130 |
1688
|
if (value1 == null) |
| 131 |
|
{ |
| 132 |
113
|
if (value2 == null) |
| 133 |
|
{ |
| 134 |
113
|
return null; |
| 135 |
|
} |
| 136 |
|
} |
| 137 |
|
else |
| 138 |
|
{ |
| 139 |
1575
|
if (value1.equals (value2)) |
| 140 |
|
{ |
| 141 |
1574
|
return null; |
| 142 |
|
} |
| 143 |
|
} |
| 144 |
1
|
return field + " inconsistent: dictionary='" + value1 + "'], java class='" + value2 + "'"; |
| 145 |
|
} |
| 146 |
|
} |