1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common.assembly.util; |
17 |
|
|
18 |
|
import java.util.ArrayList; |
19 |
|
import java.util.List; |
20 |
|
|
21 |
|
import org.kuali.student.common.assembly.data.Data; |
22 |
|
import org.kuali.student.common.assembly.data.Metadata; |
23 |
|
import org.kuali.student.common.assembly.data.QueryPath; |
24 |
|
import org.kuali.student.common.assembly.data.Data.DataType; |
25 |
|
import org.kuali.student.common.assembly.data.Data.Key; |
26 |
|
import org.kuali.student.common.assembly.helper.PropertyEnum; |
27 |
|
import org.kuali.student.common.assembly.helper.RuntimeDataHelper; |
28 |
|
|
|
|
| 0% |
Uncovered Elements: 167 (167) |
Complexity: 48 |
Complexity Density: 0.48 |
|
29 |
|
public class AssemblerUtils { |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
30 |
|
public enum VersionProperties implements PropertyEnum { |
31 |
|
TYPENAME("typeName"), ID("id"), VERSION_INDICATOR("versionIndicator"); |
32 |
|
|
33 |
|
private final String key; |
34 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
35 |
0
|
private VersionProperties(final String key) {... |
36 |
0
|
this.key = key; |
37 |
|
} |
38 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
39 |
0
|
@Override... |
40 |
|
public String getKey() { |
41 |
0
|
return this.key; |
42 |
|
} |
43 |
|
} |
44 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
45 |
0
|
public static String getVersionIndicator(Data data) {... |
46 |
0
|
String result = null; |
47 |
0
|
Data versions = getVersions(data); |
48 |
0
|
if (versions == null) { |
49 |
0
|
return null; |
50 |
|
} |
51 |
0
|
if (versions.size() > 0) { |
52 |
0
|
Data v = versions.get(0); |
53 |
0
|
if (v != null) { |
54 |
0
|
result = v.get(VersionProperties.VERSION_INDICATOR.getKey()); |
55 |
|
} |
56 |
|
} |
57 |
0
|
return result; |
58 |
|
} |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
0
|
public static String getVersionIndicator(Data data, String typeName) {... |
61 |
0
|
return getVersionIndicator(data, typeName, null); |
62 |
|
} |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
64 |
0
|
public static String getVersionIndicator(Data data, String typeName, String id) {... |
65 |
0
|
Data version = getVersionData(data, typeName, id); |
66 |
0
|
if (version == null) { |
67 |
0
|
return null; |
68 |
|
} else { |
69 |
0
|
return version.get(VersionProperties.VERSION_INDICATOR.getKey()); |
70 |
|
} |
71 |
|
} |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.5 |
|
73 |
0
|
public static Data getVersionData(Data data, String typeName, String id) {... |
74 |
0
|
Data result = null; |
75 |
0
|
Data versions = getVersions(data); |
76 |
0
|
if (versions == null) { |
77 |
0
|
return null; |
78 |
|
} |
79 |
0
|
for (Data.Property p : versions) { |
80 |
0
|
Data v = p.getValue(); |
81 |
0
|
if (typeName.equals((String) v.get(VersionProperties.TYPENAME.getKey())) && (id == null || id.equals((String) v.get(VersionProperties.ID.getKey())))) { |
82 |
0
|
result = v; |
83 |
0
|
break; |
84 |
|
} |
85 |
|
} |
86 |
0
|
return result; |
87 |
|
|
88 |
|
} |
89 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
90 |
0
|
public static Data getVersions(Data data) {... |
91 |
0
|
Data result = null; |
92 |
|
|
93 |
0
|
if (data != null) { |
94 |
|
|
95 |
0
|
Data runtime = data.get("_runtimeData"); |
96 |
0
|
if (runtime != null) { |
97 |
0
|
result = runtime.get(RuntimeDataHelper.Properties.VERSIONS.getKey()); |
98 |
|
} |
99 |
|
} |
100 |
|
|
101 |
0
|
return result; |
102 |
|
} |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
104 |
0
|
public static void addVersionIndicator(Data data, String typeName, String id, String version) {... |
105 |
0
|
Data existing = getVersionData(data, typeName, id); |
106 |
0
|
if (existing == null) { |
107 |
0
|
Data d = new Data(); |
108 |
0
|
d.set(VersionProperties.TYPENAME.getKey(), typeName); |
109 |
0
|
d.set(VersionProperties.ID.getKey(), id); |
110 |
0
|
d.set(VersionProperties.VERSION_INDICATOR.getKey(), version); |
111 |
0
|
Data versions = getVersions(data); |
112 |
0
|
if (versions == null) { |
113 |
0
|
versions = new Data(); |
114 |
0
|
setVersions(data, versions); |
115 |
|
} |
116 |
0
|
versions.add(d); |
117 |
|
} else { |
118 |
0
|
existing.set(VersionProperties.VERSION_INDICATOR.getKey(), version); |
119 |
|
} |
120 |
|
} |
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
121 |
0
|
public static void setVersions(Data data, Data versions) {... |
122 |
0
|
if (data != null) { |
123 |
|
|
124 |
0
|
Data runtime = data.get("_runtimeData"); |
125 |
0
|
if (runtime == null) { |
126 |
0
|
runtime = new Data(); |
127 |
0
|
data.set("_runtimeData", runtime); |
128 |
|
} |
129 |
0
|
runtime.set(RuntimeDataHelper.Properties.VERSIONS.getKey(), versions); |
130 |
|
} |
131 |
|
} |
132 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
133 |
0
|
public static boolean isCreated(Data data) {... |
134 |
0
|
return isFlagSet(data, RuntimeDataHelper.Properties.CREATED.getKey()); |
135 |
|
} |
136 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
137 |
0
|
public static boolean isDeleted(Data data) {... |
138 |
0
|
return isFlagSet(data, RuntimeDataHelper.Properties.DELETED.getKey()); |
139 |
|
} |
140 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
141 |
0
|
public static boolean isUpdated(Data data) {... |
142 |
0
|
return isFlagSet(data, RuntimeDataHelper.Properties.UPDATED.getKey()); |
143 |
|
} |
144 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
145 |
0
|
public static boolean isModified(Data data) {... |
146 |
0
|
return isCreated(data) || isUpdated(data) || isDeleted(data); |
147 |
|
} |
148 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
149 |
0
|
public static void setCreated(Data data, boolean flag) {... |
150 |
0
|
setFlag(data, RuntimeDataHelper.Properties.CREATED.getKey(), flag); |
151 |
|
} |
152 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
153 |
0
|
public static void setDeleted(Data data, boolean flag) {... |
154 |
0
|
setFlag(data, RuntimeDataHelper.Properties.DELETED.getKey(), flag); |
155 |
|
} |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
0
|
public static void setUpdated(Data data, boolean flag) {... |
158 |
0
|
setFlag(data, RuntimeDataHelper.Properties.UPDATED.getKey(), flag); |
159 |
|
} |
160 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
161 |
0
|
private static void setFlag(Data data, String key, Boolean flag) {... |
162 |
0
|
if (data != null) { |
163 |
0
|
Data runtime = data.get("_runtimeData"); |
164 |
0
|
if (runtime == null) { |
165 |
0
|
runtime = new Data(); |
166 |
0
|
data.set("_runtimeData", runtime); |
167 |
|
} |
168 |
0
|
runtime.set(key, flag); |
169 |
|
} |
170 |
|
} |
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
171 |
0
|
private static boolean isFlagSet(Data data, String key) {... |
172 |
0
|
boolean result = false; |
173 |
|
|
174 |
0
|
if (data != null) { |
175 |
0
|
Data runtime = data.get("_runtimeData"); |
176 |
0
|
if (runtime != null) { |
177 |
0
|
result = runtime.get(key) != null && (Boolean) runtime.get(key); |
178 |
|
} |
179 |
|
} |
180 |
|
|
181 |
0
|
return result; |
182 |
|
} |
183 |
|
|
184 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
185 |
0
|
public static List<QueryPath> findDirtyElements(Data data) {... |
186 |
0
|
List<QueryPath> results = new ArrayList<QueryPath>(); |
187 |
0
|
_findDirtyElements(data, results, new QueryPath()); |
188 |
0
|
return results; |
189 |
|
} |
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 6 |
Complexity Density: 0.35 |
|
190 |
0
|
private static void _findDirtyElements(Data data, List<QueryPath> results, QueryPath currentFrame) {... |
191 |
0
|
if (data == null) { |
192 |
0
|
return; |
193 |
|
} |
194 |
|
|
195 |
0
|
Data flags = getDirtyFlags(data); |
196 |
0
|
if (flags != null && flags.size() > 0) { |
197 |
0
|
for (Data.Property p : flags) { |
198 |
0
|
QueryPath q = new QueryPath(); |
199 |
0
|
q.addAll(currentFrame); |
200 |
0
|
Key key = p.getWrappedKey(); |
201 |
0
|
q.add(key); |
202 |
0
|
results.add(q); |
203 |
|
} |
204 |
|
} |
205 |
|
|
206 |
0
|
for (Data.Property p : data) { |
207 |
0
|
if (p.getValueType().equals(Data.class) && p.getValue() != null) { |
208 |
0
|
QueryPath q = new QueryPath(); |
209 |
0
|
q.addAll(currentFrame); |
210 |
0
|
Key key = p.getWrappedKey(); |
211 |
0
|
q.add(key); |
212 |
|
|
213 |
0
|
_findDirtyElements((Data) p.getValue(), results, q); |
214 |
|
} |
215 |
|
} |
216 |
|
} |
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
217 |
0
|
public static Data getDirtyFlags(Data data) {... |
218 |
0
|
Data result = null; |
219 |
0
|
Data runtime = data.get("_runtimeData"); |
220 |
0
|
if (runtime != null) { |
221 |
0
|
result = runtime.get("dirty"); |
222 |
|
|
223 |
|
} |
224 |
0
|
return result; |
225 |
|
} |
226 |
|
|
227 |
|
|
228 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
229 |
0
|
public static Metadata get(Metadata metadata, QueryPath frame) {... |
230 |
0
|
if(frame.size() == 1) { |
231 |
0
|
return metadata.getProperties().get(frame.get(0).get()); |
232 |
|
} else { |
233 |
0
|
if (metadata.getDataType() == DataType.LIST){ |
234 |
0
|
return get(metadata, frame, DataType.LIST); |
235 |
|
} |
236 |
|
else{ |
237 |
0
|
return get(metadata.getProperties().get(frame.get(0).get()), frame.subPath(1, frame.size())); |
238 |
|
} |
239 |
|
} |
240 |
|
} |
241 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
242 |
0
|
private static Metadata get(Metadata metadata, QueryPath frame, DataType type){... |
243 |
0
|
if(type == DataType.LIST){ |
244 |
0
|
return get(metadata.getProperties().get(QueryPath.getWildCard()), frame.subPath(1, frame.size())); |
245 |
|
} |
246 |
|
else{ |
247 |
0
|
return get(metadata.getProperties().get(frame.get(0).get()), frame.subPath(1, frame.size())); |
248 |
|
} |
249 |
|
} |
250 |
|
} |