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 |
|
private DictionaryModel model; |
22 |
|
private ModelFinder finder; |
23 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
24 |
0
|
public DictionaryParentSetter(DictionaryModel model) {... |
25 |
0
|
this.model = model; |
26 |
0
|
this.finder = new ModelFinder(model); |
27 |
|
} |
28 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
29 |
0
|
public void set() {... |
30 |
0
|
for (int i = 1; i < model.getDictionary().size(); i++) { |
31 |
0
|
Dictionary child = model.getDictionary().get(i); |
32 |
0
|
Dictionary parent = calcParent(i, child); |
33 |
0
|
child.setParent(parent); |
34 |
|
} |
35 |
|
} |
36 |
|
|
|
|
| 0% |
Uncovered Elements: 53 (53) |
Complexity: 13 |
Complexity Density: 0.45 |
|
37 |
0
|
private Dictionary calcParent(int index, Dictionary child) {... |
38 |
|
|
39 |
|
|
40 |
0
|
if (index == 0) { |
41 |
0
|
return null; |
42 |
|
} |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
0
|
XmlType xmlType = finder.findXmlType(child.getXmlObject()); |
47 |
0
|
if (xmlType == null) { |
48 |
0
|
throw new DictionaryExecutionException("child.getXmlObject ()=" + child.getXmlObject()); |
49 |
|
} |
50 |
0
|
if (xmlType.hasOwnCreateUpdate()) { |
51 |
0
|
List<Field> fields = finder.findFields(child.getXmlObject()); |
52 |
0
|
if (fields.get(0).getShortName().equalsIgnoreCase(child.getShortName())) { |
53 |
0
|
return null; |
54 |
|
} |
55 |
|
} |
56 |
0
|
Dictionary prev = model.getDictionary().get(index - 1); |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
0
|
if (prev.getXmlObject().equalsIgnoreCase(child.getXmlObject())) { |
62 |
0
|
return prev.getParent(); |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
0
|
Field prevField = finder.findField(prev); |
67 |
0
|
if (prevField == null) { |
68 |
0
|
throw new DictionaryExecutionException("Could not find field associated with dictionary entry with id =" + prev.getId()); |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
0
|
if (calcType(prevField.getXmlType()).equalsIgnoreCase(child.getXmlObject())) { |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
0
|
for (int i = index - 2; i > -1; i--) { |
81 |
0
|
Dictionary prev2 = model.getDictionary().get(i); |
82 |
0
|
if (prev2.getXmlObject().equalsIgnoreCase(prev.getXmlObject())) { |
83 |
0
|
if (prev2.getShortName().equalsIgnoreCase(prev.getShortName())) { |
84 |
0
|
prev = prev2; |
85 |
0
|
continue; |
86 |
|
} |
87 |
|
} |
88 |
0
|
break; |
89 |
|
} |
90 |
0
|
return prev; |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
0
|
for (int i = index - 1; i > -1; i--) { |
106 |
0
|
Dictionary dict = model.getDictionary().get(i); |
107 |
0
|
if (dict.getXmlObject().equalsIgnoreCase(child.getXmlObject())) { |
108 |
0
|
return dict.getParent(); |
109 |
|
} |
110 |
|
} |
111 |
0
|
throw new DictionaryExecutionException("dictionary entry " + child.getId() |
112 |
|
+ " could not calculate the parent"); |
113 |
|
} |
114 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
115 |
0
|
private String calcType(String type) {... |
116 |
0
|
if (type.endsWith("List")) { |
117 |
0
|
type = type.substring(0, type.length() - "List".length()); |
118 |
|
} |
119 |
|
|
120 |
0
|
return type; |
121 |
|
} |
122 |
|
} |