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