1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.web.ui;
17
18 import org.apache.commons.beanutils.PropertyUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.core.api.mo.common.active.Inactivatable;
21 import org.kuali.rice.kns.datadictionary.CollectionDefinitionI;
22 import org.kuali.rice.kns.datadictionary.FieldDefinition;
23 import org.kuali.rice.kns.datadictionary.FieldDefinitionI;
24 import org.kuali.rice.kns.datadictionary.InquiryCollectionDefinition;
25 import org.kuali.rice.kns.datadictionary.InquirySectionDefinition;
26 import org.kuali.rice.kns.datadictionary.InquirySubSectionHeaderDefinition;
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.MaintainableSubSectionHeaderDefinition;
32 import org.kuali.rice.kns.datadictionary.SubSectionHeaderDefinitionI;
33 import org.kuali.rice.kns.document.authorization.FieldRestriction;
34 import org.kuali.rice.kns.inquiry.Inquirable;
35 import org.kuali.rice.kns.inquiry.InquiryRestrictions;
36 import org.kuali.rice.kns.lookup.LookupUtils;
37 import org.kuali.rice.kns.maintenance.Maintainable;
38 import org.kuali.rice.kns.service.BusinessObjectAuthorizationService;
39 import org.kuali.rice.kns.service.KNSServiceLocator;
40 import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService;
41 import org.kuali.rice.kns.util.FieldUtils;
42 import org.kuali.rice.kns.util.KNSConstants;
43 import org.kuali.rice.kns.util.MaintenanceUtils;
44 import org.kuali.rice.kns.util.WebUtils;
45 import org.kuali.rice.krad.bo.BusinessObject;
46 import org.kuali.rice.krad.bo.PersistableBusinessObject;
47 import org.kuali.rice.krad.datadictionary.mask.MaskFormatter;
48 import org.kuali.rice.krad.exception.ClassNotPersistableException;
49 import org.kuali.rice.krad.service.DataDictionaryService;
50 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
51 import org.kuali.rice.krad.util.KRADConstants;
52 import org.kuali.rice.krad.util.ObjectUtils;
53
54 import java.util.ArrayList;
55 import java.util.Collection;
56 import java.util.HashMap;
57 import java.util.HashSet;
58 import java.util.Iterator;
59 import java.util.List;
60 import java.util.Map;
61 import java.util.Set;
62
63 @Deprecated
64 public class SectionBridge {
65 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SectionBridge.class);
66 private static BusinessObjectAuthorizationService businessObjectAuthorizationService;
67 private static BusinessObjectAuthorizationService getBusinessObjectAuthorizationService() {
68 if (businessObjectAuthorizationService == null) {
69 businessObjectAuthorizationService = KNSServiceLocator.getBusinessObjectAuthorizationService();
70 }
71 return businessObjectAuthorizationService;
72 }
73 private static DataDictionaryService dataDictionaryService;
74 private static DataDictionaryService getDataDictionaryService() {
75 if (dataDictionaryService == null) {
76 dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService();
77 }
78 return dataDictionaryService;
79 }
80 private static MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService;
81
82
83
84
85
86
87
88
89 public static final Section toSection(Inquirable inquirable, InquirySectionDefinition sd, BusinessObject o, InquiryRestrictions auths) {
90 Section section = new Section();
91 section.setSectionId( sd.getId() );
92 section.setSectionTitle(sd.getTitle());
93 section.setRows(new ArrayList());
94 section.setDefaultOpen(sd.isDefaultOpen());
95
96 if (sd.getNumberOfColumns() != null) {
97 section.setNumberOfColumns(sd.getNumberOfColumns());
98 }
99 else {
100 section.setNumberOfColumns(KRADConstants.DEFAULT_NUM_OF_COLUMNS);
101 }
102
103 List<Field> sectionFields = new ArrayList();
104 for (FieldDefinition fieldDefinition : sd.getInquiryFields()) {
105 List row = new ArrayList();
106
107 Field f = null;
108 if (fieldDefinition instanceof InquiryCollectionDefinition) {
109 InquiryCollectionDefinition inquiryCollectionDefinition = (InquiryCollectionDefinition) fieldDefinition;
110
111 List<Row> sectionRows = new ArrayList();
112 sectionRows = getContainerRows(section, inquiryCollectionDefinition, o, null, null, new ArrayList(), new HashSet<String>(), new StringBuffer(section.getErrorKey()), inquiryCollectionDefinition.getNumberOfColumns(), inquirable);
113 section.setRows(sectionRows);
114 }
115 else if (fieldDefinition instanceof InquirySubSectionHeaderDefinition) {
116 f = createMaintainableSubSectionHeader((InquirySubSectionHeaderDefinition) fieldDefinition);
117 }
118 else {
119 f = FieldBridge.toField(fieldDefinition, o, section);
120 }
121
122 if (null != f) {
123 sectionFields.add(f);
124 }
125
126 }
127
128 if (!sectionFields.isEmpty()) {
129 section.setRows(FieldUtils.wrapFields(sectionFields, section.getNumberOfColumns()));
130 }
131
132 applyInquirySectionAuthorizations(section, auths);
133
134 section.setRows(reArrangeRows(section.getRows(), section.getNumberOfColumns()));
135
136 return section;
137 }
138
139
140 private static final void applyInquirySectionAuthorizations(Section section, InquiryRestrictions inquiryRestrictions) {
141 applyInquiryRowsAuthorizations(section.getRows(), inquiryRestrictions);
142 }
143
144 private static final void applyInquiryRowsAuthorizations(List<Row> rows, InquiryRestrictions inquiryRestrictions) {
145 for (Row row : rows) {
146 List<Field> rowFields = row.getFields();
147 for (Field field : rowFields) {
148 applyInquiryFieldAuthorizations(field, inquiryRestrictions);
149 }
150 }
151 }
152
153 protected static final void applyInquiryFieldAuthorizations(Field field, InquiryRestrictions inquiryRestrictions) {
154 if (Field.CONTAINER.equals(field.getFieldType())) {
155 applyInquiryRowsAuthorizations(field.getContainerRows(), inquiryRestrictions);
156 field.setContainerRows(reArrangeRows(field.getContainerRows(), field.getNumberOfColumnsForCollection()));
157 }
158 else if (!Field.IMAGE_SUBMIT.equals(field.getFieldType())) {
159 FieldRestriction fieldRestriction = inquiryRestrictions.getFieldRestriction(field.getPropertyName());
160 if (fieldRestriction.isHidden()) {
161 field.setFieldType(Field.HIDDEN);
162 field.setPropertyValue(null);
163 }
164
165 else if (fieldRestriction.isMasked() || fieldRestriction.isPartiallyMasked()) {
166 field.setSecure(true);
167 MaskFormatter maskFormatter = fieldRestriction.getMaskFormatter();
168 String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue());
169 field.setDisplayMaskValue(displayMaskValue);
170
171 field.setEncryptedValue("");
172 }
173 }
174 }
175
176
177 private static final List<Row> reArrangeRows(List<Row> rows, int numberOfColumns){
178 List<Row> rearrangedRows = new ArrayList<Row>();
179
180 for (Row row : rows) {
181 List<Field> fields = new ArrayList<Field>();
182 List<Field> rowFields = row.getFields();
183 for (Field field : rowFields) {
184 if(!Field.HIDDEN.equals(field.getFieldType()) && !Field.BLANK_SPACE.equals(field.getFieldType())){
185 fields.add(field);
186 }
187 }
188 List<Row> rewrappedFieldRows = FieldUtils.wrapFields(fields, numberOfColumns);
189 if (row.isHidden()) {
190 for (Row rewrappedRow : rewrappedFieldRows) {
191 rewrappedRow.setHidden(true);
192 }
193 }
194 rearrangedRows.addAll(rewrappedFieldRows);
195 }
196
197 return rearrangedRows;
198 }
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215 public static final Section toSection(MaintainableSectionDefinition sd, BusinessObject o, Maintainable maintainable, Maintainable oldMaintainable, String maintenanceAction, List<String> displayedFieldNames, Set<String> conditionallyRequiredMaintenanceFields) throws InstantiationException, IllegalAccessException {
216 Section section = new Section();
217
218 section.setSectionId( sd.getId() );
219 section.setSectionTitle(sd.getTitle());
220 section.setSectionClass(o.getClass());
221 section.setHidden( sd.isHidden() );
222 section.setDefaultOpen(sd.isDefaultOpen());
223 section.setHelpUrl(sd.getHelpUrl());
224
225
226 Collection<MaintainableItemDefinition> maintItems = sd.getMaintainableItems();
227 List<Row> sectionRows = new ArrayList<Row>();
228 List<Field> sectionFields = new ArrayList<Field>();
229
230 for (MaintainableItemDefinition maintItem : maintItems) {
231 Field field = FieldBridge.toField(maintItem, sd, o, maintainable, section, displayedFieldNames, conditionallyRequiredMaintenanceFields);
232 boolean skipAdd = false;
233
234
235 if (maintItem instanceof MaintainableCollectionDefinition) {
236 MaintainableCollectionDefinition definition = (MaintainableCollectionDefinition) maintItem;
237 section.getContainedCollectionNames().add(maintItem.getName());
238
239 StringBuffer containerRowErrorKey = new StringBuffer();
240 sectionRows = getContainerRows(section, definition, o, maintainable, oldMaintainable, displayedFieldNames, conditionallyRequiredMaintenanceFields, containerRowErrorKey, KRADConstants.DEFAULT_NUM_OF_COLUMNS, null);
241 } else if (maintItem instanceof MaintainableSubSectionHeaderDefinition) {
242 MaintainableSubSectionHeaderDefinition definition = (MaintainableSubSectionHeaderDefinition) maintItem;
243 field = createMaintainableSubSectionHeader(definition);
244 }
245
246 if (!skipAdd) {
247 sectionFields.add(field);
248 }
249 }
250
251
252
253 if (o != null) {
254 sectionFields = FieldUtils.populateFieldsFromBusinessObject(sectionFields, o);
255
256
257 if (KRADConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceAction)) {
258 for (Iterator iterator = sectionFields.iterator(); iterator.hasNext();) {
259 Field element = (Field) iterator.next();
260 if (element.isSecure()) {
261 element.setPropertyValue("");
262 }
263 }
264 }
265 }
266
267 sectionRows.addAll(FieldUtils.wrapFields(sectionFields));
268 section.setRows(sectionRows);
269
270 return section;
271
272 }
273
274
275
276
277
278
279 public static final List<Row> getContainerRows(Section s, CollectionDefinitionI collectionDefinition, BusinessObject o, Maintainable m, Maintainable oldMaintainable, List<String> displayedFieldNames, Set<String> conditionallyRequiredMaintenanceFields, StringBuffer containerRowErrorKey, int numberOfColumns, Inquirable inquirable) {
280 return getContainerRows(s, collectionDefinition, o, m, oldMaintainable, displayedFieldNames, conditionallyRequiredMaintenanceFields, containerRowErrorKey, "", false, numberOfColumns, inquirable);
281 }
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297 public static final List<Row> getContainerRows(Section s, CollectionDefinitionI collectionDefinition, BusinessObject o, Maintainable m, Maintainable oldMaintainable, List<String> displayedFieldNames, Set<String> conditionallyRequiredMaintenanceFields, StringBuffer containerRowErrorKey, String parents, boolean hideAdd, int numberOfColumns, Inquirable inquirable) {
298 List<Row> containerRows = new ArrayList<Row>();
299 List<Field> collFields = new ArrayList<Field>();
300
301 String collectionName = collectionDefinition.getName();
302
303
304 if (m != null && Inactivatable.class.isAssignableFrom(collectionDefinition.getBusinessObjectClass()) && StringUtils.isBlank(parents)) {
305 addShowInactiveButtonField(s, collectionName, !m.getShowInactiveRecords(collectionName));
306 }
307 if (inquirable != null && Inactivatable.class.isAssignableFrom(collectionDefinition.getBusinessObjectClass()) && StringUtils.isBlank(parents)) {
308 addShowInactiveButtonField(s, collectionName, !inquirable.getShowInactiveRecords(collectionName));
309 }
310
311
312 if (!hideAdd) {
313 List<Field> newFormFields = new ArrayList<Field>();
314 if (collectionDefinition.getIncludeAddLine()) {
315
316
317 newFormFields = FieldBridge.getNewFormFields(collectionDefinition, o, m, displayedFieldNames, conditionallyRequiredMaintenanceFields, containerRowErrorKey, parents, hideAdd, numberOfColumns);
318
319
320 } else if(collectionDefinition instanceof MaintainableCollectionDefinition) {
321 MaintainableCollectionDefinition mcd = (MaintainableCollectionDefinition)collectionDefinition;
322 if(FieldUtils.isCollectionMultipleLookupEnabled(mcd)) {
323
324 newFormFields = FieldBridge.constructContainerField(collectionDefinition, parents, o, hideAdd, numberOfColumns, mcd.getName(), new ArrayList<Field>());
325 }
326 }
327 if (null != newFormFields) {
328 containerRows.add(new Row(newFormFields));
329 }
330 }
331
332 Collection<? extends CollectionDefinitionI> collections = collectionDefinition.getCollections();
333 for (CollectionDefinitionI collection : collections) {
334 int subCollectionNumberOfColumn = numberOfColumns;
335 if (collectionDefinition instanceof InquiryCollectionDefinition) {
336 InquiryCollectionDefinition icd = (InquiryCollectionDefinition) collection;
337 if (icd.getNumberOfColumns() != null) {
338 subCollectionNumberOfColumn = icd.getNumberOfColumns();
339 }
340 }
341
342 containerRows.addAll(getContainerRows(s, collection, o, m, oldMaintainable, displayedFieldNames, conditionallyRequiredMaintenanceFields, containerRowErrorKey, parents + collectionDefinition.getName() + ".", true, subCollectionNumberOfColumn, inquirable));
343 }
344
345
346 Collection<? extends FieldDefinitionI> collectionFields = collectionDefinition.getFields();
347
348 String collectionLabel = getDataDictionaryService().getCollectionLabel(o.getClass(), collectionDefinition.getName());
349
350
351 String collectionElementLabel = collectionDefinition.getSummaryTitle();
352 if (StringUtils.isEmpty(collectionElementLabel)) {
353 collectionElementLabel = getDataDictionaryService().getCollectionElementLabel(o.getClass().getName(), collectionDefinition.getName(), collectionDefinition.getBusinessObjectClass());
354 }
355
356 boolean translateCodes = getMaintenanceDocumentDictionaryService().translateCodes(o.getClass());
357
358 if (o != null) {
359 if (PropertyUtils.isWriteable(o, collectionDefinition.getName()) && ObjectUtils.getPropertyValue(o, collectionDefinition.getName()) != null) {
360 Object obj = ObjectUtils.getPropertyValue(o, collectionName);
361
362 Object oldObj = null;
363 if (oldMaintainable != null && oldMaintainable.getBusinessObject() != null) {
364 oldObj = ObjectUtils.getPropertyValue(oldMaintainable.getBusinessObject(), collectionName);
365 }
366
367 if (obj instanceof List) {
368 Map summaryFields = new HashMap();
369 boolean hidableRowsPresent = false;
370 for (int i = 0; i < ((List) obj).size(); i++) {
371 BusinessObject lineBusinessObject = (BusinessObject) ((List) obj).get(i);
372
373 if (lineBusinessObject instanceof PersistableBusinessObject) {
374 ((PersistableBusinessObject) lineBusinessObject).refreshNonUpdateableReferences();
375 }
376
377
378
379
380
381 boolean setRowHidden = false;
382 BusinessObject oldLineBusinessObject = null;
383 if (oldObj != null && ((List) oldObj).size() > i) {
384 oldLineBusinessObject = (BusinessObject) ((List) oldObj).get(i);
385 }
386
387 if (lineBusinessObject instanceof Inactivatable && !((Inactivatable) lineBusinessObject).isActive()) {
388 if (m != null) {
389
390 if (!hidableRowsPresent) {
391 hidableRowsPresent = isRowHideableForMaintenanceDocument(lineBusinessObject, oldLineBusinessObject);
392 }
393 setRowHidden = isRowHiddenForMaintenanceDocument(lineBusinessObject, oldLineBusinessObject, m, collectionName);
394 }
395 if (inquirable != null) {
396
397 if (!hidableRowsPresent) {
398 hidableRowsPresent = isRowHideableForInquiry(lineBusinessObject);
399 }
400 setRowHidden = isRowHiddenForInquiry(lineBusinessObject, inquirable, collectionName);
401 }
402 }
403
404 collFields = new ArrayList<Field>();
405 List<String> duplicateIdentificationFieldNames = new ArrayList<String>();
406
407
408 if (collectionDefinition instanceof MaintainableCollectionDefinition) {
409 Collection<MaintainableFieldDefinition> duplicateFieldDefs = ((MaintainableCollectionDefinition)collectionDefinition).getDuplicateIdentificationFields();
410 for (MaintainableFieldDefinition eachFieldDef : duplicateFieldDefs) {
411 duplicateIdentificationFieldNames.add(eachFieldDef.getName());
412 }
413 }
414
415 for (FieldDefinitionI collectionField : collectionFields) {
416
417
418 Field collField = FieldUtils.getPropertyField(collectionDefinition.getBusinessObjectClass(), collectionField.getName(), false);
419
420 if (translateCodes) {
421 FieldUtils.setAdditionalDisplayPropertyForCodes(lineBusinessObject.getClass(), collField.getPropertyName(), collField);
422 }
423
424 FieldBridge.setupField(collField, collectionField, conditionallyRequiredMaintenanceFields);
425 setPrimaryKeyFieldsReadOnly(collectionDefinition.getBusinessObjectClass(), collField);
426
427
428
429 if (duplicateIdentificationFieldNames.size() > 0) {
430 setDuplicateIdentificationFieldsReadOnly(collField, duplicateIdentificationFieldNames);
431 }
432
433 FieldUtils.setInquiryURL(collField, lineBusinessObject, collectionField.getName());
434
435 String name = collField.getPropertyName();
436
437
438 collField.setPropertyName(collectionDefinition.getName() + "[" + (new Integer(i)).toString() + "]." + collField.getPropertyName());
439
440
441
442
443
444 if (collectionField instanceof MaintainableFieldDefinition) {
445 MaintenanceUtils.setFieldQuickfinder(lineBusinessObject, collectionDefinition.getName(), false, i, name, collField, displayedFieldNames, m, (MaintainableFieldDefinition) collectionField);
446 MaintenanceUtils.setFieldDirectInquiry(lineBusinessObject, name, (MaintainableFieldDefinition) collectionField, collField, displayedFieldNames);
447 } else {
448 LookupUtils
449 .setFieldQuickfinder(lineBusinessObject, collectionDefinition.getName(), false,
450 i, name, collField, displayedFieldNames, m);
451 LookupUtils.setFieldDirectInquiry(lineBusinessObject, name, collField);
452 }
453
454 String propertyValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(lineBusinessObject, collectionField.getName());
455
456
457
458 if (StringUtils.isBlank(propertyValue) && Field.FILE.equals(collField.getFieldType())) {
459 Object fileName = ObjectUtils.getNestedValue(lineBusinessObject, KRADConstants.BO_ATTACHMENT_FILE_NAME);
460 collField.setPropertyValue(fileName);
461 } else {
462 collField.setPropertyValue(propertyValue);
463
464 }
465
466 if (Field.FILE.equals(collField.getFieldType())) {
467 Object fileType = ObjectUtils.getNestedValue(lineBusinessObject, KRADConstants.BO_ATTACHMENT_FILE_CONTENT_TYPE);
468 if (fileType == null
469 && collField.getPropertyName().contains(".")) {
470
471 String tempName = collField.getPropertyName().substring(collField.getPropertyName().lastIndexOf('.')+1);
472 fileType = ObjectUtils.getNestedValue(lineBusinessObject, (tempName + "." + KRADConstants.BO_ATTACHMENT_FILE_CONTENT_TYPE));
473 }
474 collField.setImageSrc(WebUtils.getAttachmentImageForUrl((String) fileType));
475 }
476
477 if (StringUtils.isNotBlank(collField.getAlternateDisplayPropertyName())) {
478 String alternateDisplayPropertyValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(lineBusinessObject,
479 collField.getAlternateDisplayPropertyName());
480 collField.setAlternateDisplayPropertyValue(alternateDisplayPropertyValue);
481 }
482
483 if (StringUtils.isNotBlank(collField.getAdditionalDisplayPropertyName())) {
484 String additionalDisplayPropertyValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(lineBusinessObject,
485 collField.getAdditionalDisplayPropertyName());
486 collField.setAdditionalDisplayPropertyValue(additionalDisplayPropertyValue);
487 }
488
489
490 updateUserFields(collField, lineBusinessObject);
491
492
493 if (collectionField.isReadOnlyAfterAdd()) {
494 collField.setReadOnly(true);
495 }
496
497
498 if (collectionDefinition.hasSummaryField(collectionField.getName())) {
499 summaryFields.put(collectionField.getName(), collField);
500 }
501
502 collFields.add(collField);
503 }
504
505 Field containerField;
506 containerField = FieldUtils.constructContainerField(
507 KRADConstants.EDIT_PREFIX + "[" + (new Integer(i)).toString() + "]", collectionLabel + " " + (i + 1), collFields, numberOfColumns);
508
509 containerField.setContainerName(collectionDefinition.getName() + "[" + (new Integer(i)).toString() + "].");
510
511
512
513 if (lineBusinessObject instanceof PersistableBusinessObject &&
514 (((PersistableBusinessObject) lineBusinessObject).isNewCollectionRecord()
515 || collectionDefinition.isAlwaysAllowCollectionDeletion())) {
516 containerField.getContainerRows().add(new Row(getDeleteRowButtonField(parents + collectionDefinition.getName(), (new Integer(i)).toString())));
517 }
518
519 if (StringUtils.isNotEmpty(collectionElementLabel)) {
520
521
522
523
524 containerField.setContainerElementName(collectionElementLabel);
525
526 List orderedSummaryFields = getSummaryFields(summaryFields, collectionDefinition);
527 containerField.setContainerDisplayFields(orderedSummaryFields);
528 }
529
530 Row containerRow = new Row(containerField);
531 if (setRowHidden) {
532 containerRow.setHidden(true);
533 }
534 containerRows.add(containerRow);
535
536
537
538 Collection<? extends CollectionDefinitionI> subCollections = collectionDefinition.getCollections();
539 List<Field> subCollFields = new ArrayList<Field>();
540
541 summaryFields = new HashMap();
542
543 for (CollectionDefinitionI subCollection : subCollections) {
544 Collection<? extends FieldDefinitionI> subCollectionFields = subCollection.getFields();
545 int subCollectionNumberOfColumns = numberOfColumns;
546
547 if (!s.getContainedCollectionNames().contains(collectionDefinition.getName() + "." + subCollection.getName())) {
548 s.getContainedCollectionNames().add(collectionDefinition.getName() + "." + subCollection.getName());
549 }
550
551 if (subCollection instanceof InquiryCollectionDefinition) {
552 InquiryCollectionDefinition icd = (InquiryCollectionDefinition) subCollection;
553 if (icd.getNumberOfColumns() != null) {
554 subCollectionNumberOfColumns = icd.getNumberOfColumns();
555 }
556 }
557
558 String subCollectionLabel = getDataDictionaryService().getCollectionLabel(o.getClass(), subCollection.getName());
559
560
561 String subCollectionElementLabel = subCollection.getSummaryTitle();
562 if (StringUtils.isEmpty(subCollectionElementLabel)) {
563 subCollectionElementLabel = getDataDictionaryService().getCollectionElementLabel(o.getClass().getName(), subCollection.getName(), subCollection.getBusinessObjectClass());
564 }
565
566
567 String subCollectionName = subCollection.getName();
568 Object subObj = ObjectUtils.getPropertyValue(lineBusinessObject, subCollectionName);
569
570 Object oldSubObj = null;
571 if (oldLineBusinessObject != null) {
572 oldSubObj = ObjectUtils.getPropertyValue(oldLineBusinessObject, subCollectionName);
573 }
574
575 if (subObj instanceof List) {
576
577
578 containerField.getContainerRows().addAll(getContainerRows(s, subCollection, o, m, oldMaintainable, displayedFieldNames, conditionallyRequiredMaintenanceFields, containerRowErrorKey, parents + collectionDefinition.getName() + "[" + i + "]" + ".", false, subCollectionNumberOfColumns, inquirable));
579
580
581 for (int j = 0; j < ((List) subObj).size(); j++) {
582 BusinessObject lineSubBusinessObject = (BusinessObject) ((List) subObj).get(j);
583
584 if (lineSubBusinessObject instanceof PersistableBusinessObject) {
585 ((PersistableBusinessObject) lineSubBusinessObject).refreshNonUpdateableReferences();
586 }
587
588
589 boolean setSubRowHidden = false;
590 if (lineSubBusinessObject instanceof Inactivatable && !((Inactivatable) lineSubBusinessObject).isActive()) {
591 if (oldSubObj != null) {
592
593 BusinessObject oldLineSubBusinessObject = (BusinessObject) ((List) oldSubObj).get(j);
594 if (m != null) {
595 if (!hidableRowsPresent) {
596 hidableRowsPresent = isRowHideableForMaintenanceDocument(lineSubBusinessObject, oldLineSubBusinessObject);
597 }
598 setSubRowHidden = isRowHiddenForMaintenanceDocument(lineSubBusinessObject, oldLineSubBusinessObject, m, collectionName);
599 }
600 }
601 if (inquirable != null) {
602 if (!hidableRowsPresent) {
603 hidableRowsPresent = isRowHideableForInquiry(lineSubBusinessObject);
604 }
605 setSubRowHidden = isRowHiddenForInquiry(lineSubBusinessObject, inquirable, collectionName);
606 }
607 }
608
609
610 subCollFields = new ArrayList<Field>();
611
612 for (FieldDefinitionI subCollectionField : subCollectionFields) {
613
614
615 Field subCollField = FieldUtils.getPropertyField(subCollection.getBusinessObjectClass(), subCollectionField.getName(), false);
616
617 String subCollectionFullName = collectionDefinition.getName() + "[" + i + "]" + "." + subCollection.getName();
618
619 if (translateCodes) {
620 FieldUtils.setAdditionalDisplayPropertyForCodes(lineSubBusinessObject.getClass(), subCollField.getPropertyName(), subCollField);
621 }
622
623 FieldBridge.setupField(subCollField, subCollectionField, conditionallyRequiredMaintenanceFields);
624 setPrimaryKeyFieldsReadOnly(subCollection.getBusinessObjectClass(), subCollField);
625
626
627 String name = subCollField.getPropertyName();
628
629
630 subCollField.setPropertyName(subCollectionFullName + "[" + j + "]." + subCollField.getPropertyName());
631
632
633 if (subCollectionField instanceof MaintainableFieldDefinition) {
634 MaintenanceUtils.setFieldQuickfinder(lineSubBusinessObject, subCollectionFullName, false, j, name, subCollField, displayedFieldNames, m, (MaintainableFieldDefinition) subCollectionField);
635 MaintenanceUtils
636 .setFieldDirectInquiry(lineSubBusinessObject, subCollectionFullName,
637 false, j, name, subCollField, displayedFieldNames, m,
638 (MaintainableFieldDefinition) subCollectionField);
639 } else {
640 LookupUtils.setFieldQuickfinder(lineSubBusinessObject, subCollectionFullName, false, j, name, subCollField, displayedFieldNames);
641 LookupUtils.setFieldDirectInquiry(lineBusinessObject, name, subCollField);
642 }
643
644 String propertyValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(lineSubBusinessObject, subCollectionField.getName());
645 subCollField.setPropertyValue(propertyValue);
646
647 if (StringUtils.isNotBlank(subCollField.getAlternateDisplayPropertyName())) {
648 String alternateDisplayPropertyValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(lineSubBusinessObject,
649 subCollField.getAlternateDisplayPropertyName());
650 subCollField.setAlternateDisplayPropertyValue(alternateDisplayPropertyValue);
651 }
652
653 if (StringUtils.isNotBlank(subCollField.getAdditionalDisplayPropertyName())) {
654 String additionalDisplayPropertyValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(lineSubBusinessObject,
655 subCollField.getAdditionalDisplayPropertyName());
656 subCollField.setAdditionalDisplayPropertyValue(additionalDisplayPropertyValue);
657 }
658
659
660 if (subCollection.hasSummaryField(subCollectionField.getName())) {
661 summaryFields.put(subCollectionField.getName(), subCollField);
662 }
663
664 if (subCollectionField.isReadOnlyAfterAdd()) {
665 subCollField.setReadOnly(true);
666 }
667
668 subCollFields.add(subCollField);
669 }
670
671 Field subContainerField = FieldUtils.constructContainerField(
672 KRADConstants.EDIT_PREFIX + "[" + (new Integer(j)).toString() + "]", subCollectionLabel, subCollFields);
673 if (lineSubBusinessObject instanceof PersistableBusinessObject && (((PersistableBusinessObject) lineSubBusinessObject).isNewCollectionRecord() || subCollection.isAlwaysAllowCollectionDeletion())) {
674 subContainerField.getContainerRows().add(new Row(getDeleteRowButtonField(parents + collectionDefinition.getName() + "[" + i + "]" + "." + subCollectionName, (new Integer(j)).toString())));
675 }
676
677
678 if (StringUtils.isNotEmpty(subCollectionElementLabel)) {
679
680
681
682
683 subContainerField.setContainerElementName(collectionElementLabel + "-" + subCollectionElementLabel);
684 }
685 subContainerField.setContainerName(collectionDefinition.getName() + "." + subCollectionName);
686 if (!summaryFields.isEmpty()) {
687
688 List orderedSummaryFields = getSummaryFields(summaryFields, subCollection);
689 subContainerField.setContainerDisplayFields(orderedSummaryFields);
690 }
691
692 Row subContainerRow = new Row(subContainerField);
693 if (setRowHidden || setSubRowHidden) {
694 subContainerRow.setHidden(true);
695 }
696 containerField.getContainerRows().add(subContainerRow);
697 }
698 }
699 }
700 }
701 if ( !hidableRowsPresent ) {
702 s.setExtraButtonSource( "" );
703 }
704 }
705 }
706 }
707
708 return containerRows;
709 }
710
711
712
713
714
715
716
717 private static final void updateUserFields(Field field, BusinessObject businessObject){
718
719 if ( field.getFieldType().equals(Field.KUALIUSER) ) {
720
721 try {
722 if ( StringUtils.isNotBlank(field.getUniversalIdAttributeName()) ) {
723 Object principalId = ObjectUtils.getNestedValue(businessObject, field.getUniversalIdAttributeName());
724 if ( principalId != null ) {
725 field.setUniversalIdValue(principalId.toString());
726 }
727 }
728 if ( StringUtils.isNotBlank(field.getPersonNameAttributeName()) ) {
729 Object personName = ObjectUtils.getNestedValue(businessObject, field.getPersonNameAttributeName());
730 if ( personName != null ) {
731 field.setPersonNameValue( personName.toString() );
732 }
733 }
734 } catch ( Exception ex ) {
735 LOG.warn( "Unable to get principal ID or person name property in SectionBridge.", ex );
736 }
737 }
738 }
739
740
741
742
743
744
745
746
747
748 private static final Field getDeleteRowButtonField(String collectionName, String rowIndex) {
749 Field deleteButtonField = new Field();
750
751 String deleteButtonName = KRADConstants.DISPATCH_REQUEST_PARAMETER + "." + KRADConstants.DELETE_LINE_METHOD + "." + collectionName + "." + KRADConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL + ".line" + rowIndex;
752 deleteButtonField.setPropertyName(deleteButtonName);
753 deleteButtonField.setFieldType(Field.IMAGE_SUBMIT);
754 deleteButtonField.setPropertyValue("images/tinybutton-delete1.gif");
755
756 return deleteButtonField;
757 }
758
759
760
761
762
763
764
765
766
767 private static final void addShowInactiveButtonField(Section section, String collectionName, boolean showInactive) {
768 String methodName = KRADConstants.DISPATCH_REQUEST_PARAMETER + "." + KRADConstants.TOGGLE_INACTIVE_METHOD + "." + collectionName.replace( '.', '_' );
769 methodName += "." + KRADConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL + showInactive + ".anchorshowInactive." + collectionName + KRADConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL;
770
771 String imageSource = showInactive ? "tinybutton-showinact.gif" : "tinybutton-hideinact.gif";
772
773 String showInactiveButton = "property=" + methodName + ";src=" + imageSource + ";alt=show(hide) inactive" + ";title=show(hide) inactive";
774
775 section.setExtraButtonSource(showInactiveButton);
776 }
777
778
779
780
781
782
783 private static final void setPrimaryKeyFieldsReadOnly(Class businessObjectClass, Field field) {
784 try{
785
786
787 List primaryKeyPropertyNames =
788 KNSServiceLocator.getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(businessObjectClass);
789 if (primaryKeyPropertyNames.contains(field.getPropertyName())) {
790 field.setReadOnly(true);
791 }
792 } catch(ClassNotPersistableException ex){
793
794 LOG.info("Not persistable dataObjectClass: "+businessObjectClass+", field: "+field);
795 }
796 }
797
798 private static void setDuplicateIdentificationFieldsReadOnly(Field field, List<String>duplicateIdentificationFieldNames) {
799 if (duplicateIdentificationFieldNames.contains(field.getPropertyName())) {
800 field.setReadOnly(true);
801 }
802 }
803
804
805
806
807
808
809
810
811 private static final List<Field> getSummaryFields(Map collSummaryFields, CollectionDefinitionI collectionDefinition) {
812 List<Field> orderedSummaryFields = new ArrayList<Field>();
813 for (FieldDefinitionI summaryField : collectionDefinition.getSummaryFields()) {
814 String name = summaryField.getName();
815 boolean found = false;
816 Field addField = (Field) collSummaryFields.get(name);
817 if (!(addField == null)) {
818 orderedSummaryFields.add(addField);
819 found = true;
820 }
821
822 if (!found) {
823
824 LOG.error("summaryField " + summaryField + " not present in the list");
825 }
826
827 }
828 return orderedSummaryFields;
829 }
830
831
832
833
834
835
836
837 private static final Field createMaintainableSubSectionHeader(SubSectionHeaderDefinitionI definition) {
838 Field separatorField = new Field();
839 separatorField.setFieldLabel(definition.getName());
840 separatorField.setFieldType(Field.SUB_SECTION_SEPARATOR);
841 separatorField.setReadOnly(true);
842
843 return separatorField;
844 }
845
846
847
848
849
850
851
852
853
854
855 protected static boolean isRowHideableForMaintenanceDocument(BusinessObject lineBusinessObject, BusinessObject oldLineBusinessObject) {
856 if (oldLineBusinessObject != null) {
857 if (((PersistableBusinessObject) lineBusinessObject).isNewCollectionRecord()) {
858
859 return false;
860 }
861 if (!((Inactivatable) lineBusinessObject).isActive() && !((Inactivatable) oldLineBusinessObject).isActive()) {
862
863 return true;
864 }
865 }
866 return false;
867 }
868
869
870
871
872
873
874
875
876
877 protected static boolean isRowHiddenForMaintenanceDocument(BusinessObject lineBusinessObject, BusinessObject oldLineBusinessObject,
878 Maintainable newMaintainable, String collectionName) {
879 return isRowHideableForMaintenanceDocument(lineBusinessObject, oldLineBusinessObject) && !newMaintainable.getShowInactiveRecords(collectionName);
880 }
881
882
883
884
885
886
887
888
889 protected static boolean isRowHideableForInquiry(BusinessObject lineBusinessObject) {
890 return !((Inactivatable) lineBusinessObject).isActive();
891 }
892
893
894
895
896
897
898
899
900
901 protected static boolean isRowHiddenForInquiry(BusinessObject lineBusinessObject, Inquirable inquirable, String collectionName) {
902 return isRowHideableForInquiry(lineBusinessObject) && !inquirable.getShowInactiveRecords(collectionName);
903 }
904
905 public static MaintenanceDocumentDictionaryService getMaintenanceDocumentDictionaryService() {
906 if (maintenanceDocumentDictionaryService == null) {
907 maintenanceDocumentDictionaryService = KNSServiceLocator.getMaintenanceDocumentDictionaryService();
908 }
909 return maintenanceDocumentDictionaryService;
910 }
911 }
912