1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.datadictionary.exporter; |
17 | |
|
18 | |
import java.util.Iterator; |
19 | |
|
20 | |
import org.apache.commons.lang.StringUtils; |
21 | |
import org.kuali.rice.kew.api.doctype.DocumentType; |
22 | |
import org.kuali.rice.kns.datadictionary.MaintainableCollectionDefinition; |
23 | |
import org.kuali.rice.kns.datadictionary.MaintainableFieldDefinition; |
24 | |
import org.kuali.rice.kns.datadictionary.MaintainableItemDefinition; |
25 | |
import org.kuali.rice.kns.datadictionary.MaintainableSectionDefinition; |
26 | |
import org.kuali.rice.kns.datadictionary.MaintainableSubSectionHeaderDefinition; |
27 | |
import org.kuali.rice.kns.datadictionary.MaintenanceDocumentEntry; |
28 | |
import org.kuali.rice.krad.datadictionary.exporter.ExportMap; |
29 | |
import org.kuali.rice.krad.service.DocumentHelperService; |
30 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
@Deprecated |
38 | |
public class MaintenanceDocumentEntryMapper extends DocumentEntryMapper { |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public MaintenanceDocumentEntryMapper() { |
44 | 0 | } |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public ExportMap mapEntry(MaintenanceDocumentEntry entry) { |
52 | |
|
53 | 0 | ExportMap entryMap = new ExportMap(entry.getJstlKey()); |
54 | |
|
55 | 0 | Class businessRulesClass = entry.getBusinessRulesClass(); |
56 | 0 | if (businessRulesClass != null) { |
57 | 0 | entryMap.set("businessRulesClass", businessRulesClass.getName()); |
58 | |
} |
59 | |
|
60 | 0 | entryMap.set("documentTypeName", entry.getDocumentTypeName()); |
61 | |
|
62 | 0 | DocumentType docType = getDocumentType(entry.getDocumentTypeName()); |
63 | 0 | entryMap.set("label", docType.getLabel()); |
64 | |
|
65 | 0 | if (docType.getDescription() != null) { |
66 | 0 | entryMap.set("description", docType.getDescription()); |
67 | |
} |
68 | |
|
69 | 0 | DocumentHelperService documentHelperService = KRADServiceLocatorWeb.getDocumentHelperService(); |
70 | 0 | entryMap.set("documentAuthorizerClass", documentHelperService.getDocumentAuthorizer(entry.getDocumentTypeName()).getClass().getName()); |
71 | 0 | entryMap.set("documentPresentationControllerClass", documentHelperService.getDocumentPresentationController(entry.getDocumentTypeName()).getClass().getName()); |
72 | |
|
73 | 0 | entryMap.set("allowsNoteAttachments", Boolean.toString(entry.getAllowsNoteAttachments())); |
74 | |
|
75 | 0 | entryMap.set("allowsNoteFYI", Boolean.toString(entry.getAllowsNoteFYI())); |
76 | |
|
77 | 0 | if (entry.getAttachmentTypesValuesFinderClass() != null) { |
78 | 0 | entryMap.set("attachmentTypesValuesFinderClass", entry.getAttachmentTypesValuesFinderClass().getName()); |
79 | |
} |
80 | |
|
81 | 0 | entryMap.set("displayTopicFieldInNotes", Boolean.toString(entry.getDisplayTopicFieldInNotes())); |
82 | |
|
83 | 0 | entryMap.set("usePessimisticLocking", Boolean.toString(entry.getUsePessimisticLocking())); |
84 | 0 | entryMap.set("useWorkflowPessimisticLocking", Boolean.toString(entry.getUseWorkflowPessimisticLocking())); |
85 | 0 | entryMap.set("sessionDocument", Boolean.toString(entry.isSessionDocument())); |
86 | |
|
87 | 0 | entryMap.set(new AttributesMapBuilder().buildAttributesMap(entry)); |
88 | 0 | entryMap.set(new CollectionsMapBuilder().buildCollectionsMap(entry)); |
89 | |
|
90 | |
|
91 | 0 | entryMap.set("maintenanceDocument", "true"); |
92 | 0 | entryMap.set("dataObjectClass", entry.getBusinessObjectClass().getName()); |
93 | 0 | entryMap.set("maintainableClass", entry.getMaintainableClass().getName()); |
94 | |
|
95 | |
|
96 | 0 | entryMap.set(buildMaintainableSectionsMap(entry)); |
97 | |
|
98 | 0 | return entryMap; |
99 | |
} |
100 | |
|
101 | |
private ExportMap buildMaintainableSectionsMap(MaintenanceDocumentEntry entry) { |
102 | 0 | ExportMap maintainableSectionsMap = new ExportMap("maintainableSections"); |
103 | |
|
104 | 0 | int index = 0; |
105 | 0 | for (Iterator i = entry.getMaintainableSections().iterator(); i.hasNext();) { |
106 | 0 | MaintainableSectionDefinition section = (MaintainableSectionDefinition) i.next(); |
107 | |
|
108 | 0 | maintainableSectionsMap.set(buildMaintainableSectionMap(section, index++)); |
109 | 0 | } |
110 | |
|
111 | 0 | return maintainableSectionsMap; |
112 | |
} |
113 | |
|
114 | |
private ExportMap buildMaintainableSectionMap(MaintainableSectionDefinition section, int index) { |
115 | 0 | ExportMap sectionMap = new ExportMap(Integer.toString(index)); |
116 | |
|
117 | 0 | sectionMap.set("index", Integer.toString(index)); |
118 | 0 | sectionMap.set("title", section.getTitle()); |
119 | |
|
120 | 0 | sectionMap.set(buildMaintainableItemsMap(section)); |
121 | |
|
122 | 0 | return sectionMap; |
123 | |
} |
124 | |
|
125 | |
private ExportMap buildMaintainableItemsMap(MaintainableSectionDefinition section) { |
126 | 0 | ExportMap itemsMap = new ExportMap("maintainableItems"); |
127 | |
|
128 | 0 | for (Iterator i = section.getMaintainableItems().iterator(); i.hasNext();) { |
129 | 0 | MaintainableItemDefinition item = (MaintainableItemDefinition) i.next(); |
130 | 0 | itemsMap.set(buildMaintainableItemMap(item)); |
131 | 0 | } |
132 | |
|
133 | 0 | return itemsMap; |
134 | |
} |
135 | |
|
136 | |
private ExportMap buildMaintainableItemMap(MaintainableItemDefinition item) { |
137 | 0 | ExportMap itemMap = new ExportMap(item.getName()); |
138 | |
|
139 | 0 | if (item instanceof MaintainableFieldDefinition) { |
140 | 0 | MaintainableFieldDefinition field = (MaintainableFieldDefinition) item; |
141 | |
|
142 | 0 | itemMap.set("field", "true"); |
143 | 0 | itemMap.set("name", field.getName()); |
144 | 0 | itemMap.set("required", Boolean.toString(field.isRequired())); |
145 | 0 | if (StringUtils.isNotBlank(field.getAlternateDisplayAttributeName())) { |
146 | 0 | itemMap.set("alternateDisplayAttributeName", field.getAlternateDisplayAttributeName()); |
147 | |
} |
148 | 0 | if (StringUtils.isNotBlank(field.getAdditionalDisplayAttributeName())) { |
149 | 0 | itemMap.set("additionalDisplayAttributeName", field.getAdditionalDisplayAttributeName()); |
150 | |
} |
151 | 0 | } |
152 | 0 | else if (item instanceof MaintainableCollectionDefinition) { |
153 | 0 | MaintainableCollectionDefinition collection = (MaintainableCollectionDefinition) item; |
154 | |
|
155 | 0 | itemMap.set("collection", "true"); |
156 | 0 | itemMap.set("name", collection.getName()); |
157 | 0 | itemMap.set("dataObjectClass", collection.getBusinessObjectClass().getName()); |
158 | 0 | } |
159 | 0 | else if (item instanceof MaintainableSubSectionHeaderDefinition) { |
160 | 0 | MaintainableSubSectionHeaderDefinition subSectionHeader = (MaintainableSubSectionHeaderDefinition) item; |
161 | 0 | itemMap.set("name", subSectionHeader.getName()); |
162 | 0 | } |
163 | |
else { |
164 | 0 | throw new IllegalStateException("unable to create itemMap for unknown MaintainableItem subclass '" + item.getClass().getName() + "'"); |
165 | |
} |
166 | |
|
167 | 0 | return itemMap; |
168 | |
} |
169 | |
} |