View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.kns.service.DocumentHelperService;
29  import org.kuali.rice.kns.service.KNSServiceLocator;
30  import org.kuali.rice.krad.datadictionary.exporter.ExportMap;
31  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
32  
33  /**
34   * MaintenanceDocumentEntryMapper
35   * 
36   * @deprecated Only used by KNS classes, no replacement.
37   */
38  @Deprecated
39  public class MaintenanceDocumentEntryMapper extends DocumentEntryMapper {
40  
41      /**
42       * Default constructor
43       */
44      public MaintenanceDocumentEntryMapper() {
45      }
46  
47  
48      /**
49       * @param entry
50       * @return Map containing a String- and Map-based representation of the given entry
51       */
52      public ExportMap mapEntry(MaintenanceDocumentEntry entry) {
53           // simple properties
54          ExportMap entryMap = new ExportMap(entry.getJstlKey());
55  
56          Class businessRulesClass = entry.getBusinessRulesClass();
57          if (businessRulesClass != null) {
58              entryMap.set("businessRulesClass", businessRulesClass.getName());
59          }
60  
61          entryMap.set("documentTypeName", entry.getDocumentTypeName());
62  
63          DocumentType docType = getDocumentType(entry.getDocumentTypeName());
64          entryMap.set("label", docType.getLabel());
65  
66          if (docType.getDescription() != null) {
67              entryMap.set("description", docType.getDescription());
68          }
69  
70          DocumentHelperService documentHelperService = KNSServiceLocator.getDocumentHelperService();
71          entryMap.set("documentAuthorizerClass", documentHelperService.getDocumentAuthorizer(entry.getDocumentTypeName()).getClass().getName());
72          entryMap.set("documentPresentationControllerClass", documentHelperService.getDocumentPresentationController(entry.getDocumentTypeName()).getClass().getName());
73  
74          entryMap.set("allowsNoteAttachments", Boolean.toString(entry.getAllowsNoteAttachments()));
75  
76          entryMap.set("allowsNoteFYI", Boolean.toString(entry.getAllowsNoteFYI()));
77  
78          if (entry.getAttachmentTypesValuesFinderClass() != null) {
79              entryMap.set("attachmentTypesValuesFinderClass", entry.getAttachmentTypesValuesFinderClass().getName());
80          }
81  
82          entryMap.set("displayTopicFieldInNotes", Boolean.toString(entry.getDisplayTopicFieldInNotes()));
83  
84          entryMap.set("usePessimisticLocking", Boolean.toString(entry.getUsePessimisticLocking()));
85          entryMap.set("useWorkflowPessimisticLocking", Boolean.toString(entry.getUseWorkflowPessimisticLocking()));
86          entryMap.set("sessionDocument", Boolean.toString(entry.isSessionDocument()));
87  
88          entryMap.set(new AttributesMapBuilder().buildAttributesMap(entry));
89          entryMap.set(new CollectionsMapBuilder().buildCollectionsMap(entry));
90  
91          // simple properties
92          entryMap.set("maintenanceDocument", "true");
93          entryMap.set("dataObjectClass", entry.getBusinessObjectClass().getName());
94          entryMap.set("maintainableClass", entry.getMaintainableClass().getName());
95  
96          // complex properties
97          entryMap.set(buildMaintainableSectionsMap(entry));
98  
99          return entryMap;
100     }
101 
102     private ExportMap buildMaintainableSectionsMap(MaintenanceDocumentEntry entry) {
103         ExportMap maintainableSectionsMap = new ExportMap("maintainableSections");
104 
105         int index = 0;
106         for (Iterator i = entry.getMaintainableSections().iterator(); i.hasNext();) {
107             MaintainableSectionDefinition section = (MaintainableSectionDefinition) i.next();
108 
109             maintainableSectionsMap.set(buildMaintainableSectionMap(section, index++));
110         }
111 
112         return maintainableSectionsMap;
113     }
114 
115     private ExportMap buildMaintainableSectionMap(MaintainableSectionDefinition section, int index) {
116         ExportMap sectionMap = new ExportMap(Integer.toString(index));
117 
118         sectionMap.set("index", Integer.toString(index));
119         sectionMap.set("title", section.getTitle());
120 
121         sectionMap.set(buildMaintainableItemsMap(section));
122 
123         return sectionMap;
124     }
125 
126     private ExportMap buildMaintainableItemsMap(MaintainableSectionDefinition section) {
127         ExportMap itemsMap = new ExportMap("maintainableItems");
128 
129         for (Iterator i = section.getMaintainableItems().iterator(); i.hasNext();) {
130             MaintainableItemDefinition item = (MaintainableItemDefinition) i.next();
131             itemsMap.set(buildMaintainableItemMap(item));
132         }
133 
134         return itemsMap;
135     }
136 
137     private ExportMap buildMaintainableItemMap(MaintainableItemDefinition item) {
138         ExportMap itemMap = new ExportMap(item.getName());
139 
140         if (item instanceof MaintainableFieldDefinition) {
141             MaintainableFieldDefinition field = (MaintainableFieldDefinition) item;
142 
143             itemMap.set("field", "true");
144             itemMap.set("name", field.getName());
145             itemMap.set("required", Boolean.toString(field.isRequired()));
146 			if (StringUtils.isNotBlank(field.getAlternateDisplayAttributeName())) {
147 				itemMap.set("alternateDisplayAttributeName", field.getAlternateDisplayAttributeName());
148 			}
149 			if (StringUtils.isNotBlank(field.getAdditionalDisplayAttributeName())) {
150 				itemMap.set("additionalDisplayAttributeName", field.getAdditionalDisplayAttributeName());
151 			}
152         }
153         else if (item instanceof MaintainableCollectionDefinition) {
154             MaintainableCollectionDefinition collection = (MaintainableCollectionDefinition) item;
155 
156             itemMap.set("collection", "true");
157             itemMap.set("name", collection.getName());
158             itemMap.set("dataObjectClass", collection.getBusinessObjectClass().getName());
159         }
160         else if (item instanceof MaintainableSubSectionHeaderDefinition) {
161             MaintainableSubSectionHeaderDefinition subSectionHeader = (MaintainableSubSectionHeaderDefinition) item;
162             itemMap.set("name", subSectionHeader.getName());
163         }
164         else {
165             throw new IllegalStateException("unable to create itemMap for unknown MaintainableItem subclass '" + item.getClass().getName() + "'");
166         }
167 
168         return itemMap;
169     }
170 }