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