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