1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.service.impl; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collection; |
20 | |
import java.util.Iterator; |
21 | |
import java.util.List; |
22 | |
|
23 | |
import org.apache.commons.lang.StringUtils; |
24 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
25 | |
import org.kuali.rice.kew.dto.DocumentTypeDTO; |
26 | |
import org.kuali.rice.kew.exception.WorkflowException; |
27 | |
import org.kuali.rice.kns.bo.PersistableBusinessObject; |
28 | |
import org.kuali.rice.kns.datadictionary.DataDictionary; |
29 | |
import org.kuali.rice.kns.datadictionary.MaintainableCollectionDefinition; |
30 | |
import org.kuali.rice.kns.datadictionary.MaintainableFieldDefinition; |
31 | |
import org.kuali.rice.kns.datadictionary.MaintainableItemDefinition; |
32 | |
import org.kuali.rice.kns.datadictionary.MaintainableSectionDefinition; |
33 | |
import org.kuali.rice.kns.datadictionary.MaintenanceDocumentEntry; |
34 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
35 | |
import org.kuali.rice.kns.lookup.valuefinder.ValueFinder; |
36 | |
import org.kuali.rice.kns.maintenance.Maintainable; |
37 | |
import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase; |
38 | |
import org.kuali.rice.kns.rule.BusinessRule; |
39 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
40 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
41 | |
import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService; |
42 | |
import org.kuali.rice.kns.util.GlobalVariables; |
43 | |
import org.kuali.rice.kns.util.ObjectUtils; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | 0 | public class MaintenanceDocumentDictionaryServiceImpl implements MaintenanceDocumentDictionaryService { |
50 | 0 | protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceDocumentDictionaryServiceImpl.class); |
51 | |
|
52 | |
private DataDictionaryService dataDictionaryService; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
protected DocumentTypeDTO getDocumentType(String documentTypeName) { |
61 | |
try { |
62 | 0 | return KNSServiceLocatorWeb.getWorkflowInfoService().getDocType(documentTypeName); |
63 | 0 | } catch (WorkflowException e) { |
64 | 0 | throw new RuntimeException("Caught exception attempting to get document type for doc type name '" + documentTypeName + "'", e); |
65 | |
} |
66 | |
} |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
public String getMaintenanceLabel(String docTypeName) { |
72 | 0 | String label = null; |
73 | |
|
74 | 0 | DocumentTypeDTO docType = getDocumentType(docTypeName); |
75 | 0 | if (docType != null) { |
76 | 0 | label = docType.getDocTypeLabel(); |
77 | |
} |
78 | |
|
79 | 0 | return label; |
80 | |
} |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
public String getMaintenanceDescription(String docTypeName) { |
86 | 0 | String description = null; |
87 | |
|
88 | 0 | DocumentTypeDTO docType = getDocumentType(docTypeName); |
89 | 0 | if (docType != null) { |
90 | 0 | description = docType.getDocTypeDescription(); |
91 | |
} |
92 | |
|
93 | 0 | return description; |
94 | |
} |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
public Class getMaintainableClass(String docTypeName) { |
100 | 0 | Class maintainableClass = null; |
101 | |
|
102 | 0 | MaintenanceDocumentEntry entry = getMaintenanceDocumentEntry(docTypeName); |
103 | 0 | if (entry != null) { |
104 | 0 | LOG.debug("suppling a generic Rule to insure basic validation"); |
105 | 0 | maintainableClass = entry.getMaintainableClass(); |
106 | |
} |
107 | |
|
108 | 0 | return maintainableClass; |
109 | |
} |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public Class getBusinessObjectClass(String docTypeName) { |
115 | 0 | Class businessObjectClass = null; |
116 | |
|
117 | 0 | MaintenanceDocumentEntry entry = getMaintenanceDocumentEntry(docTypeName); |
118 | 0 | if (entry != null) { |
119 | 0 | businessObjectClass = entry.getBusinessObjectClass(); |
120 | |
} |
121 | |
|
122 | 0 | return businessObjectClass; |
123 | |
} |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
public String getDocumentTypeName(Class businessObjectClass) { |
129 | 0 | String documentTypeName = null; |
130 | |
|
131 | 0 | MaintenanceDocumentEntry entry = getMaintenanceDocumentEntry(businessObjectClass); |
132 | 0 | if (entry != null) { |
133 | 0 | documentTypeName = entry.getDocumentTypeName(); |
134 | |
} |
135 | |
|
136 | 0 | return documentTypeName; |
137 | |
} |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
public List getMaintainableSections(String docTypeName) { |
143 | 0 | List sections = null; |
144 | |
|
145 | 0 | MaintenanceDocumentEntry entry = getMaintenanceDocumentEntry(docTypeName); |
146 | 0 | if (entry != null) { |
147 | 0 | sections = entry.getMaintainableSections(); |
148 | |
} |
149 | |
|
150 | 0 | return sections; |
151 | |
} |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
public Class<? extends BusinessRule> getBusinessRulesClass(MaintenanceDocument document) { |
157 | 0 | Maintainable maintainable = document.getOldMaintainableObject(); |
158 | 0 | if (maintainable == null) { |
159 | 0 | throw new IllegalArgumentException("unable to determine documentType for maintenanceDocument with no oldMaintainableObject"); |
160 | |
} |
161 | |
|
162 | 0 | Class<? extends BusinessRule> businessRulesClass = null; |
163 | |
|
164 | 0 | MaintenanceDocumentEntry entry = getMaintenanceDocumentEntry(maintainable.getBoClass()); |
165 | 0 | if (entry != null) { |
166 | 0 | businessRulesClass = entry.getBusinessRulesClass(); |
167 | |
} |
168 | |
|
169 | 0 | if (businessRulesClass == null) { |
170 | 0 | return MaintenanceDocumentRuleBase.class; |
171 | |
} |
172 | |
|
173 | 0 | LOG.info("return class: " + businessRulesClass.getName()); |
174 | |
|
175 | 0 | return businessRulesClass; |
176 | |
} |
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
public Collection getDefaultExistenceChecks(Class businessObjectClass) { |
182 | 0 | return getDefaultExistenceChecks(getDocumentTypeName(businessObjectClass)); |
183 | |
} |
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
public Collection getDefaultExistenceChecks(String docTypeName) { |
189 | |
|
190 | 0 | Collection defaultExistenceChecks = null; |
191 | |
|
192 | 0 | MaintenanceDocumentEntry entry = getMaintenanceDocumentEntry(docTypeName); |
193 | 0 | if (entry != null) { |
194 | 0 | defaultExistenceChecks = entry.getDefaultExistenceChecks(); |
195 | |
} |
196 | |
|
197 | 0 | return defaultExistenceChecks; |
198 | |
} |
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
public List getLockingKeys(String docTypeName) { |
204 | 0 | List lockingKeys = null; |
205 | |
|
206 | 0 | MaintenanceDocumentEntry entry = getMaintenanceDocumentEntry(docTypeName); |
207 | 0 | if (entry != null) { |
208 | 0 | lockingKeys = entry.getLockingKeyFieldNames(); |
209 | |
} |
210 | |
|
211 | 0 | return lockingKeys; |
212 | |
} |
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
public void setDataDictionaryService(DataDictionaryService dataDictionaryService) { |
218 | 0 | this.dataDictionaryService = dataDictionaryService; |
219 | 0 | } |
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
public DataDictionary getDataDictionary() { |
225 | 0 | return this.dataDictionaryService.getDataDictionary(); |
226 | |
} |
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
public MaintenanceDocumentEntry getMaintenanceDocumentEntry(String docTypeName) { |
233 | 0 | if (StringUtils.isBlank(docTypeName)) { |
234 | 0 | throw new IllegalArgumentException("invalid (blank) docTypeName"); |
235 | |
} |
236 | |
|
237 | 0 | MaintenanceDocumentEntry entry = (MaintenanceDocumentEntry)getDataDictionary().getDocumentEntry(docTypeName); |
238 | 0 | return entry; |
239 | |
} |
240 | |
|
241 | |
private MaintenanceDocumentEntry getMaintenanceDocumentEntry(Class businessObjectClass) { |
242 | 0 | if (businessObjectClass == null) { |
243 | 0 | throw new IllegalArgumentException("invalid (blank) businessObjectClass"); |
244 | |
} |
245 | |
|
246 | 0 | MaintenanceDocumentEntry entry = getDataDictionary().getMaintenanceDocumentEntryForBusinessObjectClass(businessObjectClass); |
247 | 0 | return entry; |
248 | |
} |
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
public String getFieldDefaultValue(Class boClass, String fieldName) { |
254 | |
|
255 | |
|
256 | 0 | if (boClass == null) { |
257 | 0 | throw new IllegalArgumentException("The boClass parameter value specified was " + "null. A valid class representing the boClass must " + "be specified."); |
258 | |
} |
259 | |
|
260 | |
|
261 | 0 | return getFieldDefaultValue(getDocumentTypeName(boClass), fieldName); |
262 | |
} |
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
public String getFieldDefaultValue(String docTypeName, String fieldName) { |
268 | |
|
269 | |
|
270 | 0 | if (StringUtils.isBlank(docTypeName)) { |
271 | 0 | throw new IllegalArgumentException("The docTypeName parameter value specified was " + "blank, whitespace, or null. A valid string representing the docTypeName must " + "be specified."); |
272 | |
} |
273 | 0 | if (StringUtils.isBlank(fieldName)) { |
274 | 0 | throw new IllegalArgumentException("The fieldName parameter value specified was " + "blank, whitespace, or null. A valid string representing the fieldName must " + "be specified."); |
275 | |
} |
276 | |
|
277 | |
|
278 | 0 | List sections = getMaintainableSections(docTypeName); |
279 | 0 | for (Iterator sectionIterator = sections.iterator(); sectionIterator.hasNext();) { |
280 | 0 | MaintainableSectionDefinition section = (MaintainableSectionDefinition) sectionIterator.next(); |
281 | |
|
282 | |
|
283 | 0 | Collection fields = section.getMaintainableItems(); |
284 | 0 | String defaultValue = getFieldDefaultValue(fields, fieldName); |
285 | |
|
286 | 0 | if (defaultValue != null) { |
287 | 0 | return defaultValue; |
288 | |
} |
289 | 0 | } |
290 | 0 | return null; |
291 | |
} |
292 | |
|
293 | |
private String getFieldDefaultValue(Collection maintainableFields, String fieldName) { |
294 | 0 | for (Iterator iterator = maintainableFields.iterator(); iterator.hasNext();) { |
295 | 0 | MaintainableItemDefinition item = (MaintainableItemDefinition) iterator.next(); |
296 | |
|
297 | 0 | if (item instanceof MaintainableFieldDefinition) { |
298 | |
|
299 | 0 | MaintainableFieldDefinition field = (MaintainableFieldDefinition) item; |
300 | |
|
301 | |
|
302 | 0 | if (field.getName().endsWith(fieldName)) { |
303 | |
|
304 | |
|
305 | 0 | if (StringUtils.isNotBlank(field.getDefaultValue())) { |
306 | 0 | return field.getDefaultValue(); |
307 | |
} |
308 | |
|
309 | |
|
310 | 0 | else if (field.getDefaultValueFinderClass() != null) { |
311 | |
|
312 | |
|
313 | 0 | ValueFinder valueFinder = null; |
314 | |
try { |
315 | 0 | valueFinder = (ValueFinder) field.getDefaultValueFinderClass().newInstance(); |
316 | |
} |
317 | 0 | catch (Exception e) { |
318 | 0 | LOG.info("Exception obtaining valueFinder for collection field default value", e); |
319 | 0 | valueFinder = null; |
320 | 0 | } |
321 | |
|
322 | |
|
323 | 0 | if (valueFinder != null) { |
324 | 0 | return valueFinder.getValue(); |
325 | |
} |
326 | 0 | } |
327 | |
|
328 | |
else { |
329 | 0 | return null; |
330 | |
} |
331 | |
} |
332 | |
} |
333 | 0 | } |
334 | 0 | return null; |
335 | |
} |
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
public String getCollectionFieldDefaultValue(String docTypeName, String collectionName, String fieldName) { |
342 | |
|
343 | 0 | if (StringUtils.isBlank(docTypeName)) { |
344 | 0 | throw new IllegalArgumentException("The docTypeName parameter value specified was blank, whitespace, or null. A valid string representing the docTypeName must be specified."); |
345 | |
} |
346 | 0 | if (StringUtils.isBlank(fieldName)) { |
347 | 0 | throw new IllegalArgumentException("The fieldName parameter value specified was blank, whitespace, or null. A valid string representing the fieldName must be specified."); |
348 | |
} |
349 | 0 | if (StringUtils.isBlank(collectionName)) { |
350 | 0 | throw new IllegalArgumentException("The collectionName parameter value specified was null. A valid string representing the collectionName must be specified."); |
351 | |
} |
352 | |
|
353 | 0 | MaintainableCollectionDefinition coll = getMaintainableCollection(docTypeName, collectionName); |
354 | 0 | if (coll != null) { |
355 | 0 | Collection collectionFields = coll.getMaintainableFields(); |
356 | 0 | return getFieldDefaultValue(collectionFields, fieldName); |
357 | |
} |
358 | 0 | return null; |
359 | |
} |
360 | |
|
361 | |
|
362 | |
|
363 | |
|
364 | |
public Boolean getAllowsCopy(MaintenanceDocument document) { |
365 | 0 | Boolean allowsCopy = Boolean.FALSE; |
366 | 0 | if (document != null && document.getNewMaintainableObject() != null) { |
367 | 0 | MaintenanceDocumentEntry entry = getMaintenanceDocumentEntry(document.getNewMaintainableObject().getBoClass()); |
368 | 0 | if (entry != null) { |
369 | 0 | allowsCopy = Boolean.valueOf(entry.getAllowsCopy()); |
370 | |
} |
371 | |
} |
372 | |
|
373 | 0 | return allowsCopy; |
374 | |
} |
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
public Boolean getAllowsNewOrCopy(String docTypeName) { |
380 | 0 | Boolean allowsNewOrCopy = Boolean.FALSE; |
381 | |
|
382 | 0 | if (docTypeName != null) { |
383 | 0 | MaintenanceDocumentEntry entry = getMaintenanceDocumentEntry(docTypeName); |
384 | 0 | if (entry != null) { |
385 | 0 | allowsNewOrCopy = Boolean.valueOf(entry.getAllowsNewOrCopy()); |
386 | |
} |
387 | |
} |
388 | |
|
389 | 0 | return allowsNewOrCopy; |
390 | |
} |
391 | |
|
392 | |
public MaintainableItemDefinition getMaintainableItem(String docTypeName, String itemName) { |
393 | |
|
394 | 0 | if (StringUtils.isBlank(docTypeName)) { |
395 | 0 | throw new IllegalArgumentException("The docTypeName parameter value specified was " + "blank, whitespace, or null. A valid string representing the docTypeName must " + "be specified."); |
396 | |
} |
397 | 0 | if (StringUtils.isBlank(itemName)) { |
398 | 0 | throw new IllegalArgumentException("The itemName parameter value specified was " + "blank, whitespace, or null. A valid string representing the itemName must " + "be specified."); |
399 | |
} |
400 | |
|
401 | |
|
402 | 0 | String[] subItems = {}; |
403 | 0 | subItems = StringUtils.split(itemName, "."); |
404 | |
|
405 | |
|
406 | |
|
407 | 0 | List sections = getMaintainableSections(docTypeName); |
408 | 0 | for (Iterator sectionIterator = sections.iterator(); sectionIterator.hasNext();) { |
409 | 0 | MaintainableSectionDefinition section = (MaintainableSectionDefinition) sectionIterator.next(); |
410 | |
|
411 | |
|
412 | 0 | Collection fields = section.getMaintainableItems(); |
413 | 0 | for (Iterator fieldIterator = fields.iterator(); fieldIterator.hasNext();) { |
414 | 0 | MaintainableItemDefinition item = (MaintainableItemDefinition) fieldIterator.next(); |
415 | |
|
416 | 0 | if (item.getName().equals(itemName)) { |
417 | 0 | return item; |
418 | |
} |
419 | |
|
420 | |
|
421 | 0 | if (item instanceof MaintainableCollectionDefinition) { |
422 | 0 | MaintainableCollectionDefinition col = (MaintainableCollectionDefinition) item; |
423 | 0 | if ((subItems.length > 1) && (StringUtils.equals(col.getName(), subItems[0]))) { |
424 | 0 | for (Iterator<MaintainableCollectionDefinition> colIterator = col.getMaintainableCollections().iterator(); colIterator.hasNext();) { |
425 | 0 | MaintainableCollectionDefinition subCol = (MaintainableCollectionDefinition) colIterator.next(); |
426 | 0 | if (subCol.getName().equals(subItems[1])) { |
427 | 0 | return subCol; |
428 | |
} |
429 | 0 | } |
430 | |
} |
431 | |
} |
432 | 0 | } |
433 | 0 | } |
434 | 0 | return null; |
435 | |
} |
436 | |
|
437 | |
public MaintainableFieldDefinition getMaintainableField(String docTypeName, String fieldName) { |
438 | 0 | MaintainableItemDefinition item = getMaintainableItem(docTypeName, fieldName); |
439 | 0 | if (item != null && item instanceof MaintainableFieldDefinition) { |
440 | 0 | return (MaintainableFieldDefinition) item; |
441 | |
} |
442 | 0 | return null; |
443 | |
} |
444 | |
|
445 | |
public MaintainableCollectionDefinition getMaintainableCollection(String docTypeName, String collectionName) { |
446 | |
|
447 | |
|
448 | 0 | if (StringUtils.contains(collectionName, "[")) { |
449 | 0 | collectionName = StringUtils.substringBefore(collectionName, "[") + StringUtils.substringAfter(collectionName, "]"); |
450 | |
} |
451 | 0 | MaintainableItemDefinition item = getMaintainableItem(docTypeName, collectionName); |
452 | 0 | if (item != null && item instanceof MaintainableCollectionDefinition) { |
453 | 0 | return (MaintainableCollectionDefinition) item; |
454 | |
} |
455 | 0 | return null; |
456 | |
} |
457 | |
|
458 | |
public Class getCollectionBusinessObjectClass(String docTypeName, String collectionName) { |
459 | 0 | MaintainableCollectionDefinition coll = getMaintainableCollection(docTypeName, collectionName); |
460 | 0 | if (coll != null) { |
461 | 0 | return coll.getBusinessObjectClass(); |
462 | |
} |
463 | 0 | return null; |
464 | |
} |
465 | |
|
466 | |
public List<MaintainableCollectionDefinition> getMaintainableCollections(String docTypeName) { |
467 | 0 | ArrayList<MaintainableCollectionDefinition> collections = new ArrayList<MaintainableCollectionDefinition>(); |
468 | |
|
469 | |
|
470 | 0 | List sections = getMaintainableSections(docTypeName); |
471 | 0 | for (Iterator sectionIterator = sections.iterator(); sectionIterator.hasNext();) { |
472 | 0 | MaintainableSectionDefinition section = (MaintainableSectionDefinition) sectionIterator.next(); |
473 | |
|
474 | |
|
475 | 0 | Collection fields = section.getMaintainableItems(); |
476 | 0 | for (Iterator fieldIterator = fields.iterator(); fieldIterator.hasNext();) { |
477 | 0 | MaintainableItemDefinition item = (MaintainableItemDefinition) fieldIterator.next(); |
478 | |
|
479 | 0 | if (item instanceof MaintainableCollectionDefinition) { |
480 | 0 | collections.add((MaintainableCollectionDefinition) item); |
481 | |
|
482 | |
} |
483 | 0 | } |
484 | 0 | } |
485 | |
|
486 | 0 | return collections; |
487 | |
} |
488 | |
|
489 | |
public List<MaintainableCollectionDefinition> getMaintainableCollections(MaintainableCollectionDefinition parentCollection) { |
490 | 0 | ArrayList<MaintainableCollectionDefinition> collections = new ArrayList<MaintainableCollectionDefinition>(); |
491 | |
|
492 | |
|
493 | 0 | Collection<MaintainableCollectionDefinition> colls = parentCollection.getMaintainableCollections(); |
494 | 0 | for (MaintainableCollectionDefinition coll : colls) { |
495 | 0 | collections.add(coll); |
496 | 0 | collections.addAll(getMaintainableCollections(coll)); |
497 | |
} |
498 | |
|
499 | 0 | return collections; |
500 | |
} |
501 | |
|
502 | |
|
503 | |
|
504 | |
|
505 | |
public void validateMaintenanceRequiredFields(MaintenanceDocument document) { |
506 | 0 | Maintainable newMaintainableObject = document.getNewMaintainableObject(); |
507 | 0 | if (newMaintainableObject == null) { |
508 | 0 | LOG.error("New maintainable is null"); |
509 | 0 | throw new RuntimeException("New maintainable is null"); |
510 | |
} |
511 | |
|
512 | 0 | List<MaintainableSectionDefinition> maintainableSectionDefinitions = getMaintainableSections(getDocumentTypeName(newMaintainableObject.getBoClass())); |
513 | 0 | for (MaintainableSectionDefinition maintainableSectionDefinition : maintainableSectionDefinitions) { |
514 | 0 | for (MaintainableItemDefinition maintainableItemDefinition : maintainableSectionDefinition.getMaintainableItems()) { |
515 | |
|
516 | 0 | if (maintainableItemDefinition instanceof MaintainableFieldDefinition) { |
517 | 0 | validateMaintainableFieldRequiredFields((MaintainableFieldDefinition) maintainableItemDefinition, newMaintainableObject.getBusinessObject(), maintainableItemDefinition.getName()); |
518 | |
} |
519 | |
|
520 | 0 | else if (maintainableItemDefinition instanceof MaintainableCollectionDefinition) { |
521 | 0 | validateMaintainableCollectionsRequiredFields(newMaintainableObject.getBusinessObject(), (MaintainableCollectionDefinition) maintainableItemDefinition); |
522 | |
} |
523 | |
} |
524 | |
} |
525 | 0 | } |
526 | |
|
527 | |
|
528 | |
|
529 | |
|
530 | |
|
531 | |
|
532 | |
|
533 | |
|
534 | |
private void validateMaintainableFieldRequiredFields(MaintainableFieldDefinition maintainableFieldDefinition, PersistableBusinessObject businessObject, String fieldName) { |
535 | |
|
536 | 0 | if (StringUtils.isBlank(fieldName)) { |
537 | 0 | throw new IllegalArgumentException("invalid fieldName parameter."); |
538 | |
} |
539 | |
|
540 | 0 | if (maintainableFieldDefinition.isRequired() && !maintainableFieldDefinition.isUnconditionallyReadOnly() ) { |
541 | |
try { |
542 | 0 | Object obj = ObjectUtils.getNestedValue(businessObject, fieldName); |
543 | |
|
544 | 0 | if (obj == null || StringUtils.isBlank(obj.toString())) { |
545 | 0 | String attributeLabel = dataDictionaryService.getAttributeLabel(businessObject.getClass(), fieldName); |
546 | 0 | String shortLabel = dataDictionaryService.getAttributeShortLabel(businessObject.getClass(), fieldName); |
547 | 0 | GlobalVariables.getMessageMap().putError(fieldName, RiceKeyConstants.ERROR_REQUIRED, attributeLabel + " (" + shortLabel + ")" ); |
548 | 0 | } else if ( fieldName.endsWith(".principalName") ) { |
549 | |
|
550 | |
|
551 | |
|
552 | |
|
553 | |
|
554 | |
|
555 | 0 | String personProperty = ObjectUtils.getNestedAttributePrefix(fieldName); |
556 | 0 | if ( StringUtils.isNotBlank(personProperty) ) { |
557 | 0 | if ( StringUtils.isBlank( (String)ObjectUtils.getNestedValue(businessObject, personProperty+".entityId") ) ) { |
558 | 0 | String attributeLabel = dataDictionaryService.getAttributeLabel(businessObject.getClass(), fieldName); |
559 | 0 | GlobalVariables.getMessageMap().putError(fieldName, RiceKeyConstants.ERROR_EXISTENCE, attributeLabel ); |
560 | |
} |
561 | |
} |
562 | |
} |
563 | 0 | } catch( Exception ex ) { |
564 | 0 | LOG.error( "unable to read property during doc required field checks", ex ); |
565 | 0 | } |
566 | |
} |
567 | 0 | } |
568 | |
|
569 | |
|
570 | |
private MaintainableCollectionDefinition getCollectionDefinition( String docTypeName, String collectionName ) { |
571 | 0 | String currentCollection = collectionName; |
572 | 0 | String nestedCollections = ""; |
573 | 0 | if (StringUtils.contains(collectionName, "[")) { |
574 | |
|
575 | 0 | currentCollection = StringUtils.substringBefore( collectionName, "[" ); |
576 | 0 | nestedCollections = StringUtils.substringAfter( collectionName, "." ); |
577 | |
} |
578 | |
|
579 | |
|
580 | 0 | List<MaintainableSectionDefinition> maintainableSectionDefinitions = getMaintainableSections( docTypeName ); |
581 | 0 | for (MaintainableSectionDefinition maintainableSectionDefinition : maintainableSectionDefinitions) { |
582 | 0 | for (MaintainableItemDefinition maintainableItemDefinition : maintainableSectionDefinition.getMaintainableItems()) { |
583 | 0 | if (maintainableItemDefinition instanceof MaintainableCollectionDefinition && maintainableItemDefinition.getName().equals( currentCollection ) ) { |
584 | 0 | if ( StringUtils.isBlank( nestedCollections ) ) { |
585 | 0 | return (MaintainableCollectionDefinition) maintainableItemDefinition; |
586 | |
} |
587 | |
|
588 | 0 | return getCollectionDefinition( (MaintainableCollectionDefinition)maintainableItemDefinition, nestedCollections ); |
589 | |
} |
590 | |
} |
591 | |
} |
592 | |
|
593 | 0 | return null; |
594 | |
} |
595 | |
|
596 | |
private MaintainableCollectionDefinition getCollectionDefinition( MaintainableCollectionDefinition collectionDef, String collectionName ) { |
597 | 0 | String currentCollection = collectionName; |
598 | 0 | String nestedCollections = ""; |
599 | 0 | if (StringUtils.contains(collectionName, "[")) { |
600 | |
|
601 | 0 | currentCollection = StringUtils.substringBefore( collectionName, "[" ); |
602 | 0 | nestedCollections = StringUtils.substringAfter( collectionName, "." ); |
603 | |
} |
604 | |
|
605 | |
|
606 | 0 | for (MaintainableCollectionDefinition maintainableCollectionDefinition : collectionDef.getMaintainableCollections()) { |
607 | 0 | if ( maintainableCollectionDefinition.getName().equals( currentCollection ) ) { |
608 | 0 | if ( StringUtils.isBlank( nestedCollections ) ) { |
609 | 0 | return maintainableCollectionDefinition; |
610 | |
} |
611 | 0 | return getCollectionDefinition( maintainableCollectionDefinition, nestedCollections ); |
612 | |
} |
613 | |
} |
614 | |
|
615 | 0 | return null; |
616 | |
} |
617 | |
|
618 | |
public void validateMaintainableCollectionsAddLineRequiredFields(MaintenanceDocument document, PersistableBusinessObject businessObject, String collectionName ) { |
619 | 0 | MaintainableCollectionDefinition def = getCollectionDefinition( getDocumentTypeName(businessObject.getClass()), collectionName ); |
620 | 0 | if ( def != null ) { |
621 | 0 | validateMaintainableCollectionsAddLineRequiredFields( document, businessObject, collectionName, def, 0); |
622 | |
} |
623 | 0 | } |
624 | |
|
625 | |
|
626 | |
|
627 | |
|
628 | |
|
629 | |
|
630 | |
|
631 | |
|
632 | |
|
633 | |
private void validateMaintainableCollectionsAddLineRequiredFields(MaintenanceDocument document, PersistableBusinessObject businessObject, String collectionName, MaintainableCollectionDefinition maintainableCollectionDefinition, int depth) { |
634 | 0 | if ( depth == 0 ) { |
635 | 0 | GlobalVariables.getMessageMap().addToErrorPath("add"); |
636 | |
} |
637 | |
|
638 | 0 | PersistableBusinessObject element = document.getNewMaintainableObject().getNewCollectionLine( collectionName ); |
639 | 0 | GlobalVariables.getMessageMap().addToErrorPath(collectionName); |
640 | 0 | for (MaintainableFieldDefinition maintainableFieldDefinition : maintainableCollectionDefinition.getMaintainableFields()) { |
641 | 0 | final String fieldName = maintainableFieldDefinition.getName(); |
642 | 0 | validateMaintainableFieldRequiredFields(maintainableFieldDefinition, element, fieldName); |
643 | |
|
644 | 0 | } |
645 | |
|
646 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath(collectionName); |
647 | 0 | if ( depth == 0 ) { |
648 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath("add"); |
649 | |
} |
650 | 0 | } |
651 | |
|
652 | |
|
653 | |
|
654 | |
|
655 | |
|
656 | |
|
657 | |
|
658 | |
private void validateMaintainableCollectionsRequiredFields(PersistableBusinessObject businessObject, MaintainableCollectionDefinition maintainableCollectionDefinition) { |
659 | 0 | final String collectionName = maintainableCollectionDefinition.getName(); |
660 | |
|
661 | |
|
662 | 0 | Collection<PersistableBusinessObject> collection = (Collection) ObjectUtils.getPropertyValue(businessObject, collectionName); |
663 | 0 | if (collection != null && !collection.isEmpty()) { |
664 | 0 | for (MaintainableFieldDefinition maintainableFieldDefinition : maintainableCollectionDefinition.getMaintainableFields()) { |
665 | 0 | int pos = 0; |
666 | 0 | final String fieldName = maintainableFieldDefinition.getName(); |
667 | 0 | for (PersistableBusinessObject element : collection) { |
668 | 0 | String parentName = collectionName + "[" + (pos++) + "]"; |
669 | 0 | GlobalVariables.getMessageMap().addToErrorPath(parentName); |
670 | 0 | validateMaintainableFieldRequiredFields(maintainableFieldDefinition, element, fieldName); |
671 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath(parentName); |
672 | 0 | } |
673 | 0 | } |
674 | |
|
675 | |
|
676 | 0 | GlobalVariables.getMessageMap().addToErrorPath(collectionName); |
677 | 0 | for (MaintainableCollectionDefinition nestedMaintainableCollectionDefinition : maintainableCollectionDefinition.getMaintainableCollections()) { |
678 | 0 | for (PersistableBusinessObject element : collection) { |
679 | 0 | validateMaintainableCollectionsRequiredFields(element, nestedMaintainableCollectionDefinition); |
680 | |
} |
681 | |
} |
682 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath(collectionName); |
683 | |
} |
684 | 0 | } |
685 | |
|
686 | |
|
687 | |
|
688 | |
|
689 | |
|
690 | |
|
691 | |
public void validateMaintainableCollectionsForDuplicateEntries(MaintenanceDocument document) { |
692 | 0 | Maintainable newMaintainableObject = document.getNewMaintainableObject(); |
693 | 0 | if (newMaintainableObject == null) { |
694 | 0 | LOG.error("New maintainable is null"); |
695 | 0 | throw new RuntimeException("New maintainable is null"); |
696 | |
} |
697 | |
|
698 | 0 | List<MaintainableSectionDefinition> maintainableSectionDefinitions = getMaintainableSections(getDocumentTypeName(newMaintainableObject.getBoClass())); |
699 | 0 | for (MaintainableSectionDefinition maintainableSectionDefinition : maintainableSectionDefinitions) { |
700 | 0 | for (MaintainableItemDefinition maintainableItemDefinition : maintainableSectionDefinition.getMaintainableItems()) { |
701 | |
|
702 | 0 | if (maintainableItemDefinition instanceof MaintainableCollectionDefinition) { |
703 | 0 | validateMaintainableCollectionsForDuplicateEntries(newMaintainableObject.getBusinessObject(), (MaintainableCollectionDefinition) maintainableItemDefinition); |
704 | |
} |
705 | |
} |
706 | |
} |
707 | 0 | } |
708 | |
|
709 | |
|
710 | |
|
711 | |
|
712 | |
|
713 | |
|
714 | |
|
715 | |
private void validateMaintainableCollectionsForDuplicateEntries(PersistableBusinessObject businessObject, MaintainableCollectionDefinition maintainableCollectionDefinition) { |
716 | 0 | final String collectionName = maintainableCollectionDefinition.getName(); |
717 | |
|
718 | 0 | if (maintainableCollectionDefinition.dissallowDuplicateKey()) { |
719 | 0 | final Class maintainableBusinessObjectClass = businessObject.getClass(); |
720 | |
|
721 | 0 | Collection<PersistableBusinessObject> collection = (Collection) ObjectUtils.getPropertyValue(businessObject, collectionName); |
722 | 0 | if (collection != null && !collection.isEmpty()) { |
723 | 0 | final String propertyName = maintainableCollectionDefinition.getAttributeToHighlightOnDuplicateKey(); |
724 | |
|
725 | 0 | final String label = dataDictionaryService.getCollectionLabel(maintainableBusinessObjectClass, collectionName); |
726 | 0 | final String shortLabel = dataDictionaryService.getCollectionShortLabel(maintainableBusinessObjectClass, collectionName); |
727 | 0 | int pos = 0; |
728 | 0 | for (PersistableBusinessObject element : collection) { |
729 | 0 | String pathToElement = collectionName + "[" + (pos++) + "]"; |
730 | 0 | if (ObjectUtils.countObjectsWithIdentitcalKey(collection, element) > 1) { |
731 | 0 | GlobalVariables.getMessageMap().addToErrorPath(pathToElement); |
732 | 0 | GlobalVariables.getMessageMap().putError(propertyName, RiceKeyConstants.ERROR_DUPLICATE_ELEMENT, new String[] { label, shortLabel }); |
733 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath(pathToElement); |
734 | |
} |
735 | 0 | } |
736 | |
|
737 | |
|
738 | 0 | GlobalVariables.getMessageMap().addToErrorPath(collectionName); |
739 | 0 | for (MaintainableCollectionDefinition nestedMaintainableCollectionDefinition : maintainableCollectionDefinition.getMaintainableCollections()) { |
740 | 0 | for (PersistableBusinessObject element : collection) { |
741 | 0 | validateMaintainableCollectionsForDuplicateEntries(element, nestedMaintainableCollectionDefinition); |
742 | |
} |
743 | |
} |
744 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath(collectionName); |
745 | |
|
746 | |
} |
747 | |
} |
748 | 0 | } |
749 | |
|
750 | |
|
751 | |
|
752 | |
|
753 | |
|
754 | |
|
755 | |
public boolean getPreserveLockingKeysOnCopy(Class businessObjectClass) { |
756 | |
|
757 | 0 | boolean preserveLockingKeysOnCopy = false; |
758 | |
|
759 | 0 | MaintenanceDocumentEntry docEntry = getMaintenanceDocumentEntry(businessObjectClass); |
760 | |
|
761 | 0 | if (docEntry != null) { |
762 | 0 | preserveLockingKeysOnCopy = docEntry.getPreserveLockingKeysOnCopy(); |
763 | |
} |
764 | |
|
765 | 0 | return preserveLockingKeysOnCopy; |
766 | |
} |
767 | |
|
768 | |
|
769 | |
|
770 | |
|
771 | |
|
772 | |
|
773 | |
public Boolean getAllowsRecordDeletion(Class businessObjectClass) { |
774 | |
|
775 | 0 | Boolean allowsRecordDeletion = Boolean.FALSE; |
776 | |
|
777 | 0 | MaintenanceDocumentEntry docEntry = getMaintenanceDocumentEntry(businessObjectClass); |
778 | |
|
779 | 0 | if (docEntry != null) { |
780 | 0 | allowsRecordDeletion = Boolean.valueOf(docEntry.getAllowsRecordDeletion()); |
781 | |
} |
782 | |
|
783 | 0 | return allowsRecordDeletion; |
784 | |
} |
785 | |
|
786 | |
|
787 | |
|
788 | |
|
789 | |
|
790 | |
|
791 | |
public Boolean getAllowsRecordDeletion(MaintenanceDocument document) { |
792 | 0 | return document != null ? this.getAllowsRecordDeletion(document.getNewMaintainableObject().getBoClass()) : Boolean.FALSE; |
793 | |
} |
794 | |
|
795 | |
|
796 | |
|
797 | |
|
798 | |
public Boolean translateCodes(Class businessObjectClass) { |
799 | 0 | boolean translateCodes = false; |
800 | |
|
801 | 0 | MaintenanceDocumentEntry docEntry = getMaintenanceDocumentEntry(businessObjectClass); |
802 | |
|
803 | 0 | if (docEntry != null) { |
804 | 0 | translateCodes = docEntry.isTranslateCodes(); |
805 | |
} |
806 | |
|
807 | 0 | return translateCodes; |
808 | |
} |
809 | |
|
810 | |
} |