1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.util.documentserializer;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.rice.kns.bo.BusinessObject;
23 import org.kuali.rice.kns.datadictionary.DataDictionary;
24 import org.kuali.rice.kns.datadictionary.MaintainableCollectionDefinition;
25 import org.kuali.rice.kns.datadictionary.MaintainableFieldDefinition;
26 import org.kuali.rice.kns.datadictionary.MaintainableItemDefinition;
27 import org.kuali.rice.kns.datadictionary.MaintainableSectionDefinition;
28 import org.kuali.rice.kns.datadictionary.MaintainableSubSectionHeaderDefinition;
29 import org.kuali.rice.kns.datadictionary.MaintenanceDocumentEntry;
30 import org.kuali.rice.kns.service.KNSServiceLocator;
31
32
33 public class MaintenanceDocumentPropertySerializibilityEvaluator
34 extends PropertySerializabilityEvaluatorBase implements PropertySerializabilityEvaluator {
35
36
37
38
39
40
41 public void initializeEvaluator(BusinessObject businessObject){
42 DataDictionary dictionary = KNSServiceLocator.getDataDictionaryService().getDataDictionary();
43 MaintenanceDocumentEntry maintenanceDocumentEntry =
44 dictionary.getMaintenanceDocumentEntryForBusinessObjectClass(businessObject.getClass());
45 serializableProperties = new PropertySerializerTrie();
46 populateSerializableProperties(maintenanceDocumentEntry.getMaintainableSections());
47 serializableProperties.addSerializablePropertyName("boNotes", true);
48 serializableProperties.addSerializablePropertyName("boNotes.attachment", true);
49 }
50
51 private void populateSerializableProperties(List<MaintainableSectionDefinition> maintainableSectionDefinitions){
52 for(MaintainableSectionDefinition maintainableSectionDefinition: maintainableSectionDefinitions){
53 populateSerializablePropertiesWithItems("", maintainableSectionDefinition.getMaintainableItems());
54 }
55 }
56
57 private void populateSerializablePropertiesWithItems(String basePath, List<MaintainableItemDefinition> maintainableItems){
58 for(MaintainableItemDefinition maintainableItemDefinition: maintainableItems){
59 if(maintainableItemDefinition instanceof MaintainableFieldDefinition){
60 serializableProperties.addSerializablePropertyName(getFullItemName(basePath, maintainableItemDefinition.getName()), true);
61 } else if(maintainableItemDefinition instanceof MaintainableCollectionDefinition){
62 serializableProperties.addSerializablePropertyName(getFullItemName(basePath, maintainableItemDefinition.getName()), true);
63 populateSerializablePropertiesWithItems(getFullItemName(basePath, maintainableItemDefinition.getName()),
64 getAllMaintainableFieldDefinitionsForSerialization(
65 (MaintainableCollectionDefinition)maintainableItemDefinition));
66 } else if(maintainableItemDefinition instanceof MaintainableSubSectionHeaderDefinition){
67
68 }
69 }
70 }
71
72 private String getFullItemName(String basePath, String itemName){
73 return StringUtils.isEmpty(basePath) ? itemName : basePath+"."+itemName;
74 }
75
76 public List<MaintainableItemDefinition> getAllMaintainableFieldDefinitionsForSerialization(
77 MaintainableCollectionDefinition maintainableCollectionDefinition){
78 List<MaintainableItemDefinition> allMaintainableItemDefinitions = new ArrayList<MaintainableItemDefinition>();
79
80 if(maintainableCollectionDefinition.getMaintainableFields()!=null){
81 allMaintainableItemDefinitions.addAll(maintainableCollectionDefinition.getMaintainableFields());
82 }
83
84 if(maintainableCollectionDefinition.getSummaryFields()!=null){
85 allMaintainableItemDefinitions.addAll(
86 (List<MaintainableFieldDefinition>)maintainableCollectionDefinition.getSummaryFields());
87 }
88
89 if(maintainableCollectionDefinition.getDuplicateIdentificationFields()!=null){
90 allMaintainableItemDefinitions.addAll(maintainableCollectionDefinition.getDuplicateIdentificationFields());
91 }
92
93
94
95
96
97 if(maintainableCollectionDefinition.getMaintainableCollections()!=null){
98 allMaintainableItemDefinitions.addAll(maintainableCollectionDefinition.getMaintainableCollections());
99 }
100
101 return allMaintainableItemDefinitions;
102 }
103
104 }