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.bo.BusinessObject;
25 import org.kuali.rice.krad.datadictionary.DataDictionary;
26 import org.kuali.rice.kns.datadictionary.MaintenanceDocumentEntry;
27 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
28 import org.kuali.rice.krad.util.documentserializer.PropertySerializabilityEvaluator;
29 import org.kuali.rice.krad.util.documentserializer.PropertySerializabilityEvaluatorBase;
30 import org.kuali.rice.krad.util.documentserializer.PropertySerializerTrie;
31 import org.kuali.rice.krad.util.documentserializer.PropertyType;
32
33 import java.util.ArrayList;
34 import java.util.Collection;
35 import java.util.List;
36 import java.util.Map;
37
38 public class MaintenanceDocumentPropertySerializibilityEvaluator
39 extends PropertySerializabilityEvaluatorBase implements PropertySerializabilityEvaluator {
40
41
42
43
44
45
46 @Override
47 public void initializeEvaluatorForDataObject(Object businessObject){
48 DataDictionary dictionary = KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary();
49 MaintenanceDocumentEntry maintenanceDocumentEntry = (MaintenanceDocumentEntry)
50 dictionary.getMaintenanceDocumentEntryForBusinessObjectClass(businessObject.getClass());
51 serializableProperties = new PropertySerializerTrie();
52 populateSerializableProperties(maintenanceDocumentEntry.getMaintainableSections());
53 serializableProperties.addSerializablePropertyName("boNotes", true);
54 serializableProperties.addSerializablePropertyName("boNotes.attachment", true);
55 }
56
57
58
59
60 @Override
61 public PropertyType determinePropertyType(Object propertyValue) {
62 if (propertyValue == null) {
63 return PropertyType.PRIMITIVE;
64 }
65
66 if (propertyValue instanceof BusinessObject) {
67 return PropertyType.BUSINESS_OBJECT;
68 }
69
70 if (propertyValue instanceof Collection) {
71 return PropertyType.COLLECTION;
72 }
73
74
75 if (propertyValue instanceof Map) {
76 return PropertyType.PRIMITIVE;
77 }
78
79 return PropertyType.PRIMITIVE;
80 }
81
82 private void populateSerializableProperties(List<MaintainableSectionDefinition> maintainableSectionDefinitions){
83 for(MaintainableSectionDefinition maintainableSectionDefinition: maintainableSectionDefinitions){
84 populateSerializablePropertiesWithItems("", maintainableSectionDefinition.getMaintainableItems());
85 }
86 }
87
88 private void populateSerializablePropertiesWithItems(String basePath, List<MaintainableItemDefinition> maintainableItems){
89 for(MaintainableItemDefinition maintainableItemDefinition: maintainableItems){
90 if(maintainableItemDefinition instanceof MaintainableFieldDefinition){
91 serializableProperties.addSerializablePropertyName(getFullItemName(basePath, maintainableItemDefinition.getName()), true);
92 } else if(maintainableItemDefinition instanceof MaintainableCollectionDefinition){
93 serializableProperties.addSerializablePropertyName(getFullItemName(basePath, maintainableItemDefinition.getName()), true);
94 populateSerializablePropertiesWithItems(getFullItemName(basePath, maintainableItemDefinition.getName()),
95 getAllMaintainableFieldDefinitionsForSerialization(
96 (MaintainableCollectionDefinition)maintainableItemDefinition));
97 } else if(maintainableItemDefinition instanceof MaintainableSubSectionHeaderDefinition){
98
99 }
100 }
101 }
102
103 private String getFullItemName(String basePath, String itemName){
104 return StringUtils.isEmpty(basePath) ? itemName : basePath+"."+itemName;
105 }
106
107 public List<MaintainableItemDefinition> getAllMaintainableFieldDefinitionsForSerialization(
108 MaintainableCollectionDefinition maintainableCollectionDefinition){
109 List<MaintainableItemDefinition> allMaintainableItemDefinitions = new ArrayList<MaintainableItemDefinition>();
110
111 if(maintainableCollectionDefinition.getMaintainableFields()!=null){
112 allMaintainableItemDefinitions.addAll(maintainableCollectionDefinition.getMaintainableFields());
113 }
114
115 if(maintainableCollectionDefinition.getSummaryFields()!=null){
116 allMaintainableItemDefinitions.addAll(
117 (List<MaintainableFieldDefinition>)maintainableCollectionDefinition.getSummaryFields());
118 }
119
120 if(maintainableCollectionDefinition.getDuplicateIdentificationFields()!=null){
121 allMaintainableItemDefinitions.addAll(maintainableCollectionDefinition.getDuplicateIdentificationFields());
122 }
123
124
125
126
127
128 if(maintainableCollectionDefinition.getMaintainableCollections()!=null){
129 allMaintainableItemDefinitions.addAll(maintainableCollectionDefinition.getMaintainableCollections());
130 }
131
132 return allMaintainableItemDefinitions;
133 }
134
135 }