001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.datadictionary.exporter;
017:
018: import java.util.Iterator;
019: import java.util.Map;
020:
021: import org.kuali.core.datadictionary.AuthorizationDefinition;
022: import org.kuali.core.datadictionary.DocumentEntry;
023:
024: /**
025: * DocumentEntryMapper
026: *
027: *
028: */
029: public abstract class DocumentEntryMapper {
030: /**
031: * @param entry
032: * @return Map containing entries for properties common to all DocumentEntry subclasses
033: */
034: protected ExportMap mapEntry(DocumentEntry entry) {
035: if (entry == null) {
036: throw new IllegalArgumentException("invalid (null) entry");
037: }
038:
039: // simple properties
040: ExportMap entryMap = new ExportMap(entry.getJstlKey());
041:
042: Class businessRulesClass = entry.getBusinessRulesClass();
043: if (businessRulesClass != null) {
044: entryMap.set("businessRulesClass", businessRulesClass
045: .getName());
046: }
047:
048: entryMap.set("documentTypeName", entry.getDocumentTypeName());
049: entryMap.set("documentTypeCode", entry.getDocumentTypeCode());
050:
051: entryMap.set("label", entry.getLabel());
052: entryMap.set("shortLabel", entry.getShortLabel());
053:
054: if (entry.getSummary() != null) {
055: entryMap.set("summary", entry.getSummary());
056: }
057: if (entry.getDescription() != null) {
058: entryMap.set("description", entry.getDescription());
059: }
060:
061: entryMap.set("documentAuthorizerClass", entry
062: .getDocumentAuthorizerClass().getName());
063:
064: entryMap.set("allowsNoteDelete", Boolean.toString(entry
065: .getAllowsNoteDelete()));
066:
067: if (entry.getAttachmentTypeValuesFinderClass() != null) {
068: entryMap.set("attachmentTypesValuesFinderClass", entry
069: .getAttachmentTypeValuesFinderClass().getName());
070: }
071:
072: entryMap.set("displayTopicFieldInNotes", Boolean.toString(entry
073: .getDisplayTopicFieldInNotes()));
074:
075: entryMap.set(new AttributesMapBuilder()
076: .buildAttributesMap(entry));
077: entryMap.set(new CollectionsMapBuilder()
078: .buildCollectionsMap(entry));
079:
080: // complex properties
081: entryMap.setOptional(buildAuthorizationsMap(entry));
082:
083: return entryMap;
084: }
085:
086: private ExportMap buildAuthorizationsMap(DocumentEntry entry) {
087: ExportMap authorizationsMap = null;
088:
089: Map authorizationDefinitions = entry
090: .getAuthorizationDefinitions();
091: if ((authorizationDefinitions != null)
092: && !authorizationDefinitions.isEmpty()) {
093: authorizationsMap = new ExportMap("authorizations");
094:
095: for (Iterator i = authorizationDefinitions.entrySet()
096: .iterator(); i.hasNext();) {
097: Map.Entry e = (Map.Entry) i.next();
098:
099: String authAction = (String) e.getKey();
100: AuthorizationDefinition authorizationDefinition = (AuthorizationDefinition) e
101: .getValue();
102:
103: authorizationsMap
104: .set(buildAuthorizationMap(authorizationDefinition));
105: }
106: }
107:
108: return authorizationsMap;
109: }
110:
111: private ExportMap buildAuthorizationMap(
112: AuthorizationDefinition authorizationDefinition) {
113: ExportMap authorizationMap = new ExportMap(
114: authorizationDefinition.getAction());
115:
116: int index = 0;
117: for (Iterator i = authorizationDefinition.getGroupNames()
118: .iterator(); i.hasNext();) {
119: String groupName = (String) i.next();
120:
121: ExportMap workgroupsMap = new ExportMap("workgroups");
122: workgroupsMap.set(Integer.toString(index++), groupName);
123:
124: authorizationMap.set(workgroupsMap);
125: }
126:
127: return authorizationMap;
128: }
129:
130: }
|