1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
package org.kuali.student.core.assembly.dictionary; |
10 | |
|
11 | |
import java.text.DateFormat; |
12 | |
import java.text.ParseException; |
13 | |
import java.text.SimpleDateFormat; |
14 | |
import java.util.ArrayList; |
15 | |
import java.util.HashMap; |
16 | |
import java.util.List; |
17 | |
import java.util.Map; |
18 | |
|
19 | |
import org.apache.log4j.Logger; |
20 | |
import org.kuali.student.core.assembly.data.ConstraintMetadata; |
21 | |
import org.kuali.student.core.assembly.data.Data; |
22 | |
import org.kuali.student.core.assembly.data.LookupMetadata; |
23 | |
import org.kuali.student.core.assembly.data.LookupParamMetadata; |
24 | |
import org.kuali.student.core.assembly.data.Metadata; |
25 | |
import org.kuali.student.core.assembly.data.UILookupConfig; |
26 | |
import org.kuali.student.core.assembly.data.UILookupData; |
27 | |
import org.kuali.student.core.assembly.data.Data.DataType; |
28 | |
import org.kuali.student.core.assembly.data.Data.Value; |
29 | |
import org.kuali.student.core.assembly.data.Metadata.WriteAccess; |
30 | |
import org.kuali.student.core.dictionary.dto.CaseConstraint; |
31 | |
import org.kuali.student.core.dictionary.dto.CommonLookupParam; |
32 | |
import org.kuali.student.core.dictionary.dto.Constraint; |
33 | |
import org.kuali.student.core.dictionary.dto.FieldDefinition; |
34 | |
import org.kuali.student.core.dictionary.dto.ObjectStructureDefinition; |
35 | |
import org.kuali.student.core.dictionary.dto.WhenConstraint; |
36 | |
import org.kuali.student.core.dictionary.service.DictionaryService; |
37 | |
import org.kuali.student.core.dto.DtoConstants.DtoState; |
38 | |
import org.springframework.beans.BeanUtils; |
39 | |
import org.springframework.context.ApplicationContext; |
40 | |
import org.springframework.context.support.ClassPathXmlApplicationContext; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public class MetadataServiceImpl { |
48 | 4 | final Logger LOG = Logger.getLogger(MetadataServiceImpl.class); |
49 | |
|
50 | 4 | private Map<String, Object> metadataRepository = null; |
51 | |
|
52 | |
private Map<String, DictionaryService> dictionaryServiceMap; |
53 | |
private List<UILookupConfig> lookupObjectStructures; |
54 | |
private String uiLookupContext; |
55 | |
|
56 | 30 | private static class RecursionCounter { |
57 | |
public static final int MAX_DEPTH = 4; |
58 | |
|
59 | 15 | private Map<String, Integer> recursions = new HashMap<String, Integer>(); |
60 | |
|
61 | |
public int increment(String objectName) { |
62 | 15 | Integer hits = recursions.get(objectName); |
63 | |
|
64 | 15 | if (hits == null) { |
65 | 15 | hits = new Integer(1); |
66 | |
} else { |
67 | 0 | hits++; |
68 | |
} |
69 | 15 | recursions.put(objectName, hits); |
70 | 15 | return hits; |
71 | |
} |
72 | |
|
73 | |
public int decrement(String objectName) { |
74 | 15 | Integer hits = recursions.get(objectName); |
75 | 15 | if (hits >= 1) { |
76 | 15 | hits--; |
77 | |
} |
78 | |
|
79 | 15 | recursions.put(objectName, hits); |
80 | 15 | return hits; |
81 | |
} |
82 | |
} |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | 4 | public MetadataServiceImpl(DictionaryService... dictionaryServices) { |
90 | 4 | if (dictionaryServices != null) { |
91 | 4 | this.dictionaryServiceMap = new HashMap<String, DictionaryService>(); |
92 | 8 | for (DictionaryService d : dictionaryServices) { |
93 | 4 | List<String> objectTypes = d.getObjectTypes(); |
94 | 4 | for (String objectType : objectTypes) { |
95 | 12 | dictionaryServiceMap.put(objectType, d); |
96 | |
} |
97 | |
} |
98 | |
} |
99 | 4 | } |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
public Metadata getMetadata(String objectKey, String type, String state, String nextState) { |
111 | 15 | if (metadataRepository == null || metadataRepository.get(objectKey) == null) { |
112 | 15 | return getMetadataFromDictionaryService(objectKey, type, state, nextState); |
113 | |
} |
114 | |
|
115 | 0 | return null; |
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
public Metadata getMetadata(String objectKey, String type, String state) { |
127 | 15 | return getMetadata(objectKey, type, state, null); |
128 | |
} |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
public Metadata getMetadata(String objectKey, String state) { |
138 | 1 | return getMetadata(objectKey, null, state); |
139 | |
} |
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
public Metadata getMetadata(String objectKey) { |
149 | 9 | return getMetadata(objectKey, null, null); |
150 | |
} |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
protected Metadata getMetadataFromDictionaryService(String objectKey, String type, String state, String nextState) { |
162 | |
|
163 | 15 | Metadata metadata = new Metadata(); |
164 | |
|
165 | 15 | ObjectStructureDefinition objectStructure = getObjectStructure(objectKey); |
166 | |
|
167 | 15 | metadata.setProperties(getProperties(objectStructure, type, state, nextState, new RecursionCounter())); |
168 | |
|
169 | 15 | metadata.setWriteAccess(WriteAccess.ALWAYS); |
170 | 15 | metadata.setDataType(DataType.DATA); |
171 | 15 | addLookupstoMetadata(objectKey, metadata, type); |
172 | 15 | return metadata; |
173 | |
} |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
private Map<String, Metadata> getProperties(ObjectStructureDefinition objectStructure, String type, String state, String nextState, RecursionCounter counter) { |
184 | 15 | String objectId = objectStructure.getName(); |
185 | 15 | int hits = counter.increment(objectId); |
186 | |
|
187 | 15 | Map<String, Metadata> properties = null; |
188 | |
|
189 | 15 | if (hits < RecursionCounter.MAX_DEPTH) { |
190 | 15 | properties = new HashMap<String, Metadata>(); |
191 | |
|
192 | 15 | List<FieldDefinition> attributes = objectStructure.getAttributes(); |
193 | 15 | for (FieldDefinition fd : attributes) { |
194 | |
|
195 | 74 | Metadata metadata = new Metadata(); |
196 | |
|
197 | |
|
198 | 74 | metadata.setWriteAccess(WriteAccess.ALWAYS); |
199 | 74 | metadata.setDataType(convertDictionaryDataType(fd.getDataType())); |
200 | 74 | metadata.setConstraints(getConstraints(fd, type, state, nextState)); |
201 | 74 | metadata.setCanEdit(!fd.isReadOnly()); |
202 | 74 | metadata.setCanUnmask(!fd.isMask()); |
203 | 74 | metadata.setCanView(!fd.isHide()); |
204 | 74 | metadata.setDynamic(fd.isDynamic()); |
205 | 74 | metadata.setLabelKey(fd.getLabelKey()); |
206 | 74 | metadata.setDefaultValue(convertDefaultValue(metadata.getDataType(), fd.getDefaultValue())); |
207 | |
|
208 | 74 | if (fd.isPartialMask()){ |
209 | 8 | metadata.setPartialMaskFormatter(fd.getPartialMaskFormatter()); |
210 | |
} |
211 | |
|
212 | 74 | if (fd.isMask()){ |
213 | 8 | metadata.setMaskFormatter(fd.getMaskFormatter()); |
214 | |
} |
215 | |
|
216 | |
|
217 | 74 | Map<String, Metadata> nestedProperties = null; |
218 | 74 | if (fd.getDataType() == org.kuali.student.core.dictionary.dto.DataType.COMPLEX && fd.getDataObjectStructure() != null) { |
219 | 0 | nestedProperties = getProperties(fd.getDataObjectStructure(), type, state, nextState, counter); |
220 | |
} |
221 | |
|
222 | |
|
223 | 74 | if (isRepeating(fd)) { |
224 | 0 | Metadata repeatingMetadata = new Metadata(); |
225 | 0 | metadata.setDataType(DataType.LIST); |
226 | |
|
227 | 0 | repeatingMetadata.setWriteAccess(WriteAccess.ALWAYS); |
228 | 0 | repeatingMetadata.setOnChangeRefreshMetadata(false); |
229 | 0 | repeatingMetadata.setDataType(convertDictionaryDataType(fd.getDataType())); |
230 | |
|
231 | 0 | if (nestedProperties != null) { |
232 | 0 | repeatingMetadata.setProperties(nestedProperties); |
233 | |
} |
234 | |
|
235 | 0 | Map<String, Metadata> repeatingProperty = new HashMap<String, Metadata>(); |
236 | 0 | repeatingProperty.put("*", repeatingMetadata); |
237 | 0 | metadata.setProperties(repeatingProperty); |
238 | 0 | } else if (nestedProperties != null) { |
239 | 0 | metadata.setProperties(nestedProperties); |
240 | |
} |
241 | |
|
242 | 74 | properties.put(fd.getName(), metadata); |
243 | |
|
244 | 74 | } |
245 | |
} |
246 | |
|
247 | 15 | counter.decrement(objectId); |
248 | 15 | return properties; |
249 | |
} |
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
protected boolean isRepeating(FieldDefinition fd) { |
258 | 74 | boolean isRepeating = false; |
259 | |
try { |
260 | 74 | int maxOccurs = Integer.parseInt(fd.getMaxOccurs()); |
261 | 21 | isRepeating = maxOccurs > 1; |
262 | 53 | } catch (NumberFormatException nfe) { |
263 | 53 | isRepeating = FieldDefinition.UNBOUNDED.equals(fd.getMaxOccurs()); |
264 | 21 | } |
265 | |
|
266 | 74 | return isRepeating; |
267 | |
} |
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
protected ObjectStructureDefinition getObjectStructure(String objectKey) { |
276 | 15 | DictionaryService dictionaryService = dictionaryServiceMap.get(objectKey); |
277 | |
|
278 | 15 | if (dictionaryService == null) { |
279 | 0 | throw new RuntimeException("Dictionary service not provided for objectKey=[" + objectKey + "]."); |
280 | |
} |
281 | |
|
282 | 15 | return dictionaryService.getObjectStructure(objectKey); |
283 | |
} |
284 | |
|
285 | |
protected List<ConstraintMetadata> getConstraints(FieldDefinition fd, String type, String state, String nextState) { |
286 | 74 | List<ConstraintMetadata> constraints = new ArrayList<ConstraintMetadata>(); |
287 | |
|
288 | 74 | ConstraintMetadata constraintMetadata = new ConstraintMetadata(); |
289 | |
|
290 | 74 | updateConstraintMetadata(constraintMetadata, (Constraint) fd, type, state, nextState); |
291 | 74 | constraints.add(constraintMetadata); |
292 | |
|
293 | 74 | return constraints; |
294 | |
} |
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
protected void updateConstraintMetadata(ConstraintMetadata constraintMetadata, Constraint constraint, String type, String state, String nextState) { |
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | 75 | if (constraint.getMinLength() != null) { |
308 | 50 | constraintMetadata.setMinLength(constraint.getMinLength()); |
309 | |
} |
310 | |
|
311 | |
|
312 | |
try { |
313 | 75 | if (constraint.getMaxLength() != null) { |
314 | 50 | constraintMetadata.setMaxLength(Integer.parseInt(constraint.getMaxLength())); |
315 | |
} |
316 | |
|
317 | 0 | } catch (NumberFormatException nfe) { |
318 | |
|
319 | |
|
320 | 0 | constraintMetadata.setMaxLength(9999); |
321 | 75 | } |
322 | |
|
323 | |
|
324 | 75 | if (constraint.getMinOccurs() != null) { |
325 | 59 | constraintMetadata.setMinOccurs(constraint.getMinOccurs()); |
326 | |
} |
327 | |
|
328 | |
|
329 | 75 | String maxOccurs = constraint.getMaxOccurs(); |
330 | 75 | if (maxOccurs != null) { |
331 | |
try { |
332 | 21 | constraintMetadata.setMaxOccurs(Integer.parseInt(maxOccurs)); |
333 | 21 | if (!FieldDefinition.SINGLE.equals(maxOccurs)) { |
334 | 0 | constraintMetadata.setId("repeating"); |
335 | |
} |
336 | 0 | } catch (NumberFormatException nfe) { |
337 | |
|
338 | 0 | if (FieldDefinition.UNBOUNDED.equals(maxOccurs)) { |
339 | 0 | constraintMetadata.setId("repeating"); |
340 | 0 | constraintMetadata.setMaxOccurs(9999); |
341 | |
} |
342 | 21 | } |
343 | |
} |
344 | |
|
345 | |
|
346 | 75 | if (constraint.getExclusiveMin() != null) { |
347 | 16 | constraintMetadata.setMinValue(constraint.getExclusiveMin()); |
348 | |
} |
349 | |
|
350 | |
|
351 | 75 | if (constraint.getInclusiveMax() != null) { |
352 | 8 | constraintMetadata.setMaxValue(constraint.getInclusiveMax()); |
353 | |
} |
354 | |
|
355 | 75 | if (constraint.getValidChars() != null) { |
356 | 22 | constraintMetadata.setValidChars(constraint.getValidChars().getValue()); |
357 | 22 | constraintMetadata.setValidCharsMessageId(constraint.getValidChars().getLabelKey()); |
358 | |
} |
359 | |
|
360 | |
|
361 | 75 | if (constraint.getCaseConstraint() != null) { |
362 | 15 | processCaseConstraint(constraintMetadata, constraint.getCaseConstraint(), type, state, nextState); |
363 | |
} |
364 | 75 | } |
365 | |
|
366 | |
protected void processCaseConstraint(ConstraintMetadata constraintMetadata, CaseConstraint caseConstraint, String type, String state, String nextState) { |
367 | 15 | String fieldPath = caseConstraint.getFieldPath(); |
368 | 15 | List<WhenConstraint> whenConstraints = caseConstraint.getWhenConstraint(); |
369 | |
|
370 | 15 | fieldPath = (fieldPath != null ? fieldPath.toUpperCase() : fieldPath); |
371 | 15 | if ("STATE".equals(fieldPath)) { |
372 | |
|
373 | |
|
374 | |
|
375 | 8 | state = (state == null ? DtoState.DRAFT.toString():state); |
376 | 8 | nextState = (nextState == null ? DtoState.getNextStateAsString(state):nextState); |
377 | |
|
378 | 8 | if ("EQUALS".equals(caseConstraint.getOperator()) && whenConstraints != null) { |
379 | 8 | for (WhenConstraint whenConstraint : whenConstraints) { |
380 | 8 | List<Object> values = whenConstraint.getValues(); |
381 | 8 | if (values != null) { |
382 | 8 | Constraint constraint = whenConstraint.getConstraint(); |
383 | |
|
384 | |
|
385 | 8 | if (values.contains(nextState)) { |
386 | 7 | if (constraint.getMinOccurs() > 0) { |
387 | 7 | constraintMetadata.setRequiredForNextState(true); |
388 | 7 | constraintMetadata.setNextState(nextState); |
389 | |
} |
390 | |
} |
391 | |
|
392 | |
|
393 | 8 | if (values.contains(state.toUpperCase())) { |
394 | 1 | updateConstraintMetadata(constraintMetadata, constraint, type, state, nextState); |
395 | |
} |
396 | |
} |
397 | 8 | } |
398 | |
} |
399 | 7 | } else if ("TYPE".equals(fieldPath)) { |
400 | |
|
401 | |
|
402 | 0 | if ("EQUALS".equals(caseConstraint.getOperator()) && whenConstraints != null) { |
403 | 0 | for (WhenConstraint whenConstraint : whenConstraints) { |
404 | 0 | List<Object> values = whenConstraint.getValues(); |
405 | 0 | if (values != null && values.contains(type)) { |
406 | 0 | Constraint constraint = whenConstraint.getConstraint(); |
407 | 0 | updateConstraintMetadata(constraintMetadata, constraint, type, state, nextState); |
408 | |
} |
409 | 0 | } |
410 | |
} |
411 | |
} |
412 | 15 | } |
413 | |
|
414 | |
|
415 | |
|
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | |
|
421 | |
protected Value convertDefaultValue(DataType dataType, Object value) { |
422 | 74 | Value v = null; |
423 | 74 | if (value instanceof String) { |
424 | 0 | String s = (String) value; |
425 | 2 | switch (dataType) { |
426 | |
case STRING: |
427 | 0 | v = new Data.StringValue(s); |
428 | 0 | break; |
429 | |
case BOOLEAN: |
430 | 0 | v = new Data.BooleanValue(Boolean.valueOf(s)); |
431 | 0 | break; |
432 | |
case FLOAT: |
433 | 0 | v = new Data.FloatValue(Float.valueOf(s)); |
434 | 0 | break; |
435 | |
case DATE: |
436 | 0 | DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |
437 | |
try { |
438 | 0 | v = new Data.DateValue(format.parse(s)); |
439 | 0 | } catch (ParseException e) { |
440 | 0 | LOG.error("Unable to get default date value from metadata definition"); |
441 | 0 | } |
442 | 0 | break; |
443 | |
case LONG: |
444 | 0 | if (!s.isEmpty()) { |
445 | 0 | v = new Data.LongValue(Long.valueOf(s)); |
446 | |
} |
447 | |
break; |
448 | |
case DOUBLE: |
449 | 0 | v = new Data.DoubleValue(Double.valueOf(s)); |
450 | 0 | break; |
451 | |
case INTEGER: |
452 | 0 | v = new Data.IntegerValue(Integer.valueOf(s)); |
453 | |
break; |
454 | |
} |
455 | 0 | } else { |
456 | 74 | v = convertDefaultValue(value); |
457 | |
} |
458 | |
|
459 | 74 | return v; |
460 | |
} |
461 | |
|
462 | |
protected Value convertDefaultValue(Object value) { |
463 | 74 | Value v = null; |
464 | |
|
465 | 74 | if (value instanceof String) { |
466 | 0 | v = new Data.StringValue((String) value); |
467 | 74 | } else if (value instanceof Boolean) { |
468 | 0 | v = new Data.BooleanValue((Boolean) value); |
469 | 74 | } else if (value instanceof Integer) { |
470 | 0 | v = new Data.IntegerValue((Integer) value); |
471 | 74 | } else if (value instanceof Double) { |
472 | 0 | v = new Data.DoubleValue((Double) value); |
473 | 74 | } else if (value instanceof Long) { |
474 | 0 | v = new Data.LongValue((Long) value); |
475 | 74 | } else if (value instanceof Short) { |
476 | 0 | v = new Data.ShortValue((Short) value); |
477 | 74 | } else if (value instanceof Float) { |
478 | 0 | v = new Data.FloatValue((Float) value); |
479 | |
} |
480 | |
|
481 | 74 | return v; |
482 | |
} |
483 | |
|
484 | |
protected DataType convertDictionaryDataType(org.kuali.student.core.dictionary.dto.DataType dataType) { |
485 | 2 | switch (dataType) { |
486 | |
case STRING: |
487 | 58 | return DataType.STRING; |
488 | |
case BOOLEAN: |
489 | 0 | return DataType.BOOLEAN; |
490 | |
case INTEGER: |
491 | 0 | return DataType.INTEGER; |
492 | |
case FLOAT: |
493 | 0 | return DataType.FLOAT; |
494 | |
case COMPLEX: |
495 | 0 | return DataType.DATA; |
496 | |
case DATE: |
497 | 8 | return DataType.DATE; |
498 | |
case DOUBLE: |
499 | 8 | return DataType.DOUBLE; |
500 | |
case LONG: |
501 | 0 | return DataType.LONG; |
502 | |
} |
503 | |
|
504 | 0 | return null; |
505 | |
} |
506 | |
|
507 | |
public void setUiLookupContext(String uiLookupContext) { |
508 | 2 | this.uiLookupContext = uiLookupContext; |
509 | 2 | init(); |
510 | |
|
511 | 2 | } |
512 | |
|
513 | |
@SuppressWarnings("unchecked") |
514 | |
private void init() { |
515 | 2 | ApplicationContext ac = new ClassPathXmlApplicationContext(uiLookupContext); |
516 | |
|
517 | 2 | Map<String, UILookupConfig> beansOfType = (Map<String, UILookupConfig>) ac.getBeansOfType(UILookupConfig.class); |
518 | 2 | lookupObjectStructures = new ArrayList<UILookupConfig>(); |
519 | 2 | for (UILookupConfig objStr : beansOfType.values()) { |
520 | 4 | lookupObjectStructures.add(objStr); |
521 | |
} |
522 | 2 | System.out.println("UILookup loaded"); |
523 | 2 | } |
524 | |
|
525 | |
private String calcSimpleName(String objectKey) { |
526 | 20 | int lastDot = objectKey.lastIndexOf("."); |
527 | 20 | if (lastDot == -1) { |
528 | 20 | return objectKey; |
529 | |
} |
530 | 0 | return objectKey.substring(lastDot + 1); |
531 | |
|
532 | |
} |
533 | |
|
534 | |
private boolean matchesObjectKey(String objectKey, String path) { |
535 | 20 | String simpleName = calcSimpleName(objectKey); |
536 | 20 | if (path.toLowerCase().startsWith(simpleName.toLowerCase())) { |
537 | |
|
538 | 14 | return true; |
539 | |
} |
540 | |
|
541 | 6 | return false; |
542 | |
} |
543 | |
|
544 | |
private boolean matchesType(String paramType, String lookupType) { |
545 | |
|
546 | 14 | if (paramType == null && lookupType == null) { |
547 | 0 | return true; |
548 | |
} |
549 | |
|
550 | |
|
551 | 14 | if (paramType == null && lookupType != null) { |
552 | 4 | return false; |
553 | |
} |
554 | |
|
555 | |
|
556 | |
|
557 | |
|
558 | |
|
559 | 10 | if (paramType != null && lookupType == null) { |
560 | 0 | return true; |
561 | |
} |
562 | 10 | if (paramType.equalsIgnoreCase(lookupType)) { |
563 | |
|
564 | 5 | return true; |
565 | |
} |
566 | |
|
567 | 5 | return false; |
568 | |
} |
569 | |
|
570 | |
private void addLookupstoMetadata(String objectKey, Metadata metadata, String type) { |
571 | 15 | if (lookupObjectStructures != null) { |
572 | 10 | for (UILookupConfig lookup : lookupObjectStructures) { |
573 | 20 | if (!matchesObjectKey(objectKey, lookup.getPath())) { |
574 | 6 | continue; |
575 | |
} |
576 | 14 | if (!matchesType(type, lookup.getType())) { |
577 | 9 | continue; |
578 | |
} |
579 | |
|
580 | |
|
581 | 5 | Map<String, Metadata> parsedMetadataMap = metadata.getProperties(); |
582 | 5 | Metadata parsedMetadata = null; |
583 | 5 | String parsedMetadataKey = ""; |
584 | 5 | String lookupFieldPath = lookup.getPath(); |
585 | 5 | String[] lookupPathTokens = getPathTokens(lookupFieldPath); |
586 | 10 | for (int i = 1; i < lookupPathTokens.length; i++) { |
587 | 5 | if (parsedMetadataMap == null) { |
588 | 0 | break; |
589 | |
} |
590 | 5 | if (i == lookupPathTokens.length - 1) { |
591 | |
|
592 | 5 | parsedMetadata = parsedMetadataMap.get(lookupPathTokens[i]); |
593 | 5 | parsedMetadataKey = parsedMetadataKey + "." + lookupPathTokens[i]; |
594 | |
} |
595 | 5 | if (parsedMetadataMap.get(lookupPathTokens[i]) != null) { |
596 | 5 | parsedMetadataMap = parsedMetadataMap.get(lookupPathTokens[i]).getProperties(); |
597 | 0 | } else if (parsedMetadataMap.get("*") != null) { |
598 | |
|
599 | 0 | parsedMetadataMap = parsedMetadataMap.get("*").getProperties(); |
600 | 0 | i--; |
601 | |
} |
602 | |
|
603 | |
} |
604 | 5 | if (parsedMetadata != null) { |
605 | |
|
606 | |
|
607 | 5 | UILookupData initialLookup = lookup.getInitialLookup(); |
608 | 5 | if (initialLookup != null) { |
609 | 5 | mapLookupDatatoMeta(initialLookup); |
610 | 5 | parsedMetadata.setInitialLookup(mapLookupDatatoMeta(lookup.getInitialLookup())); |
611 | |
} |
612 | 5 | List<LookupMetadata> additionalLookupMetadata = null; |
613 | 5 | if (lookup.getAdditionalLookups() != null) { |
614 | 0 | additionalLookupMetadata = new ArrayList<LookupMetadata>(); |
615 | 0 | for (UILookupData additionallookup : lookup.getAdditionalLookups()) { |
616 | 0 | additionalLookupMetadata.add(mapLookupDatatoMeta(additionallookup)); |
617 | |
} |
618 | 0 | parsedMetadata.setAdditionalLookups(additionalLookupMetadata); |
619 | |
} |
620 | |
} |
621 | 5 | } |
622 | |
} |
623 | 15 | } |
624 | |
|
625 | |
private LookupMetadata mapLookupDatatoMeta(UILookupData lookupData) { |
626 | 10 | LookupMetadata lookupMetadata = new LookupMetadata(); |
627 | |
List<LookupParamMetadata> paramsMetadata; |
628 | 10 | BeanUtils.copyProperties(lookupData, lookupMetadata, new String[]{"widget", "usage", "widgetOptions", "params"}); |
629 | 10 | if (lookupData.getWidget() != null) { |
630 | 10 | lookupMetadata.setWidget(org.kuali.student.core.assembly.data.LookupMetadata.Widget.valueOf(lookupData.getWidget().toString())); |
631 | |
} |
632 | 10 | if (lookupData.getUsage() != null) { |
633 | 10 | lookupMetadata.setUsage(org.kuali.student.core.assembly.data.LookupMetadata.Usage.valueOf(lookupData.getUsage().toString())); |
634 | |
} |
635 | 10 | if (lookupData.getWidgetOptions () != null) { |
636 | 0 | lookupMetadata.setWidgetOptions (new HashMap ()); |
637 | 0 | for (UILookupData.WidgetOption wo: lookupData.getWidgetOptions ().keySet ()) { |
638 | 0 | String value = lookupData.getWidgetOptions ().get (wo); |
639 | 0 | LookupMetadata.WidgetOption key = LookupMetadata.WidgetOption.valueOf(wo.toString()); |
640 | 0 | lookupMetadata.getWidgetOptions ().put (key, value); |
641 | 0 | } |
642 | |
} |
643 | 10 | if (lookupData.getParams() != null) { |
644 | 10 | paramsMetadata = new ArrayList<LookupParamMetadata>(); |
645 | 10 | for (CommonLookupParam param : lookupData.getParams()) { |
646 | 50 | paramsMetadata.add(mapLookupParamMetadata(param)); |
647 | |
} |
648 | 10 | lookupMetadata.setParams(paramsMetadata); |
649 | |
} |
650 | |
|
651 | 10 | return lookupMetadata; |
652 | |
} |
653 | |
|
654 | |
private LookupParamMetadata mapLookupParamMetadata(CommonLookupParam param) { |
655 | 50 | LookupParamMetadata paramMetadata = new LookupParamMetadata(); |
656 | 50 | BeanUtils.copyProperties(param, paramMetadata, new String[]{"childLookup", "dataType", "writeAccess", "usage", "widget"}); |
657 | 50 | if (param.getChildLookup() != null) { |
658 | 0 | paramMetadata.setChildLookup(mapLookupDatatoMeta((UILookupData) param.getChildLookup())); |
659 | |
} |
660 | 50 | if (param.getDataType() != null) { |
661 | 50 | paramMetadata.setDataType(org.kuali.student.core.assembly.data.Data.DataType.valueOf(param.getDataType().toString())); |
662 | |
} |
663 | 50 | if (param.getWriteAccess() != null) { |
664 | 40 | paramMetadata.setWriteAccess(org.kuali.student.core.assembly.data.Metadata.WriteAccess.valueOf(param.getWriteAccess().toString())); |
665 | |
} |
666 | 50 | if (param.getUsage() != null) { |
667 | 0 | paramMetadata.setUsage(org.kuali.student.core.assembly.data.LookupMetadata.Usage.valueOf(param.getUsage().toString())); |
668 | |
} |
669 | 50 | if (param.getWidget() != null) { |
670 | 0 | paramMetadata.setWidget(org.kuali.student.core.assembly.data.LookupParamMetadata.Widget.valueOf(param.getWidget().toString())); |
671 | |
} |
672 | |
|
673 | 50 | return paramMetadata; |
674 | |
} |
675 | |
|
676 | |
private static String[] getPathTokens(String fieldPath) { |
677 | 5 | return (fieldPath != null && fieldPath.contains(".") ? fieldPath.split("\\.") : new String[]{fieldPath}); |
678 | |
} |
679 | |
} |