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 | 0 | public class MaintenanceDocumentPropertySerializibilityEvaluator |
36 | |
extends PropertySerializabilityEvaluatorBase implements PropertySerializabilityEvaluator { |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
@Override |
44 | |
public void initializeEvaluatorForDataObject(Object businessObject){ |
45 | 0 | DataDictionary dictionary = KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary(); |
46 | 0 | MaintenanceDocumentEntry maintenanceDocumentEntry = (MaintenanceDocumentEntry) |
47 | |
dictionary.getMaintenanceDocumentEntryForBusinessObjectClass(businessObject.getClass()); |
48 | 0 | serializableProperties = new PropertySerializerTrie(); |
49 | 0 | populateSerializableProperties(maintenanceDocumentEntry.getMaintainableSections()); |
50 | 0 | serializableProperties.addSerializablePropertyName("boNotes", true); |
51 | 0 | serializableProperties.addSerializablePropertyName("boNotes.attachment", true); |
52 | 0 | } |
53 | |
|
54 | |
private void populateSerializableProperties(List<MaintainableSectionDefinition> maintainableSectionDefinitions){ |
55 | 0 | for(MaintainableSectionDefinition maintainableSectionDefinition: maintainableSectionDefinitions){ |
56 | 0 | populateSerializablePropertiesWithItems("", maintainableSectionDefinition.getMaintainableItems()); |
57 | |
} |
58 | 0 | } |
59 | |
|
60 | |
private void populateSerializablePropertiesWithItems(String basePath, List<MaintainableItemDefinition> maintainableItems){ |
61 | 0 | for(MaintainableItemDefinition maintainableItemDefinition: maintainableItems){ |
62 | 0 | if(maintainableItemDefinition instanceof MaintainableFieldDefinition){ |
63 | 0 | serializableProperties.addSerializablePropertyName(getFullItemName(basePath, maintainableItemDefinition.getName()), true); |
64 | 0 | } else if(maintainableItemDefinition instanceof MaintainableCollectionDefinition){ |
65 | 0 | serializableProperties.addSerializablePropertyName(getFullItemName(basePath, maintainableItemDefinition.getName()), true); |
66 | 0 | populateSerializablePropertiesWithItems(getFullItemName(basePath, maintainableItemDefinition.getName()), |
67 | |
getAllMaintainableFieldDefinitionsForSerialization( |
68 | |
(MaintainableCollectionDefinition)maintainableItemDefinition)); |
69 | 0 | } else if(maintainableItemDefinition instanceof MaintainableSubSectionHeaderDefinition){ |
70 | |
|
71 | |
} |
72 | |
} |
73 | 0 | } |
74 | |
|
75 | |
private String getFullItemName(String basePath, String itemName){ |
76 | 0 | return StringUtils.isEmpty(basePath) ? itemName : basePath+"."+itemName; |
77 | |
} |
78 | |
|
79 | |
public List<MaintainableItemDefinition> getAllMaintainableFieldDefinitionsForSerialization( |
80 | |
MaintainableCollectionDefinition maintainableCollectionDefinition){ |
81 | 0 | List<MaintainableItemDefinition> allMaintainableItemDefinitions = new ArrayList<MaintainableItemDefinition>(); |
82 | |
|
83 | 0 | if(maintainableCollectionDefinition.getMaintainableFields()!=null){ |
84 | 0 | allMaintainableItemDefinitions.addAll(maintainableCollectionDefinition.getMaintainableFields()); |
85 | |
} |
86 | |
|
87 | 0 | if(maintainableCollectionDefinition.getSummaryFields()!=null){ |
88 | 0 | allMaintainableItemDefinitions.addAll( |
89 | |
(List<MaintainableFieldDefinition>)maintainableCollectionDefinition.getSummaryFields()); |
90 | |
} |
91 | |
|
92 | 0 | if(maintainableCollectionDefinition.getDuplicateIdentificationFields()!=null){ |
93 | 0 | allMaintainableItemDefinitions.addAll(maintainableCollectionDefinition.getDuplicateIdentificationFields()); |
94 | |
} |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | 0 | if(maintainableCollectionDefinition.getMaintainableCollections()!=null){ |
101 | 0 | allMaintainableItemDefinitions.addAll(maintainableCollectionDefinition.getMaintainableCollections()); |
102 | |
} |
103 | |
|
104 | 0 | return allMaintainableItemDefinitions; |
105 | |
} |
106 | |
|
107 | |
} |