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 public MaintenanceDocumentEntryMapper() {
44 }
45
46
47
48
49
50
51 public ExportMap mapEntry(MaintenanceDocumentEntry entry) {
52
53 ExportMap entryMap = new ExportMap(entry.getJstlKey());
54
55 Class businessRulesClass = entry.getBusinessRulesClass();
56 if (businessRulesClass != null) {
57 entryMap.set("businessRulesClass", businessRulesClass.getName());
58 }
59
60 entryMap.set("documentTypeName", entry.getDocumentTypeName());
61
62 DocumentType docType = getDocumentType(entry.getDocumentTypeName());
63 entryMap.set("label", docType.getLabel());
64
65 if (docType.getDescription() != null) {
66 entryMap.set("description", docType.getDescription());
67 }
68
69 DocumentHelperService documentHelperService = KRADServiceLocatorWeb.getDocumentHelperService();
70 entryMap.set("documentAuthorizerClass", documentHelperService.getDocumentAuthorizer(entry.getDocumentTypeName()).getClass().getName());
71 entryMap.set("documentPresentationControllerClass", documentHelperService.getDocumentPresentationController(entry.getDocumentTypeName()).getClass().getName());
72
73 entryMap.set("allowsNoteAttachments", Boolean.toString(entry.getAllowsNoteAttachments()));
74
75 entryMap.set("allowsNoteFYI", Boolean.toString(entry.getAllowsNoteFYI()));
76
77 if (entry.getAttachmentTypesValuesFinderClass() != null) {
78 entryMap.set("attachmentTypesValuesFinderClass", entry.getAttachmentTypesValuesFinderClass().getName());
79 }
80
81 entryMap.set("displayTopicFieldInNotes", Boolean.toString(entry.getDisplayTopicFieldInNotes()));
82
83 entryMap.set("usePessimisticLocking", Boolean.toString(entry.getUsePessimisticLocking()));
84 entryMap.set("useWorkflowPessimisticLocking", Boolean.toString(entry.getUseWorkflowPessimisticLocking()));
85 entryMap.set("sessionDocument", Boolean.toString(entry.isSessionDocument()));
86
87 entryMap.set(new AttributesMapBuilder().buildAttributesMap(entry));
88 entryMap.set(new CollectionsMapBuilder().buildCollectionsMap(entry));
89
90
91 entryMap.set("maintenanceDocument", "true");
92 entryMap.set("dataObjectClass", entry.getBusinessObjectClass().getName());
93 entryMap.set("maintainableClass", entry.getMaintainableClass().getName());
94
95
96 entryMap.set(buildMaintainableSectionsMap(entry));
97
98 return entryMap;
99 }
100
101 private ExportMap buildMaintainableSectionsMap(MaintenanceDocumentEntry entry) {
102 ExportMap maintainableSectionsMap = new ExportMap("maintainableSections");
103
104 int index = 0;
105 for (Iterator i = entry.getMaintainableSections().iterator(); i.hasNext();) {
106 MaintainableSectionDefinition section = (MaintainableSectionDefinition) i.next();
107
108 maintainableSectionsMap.set(buildMaintainableSectionMap(section, index++));
109 }
110
111 return maintainableSectionsMap;
112 }
113
114 private ExportMap buildMaintainableSectionMap(MaintainableSectionDefinition section, int index) {
115 ExportMap sectionMap = new ExportMap(Integer.toString(index));
116
117 sectionMap.set("index", Integer.toString(index));
118 sectionMap.set("title", section.getTitle());
119
120 sectionMap.set(buildMaintainableItemsMap(section));
121
122 return sectionMap;
123 }
124
125 private ExportMap buildMaintainableItemsMap(MaintainableSectionDefinition section) {
126 ExportMap itemsMap = new ExportMap("maintainableItems");
127
128 for (Iterator i = section.getMaintainableItems().iterator(); i.hasNext();) {
129 MaintainableItemDefinition item = (MaintainableItemDefinition) i.next();
130 itemsMap.set(buildMaintainableItemMap(item));
131 }
132
133 return itemsMap;
134 }
135
136 private ExportMap buildMaintainableItemMap(MaintainableItemDefinition item) {
137 ExportMap itemMap = new ExportMap(item.getName());
138
139 if (item instanceof MaintainableFieldDefinition) {
140 MaintainableFieldDefinition field = (MaintainableFieldDefinition) item;
141
142 itemMap.set("field", "true");
143 itemMap.set("name", field.getName());
144 itemMap.set("required", Boolean.toString(field.isRequired()));
145 if (StringUtils.isNotBlank(field.getAlternateDisplayAttributeName())) {
146 itemMap.set("alternateDisplayAttributeName", field.getAlternateDisplayAttributeName());
147 }
148 if (StringUtils.isNotBlank(field.getAdditionalDisplayAttributeName())) {
149 itemMap.set("additionalDisplayAttributeName", field.getAdditionalDisplayAttributeName());
150 }
151 }
152 else if (item instanceof MaintainableCollectionDefinition) {
153 MaintainableCollectionDefinition collection = (MaintainableCollectionDefinition) item;
154
155 itemMap.set("collection", "true");
156 itemMap.set("name", collection.getName());
157 itemMap.set("dataObjectClass", collection.getBusinessObjectClass().getName());
158 }
159 else if (item instanceof MaintainableSubSectionHeaderDefinition) {
160 MaintainableSubSectionHeaderDefinition subSectionHeader = (MaintainableSubSectionHeaderDefinition) item;
161 itemMap.set("name", subSectionHeader.getName());
162 }
163 else {
164 throw new IllegalStateException("unable to create itemMap for unknown MaintainableItem subclass '" + item.getClass().getName() + "'");
165 }
166
167 return itemMap;
168 }
169 }