1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
package org.kuali.student.contract.model.util; |
6 |
|
|
7 |
|
import java.util.List; |
8 |
|
|
9 |
|
import org.kuali.student.contract.exception.DictionaryExecutionException; |
10 |
|
import org.kuali.student.contract.model.Dictionary; |
11 |
|
import org.kuali.student.contract.model.DictionaryModel; |
12 |
|
import org.kuali.student.contract.model.Field; |
13 |
|
import org.kuali.student.contract.model.XmlType; |
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
@author |
18 |
|
|
|
|
| 0% |
Uncovered Elements: 70 (70) |
Complexity: 18 |
Complexity Density: 0.47 |
|
19 |
|
public class DictionaryParentSetter |
20 |
|
{ |
21 |
|
|
22 |
|
private DictionaryModel model; |
23 |
|
private ModelFinder finder; |
24 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
25 |
0
|
public DictionaryParentSetter (DictionaryModel model)... |
26 |
|
{ |
27 |
0
|
this.model = model; |
28 |
0
|
this.finder = new ModelFinder (model); |
29 |
|
} |
30 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
31 |
0
|
public void set ()... |
32 |
|
{ |
33 |
0
|
for (int i = 1; i < model.getDictionary ().size (); i ++) |
34 |
|
{ |
35 |
0
|
Dictionary child = model.getDictionary ().get (i); |
36 |
0
|
Dictionary parent = calcParent (i, child); |
37 |
0
|
child.setParent (parent); |
38 |
|
} |
39 |
|
} |
40 |
|
|
|
|
| 0% |
Uncovered Elements: 53 (53) |
Complexity: 13 |
Complexity Density: 0.45 |
|
41 |
0
|
private Dictionary calcParent (int index, Dictionary child)... |
42 |
|
{ |
43 |
|
|
44 |
|
|
45 |
0
|
if (index == 0) |
46 |
|
{ |
47 |
0
|
return null; |
48 |
|
} |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
0
|
XmlType xmlType = finder.findXmlType (child.getXmlObject ()); |
53 |
0
|
if (xmlType == null) |
54 |
|
{ |
55 |
0
|
throw new DictionaryExecutionException ("child.getXmlObject ()=" + child.getXmlObject ()); |
56 |
|
} |
57 |
0
|
if (xmlType.hasOwnCreateUpdate ()) |
58 |
|
{ |
59 |
0
|
List<Field> fields = finder.findFields (child.getXmlObject ()); |
60 |
0
|
if (fields.get (0).getShortName ().equalsIgnoreCase (child.getShortName ())) |
61 |
|
{ |
62 |
0
|
return null; |
63 |
|
} |
64 |
|
} |
65 |
0
|
Dictionary prev = model.getDictionary ().get (index - 1); |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
0
|
if (prev.getXmlObject ().equalsIgnoreCase (child.getXmlObject ())) |
71 |
|
{ |
72 |
0
|
return prev.getParent (); |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
0
|
Field prevField = finder.findField (prev); |
77 |
0
|
if (prevField == null) |
78 |
|
{ |
79 |
0
|
throw new DictionaryExecutionException |
80 |
|
("Could not find field associated with dictionary entry with id =" + prev.getId ()); |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
0
|
if (calcType (prevField.getXmlType ()).equalsIgnoreCase (child.getXmlObject ())) |
85 |
|
{ |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
0
|
for (int i = index - 2; i > -1; i --) |
94 |
|
{ |
95 |
0
|
Dictionary prev2 = model.getDictionary ().get (i); |
96 |
0
|
if (prev2.getXmlObject ().equalsIgnoreCase (prev.getXmlObject ())) |
97 |
|
{ |
98 |
0
|
if (prev2.getShortName ().equalsIgnoreCase (prev.getShortName ())) |
99 |
|
{ |
100 |
0
|
prev = prev2; |
101 |
0
|
continue; |
102 |
|
} |
103 |
|
} |
104 |
0
|
break; |
105 |
|
} |
106 |
0
|
return prev; |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
0
|
for (int i = index - 1; i > -1; i --) |
122 |
|
{ |
123 |
0
|
Dictionary dict = model.getDictionary ().get (i); |
124 |
0
|
if (dict.getXmlObject ().equalsIgnoreCase (child.getXmlObject ())) |
125 |
|
{ |
126 |
0
|
return dict.getParent (); |
127 |
|
} |
128 |
|
} |
129 |
0
|
throw new DictionaryExecutionException ("dictionary entry " + child.getId () |
130 |
|
+ " could not calculate the parent"); |
131 |
|
} |
132 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
133 |
0
|
private String calcType (String type)... |
134 |
|
{ |
135 |
0
|
if (type.endsWith ("List")) |
136 |
|
{ |
137 |
0
|
type = type.substring (0, type.length () - "List".length ()); |
138 |
|
} |
139 |
|
|
140 |
0
|
return type; |
141 |
|
} |
142 |
|
|
143 |
|
} |