1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.datadictionary.exporter; |
17 | |
|
18 | |
import java.util.Iterator; |
19 | |
|
20 | |
import org.apache.commons.lang.StringUtils; |
21 | |
import org.kuali.rice.krad.datadictionary.MaintainableCollectionDefinition; |
22 | |
import org.kuali.rice.krad.datadictionary.MaintainableFieldDefinition; |
23 | |
import org.kuali.rice.krad.datadictionary.MaintainableItemDefinition; |
24 | |
import org.kuali.rice.krad.datadictionary.MaintainableSectionDefinition; |
25 | |
import org.kuali.rice.krad.datadictionary.MaintainableSubSectionHeaderDefinition; |
26 | |
import org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
public class MaintenanceDocumentEntryMapper extends DocumentEntryMapper { |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | public MaintenanceDocumentEntryMapper() { |
39 | 0 | } |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public ExportMap mapEntry(MaintenanceDocumentEntry entry) { |
47 | 0 | ExportMap entryMap = super.mapEntry(entry); |
48 | |
|
49 | |
|
50 | 0 | entryMap.set("maintenanceDocument", "true"); |
51 | 0 | entryMap.set("businessObjectClass", entry.getBusinessObjectClass().getName()); |
52 | 0 | entryMap.set("maintainableClass", entry.getMaintainableClass().getName()); |
53 | |
|
54 | |
|
55 | 0 | entryMap.set(buildMaintainableSectionsMap(entry)); |
56 | |
|
57 | 0 | return entryMap; |
58 | |
} |
59 | |
|
60 | |
private ExportMap buildMaintainableSectionsMap(MaintenanceDocumentEntry entry) { |
61 | 0 | ExportMap maintainableSectionsMap = new ExportMap("maintainableSections"); |
62 | |
|
63 | 0 | int index = 0; |
64 | 0 | for (Iterator i = entry.getMaintainableSections().iterator(); i.hasNext();) { |
65 | 0 | MaintainableSectionDefinition section = (MaintainableSectionDefinition) i.next(); |
66 | |
|
67 | 0 | maintainableSectionsMap.set(buildMaintainableSectionMap(section, index++)); |
68 | 0 | } |
69 | |
|
70 | 0 | return maintainableSectionsMap; |
71 | |
} |
72 | |
|
73 | |
private ExportMap buildMaintainableSectionMap(MaintainableSectionDefinition section, int index) { |
74 | 0 | ExportMap sectionMap = new ExportMap(Integer.toString(index)); |
75 | |
|
76 | 0 | sectionMap.set("index", Integer.toString(index)); |
77 | 0 | sectionMap.set("title", section.getTitle()); |
78 | |
|
79 | 0 | sectionMap.set(buildMaintainableItemsMap(section)); |
80 | |
|
81 | 0 | return sectionMap; |
82 | |
} |
83 | |
|
84 | |
private ExportMap buildMaintainableItemsMap(MaintainableSectionDefinition section) { |
85 | 0 | ExportMap itemsMap = new ExportMap("maintainableItems"); |
86 | |
|
87 | 0 | for (Iterator i = section.getMaintainableItems().iterator(); i.hasNext();) { |
88 | 0 | MaintainableItemDefinition item = (MaintainableItemDefinition) i.next(); |
89 | 0 | itemsMap.set(buildMaintainableItemMap(item)); |
90 | 0 | } |
91 | |
|
92 | 0 | return itemsMap; |
93 | |
} |
94 | |
|
95 | |
private ExportMap buildMaintainableItemMap(MaintainableItemDefinition item) { |
96 | 0 | ExportMap itemMap = new ExportMap(item.getName()); |
97 | |
|
98 | 0 | if (item instanceof MaintainableFieldDefinition) { |
99 | 0 | MaintainableFieldDefinition field = (MaintainableFieldDefinition) item; |
100 | |
|
101 | 0 | itemMap.set("field", "true"); |
102 | 0 | itemMap.set("name", field.getName()); |
103 | 0 | itemMap.set("required", Boolean.toString(field.isRequired())); |
104 | 0 | if (StringUtils.isNotBlank(field.getAlternateDisplayAttributeName())) { |
105 | 0 | itemMap.set("alternateDisplayAttributeName", field.getAlternateDisplayAttributeName()); |
106 | |
} |
107 | 0 | if (StringUtils.isNotBlank(field.getAdditionalDisplayAttributeName())) { |
108 | 0 | itemMap.set("additionalDisplayAttributeName", field.getAdditionalDisplayAttributeName()); |
109 | |
} |
110 | 0 | } |
111 | 0 | else if (item instanceof MaintainableCollectionDefinition) { |
112 | 0 | MaintainableCollectionDefinition collection = (MaintainableCollectionDefinition) item; |
113 | |
|
114 | 0 | itemMap.set("collection", "true"); |
115 | 0 | itemMap.set("name", collection.getName()); |
116 | 0 | itemMap.set("businessObjectClass", collection.getBusinessObjectClass().getName()); |
117 | 0 | } |
118 | 0 | else if (item instanceof MaintainableSubSectionHeaderDefinition) { |
119 | 0 | MaintainableSubSectionHeaderDefinition subSectionHeader = (MaintainableSubSectionHeaderDefinition) item; |
120 | 0 | itemMap.set("name", subSectionHeader.getName()); |
121 | 0 | } |
122 | |
else { |
123 | 0 | throw new IllegalStateException("unable to create itemMap for unknown MaintainableItem subclass '" + item.getClass().getName() + "'"); |
124 | |
} |
125 | |
|
126 | 0 | return itemMap; |
127 | |
} |
128 | |
} |