001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.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/ecl2.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 */ 016package org.kuali.rice.kns.datadictionary.exporter; 017 018import java.util.Iterator; 019 020import org.kuali.rice.kns.datadictionary.FieldDefinition; 021import org.kuali.rice.kns.datadictionary.LookupDefinition; 022import org.kuali.rice.kns.datadictionary.BusinessObjectEntry; 023import org.kuali.rice.krad.datadictionary.SortDefinition; 024import org.kuali.rice.krad.datadictionary.exporter.ExportMap; 025 026/** 027 * LookupMapBuilder 028 * 029 * @deprecated Only used by KNS classes, no replacement. 030 */ 031@Deprecated 032public class LookupMapBuilder { 033 034 /** 035 * Default constructor 036 */ 037 public LookupMapBuilder() { 038 } 039 040 041 /** 042 * @param entry 043 * @return ExportMap containing the standard entries for the given entry's LookupDefinition, or null if the given entry has no 044 * lookupDefinition 045 */ 046 public ExportMap buildLookupMap(BusinessObjectEntry entry) { 047 ExportMap lookupMap = null; 048 049 if (entry.hasLookupDefinition()) { 050 LookupDefinition lookupDefinition = entry.getLookupDefinition(); 051 lookupMap = new ExportMap("lookup"); 052 053 // simple properties 054 if (lookupDefinition.getLookupableID() != null) { 055 lookupMap.set("lookupableID", lookupDefinition.getLookupableID()); 056 } 057 058 lookupMap.set("title", lookupDefinition.getTitle()); 059 060 if (lookupDefinition.hasMenubar()) { 061 lookupMap.set("menubar", lookupDefinition.getMenubar()); 062 } 063 064 if (lookupDefinition.hasResultSetLimit()) { 065 lookupMap.set("resultSetLimit", lookupDefinition.getResultSetLimit().toString()); 066 } 067 // complex properties 068 lookupMap.setOptional(buildDefaultSortMap(lookupDefinition)); 069 lookupMap.set(buildLookupFieldsMap(lookupDefinition)); 070 lookupMap.set(buildResultFieldsMap(lookupDefinition)); 071 } 072 073 return lookupMap; 074 } 075 076 private ExportMap buildDefaultSortMap(LookupDefinition lookupDefinition) { 077 ExportMap defaultSortMap = null; 078 079 if (lookupDefinition.hasDefaultSort()) { 080 SortDefinition defaultSortDefinition = lookupDefinition.getDefaultSort(); 081 defaultSortMap = new ExportMap("defaultSort"); 082 083 defaultSortMap.set("sortAscending", Boolean.toString(defaultSortDefinition.getSortAscending())); 084 defaultSortMap.set(buildSortAttributesMap(defaultSortDefinition)); 085 } 086 087 return defaultSortMap; 088 } 089 090 private ExportMap buildSortAttributesMap(SortDefinition sortDefinition) { 091 ExportMap sortAttributesMap = new ExportMap("sortAttributes"); 092 093 for (Iterator i = sortDefinition.getAttributeNames().iterator(); i.hasNext();) { 094 String attributeName = (String) i.next(); 095 096 ExportMap attributeMap = new ExportMap(attributeName); 097 attributeMap.set("attributeName", attributeName); 098 099 sortAttributesMap.set(attributeMap); 100 } 101 102 return sortAttributesMap; 103 } 104 105 private ExportMap buildLookupFieldsMap(LookupDefinition lookupDefinition) { 106 ExportMap lookupFieldsMap = new ExportMap("lookupFields"); 107 108 for (Iterator i = lookupDefinition.getLookupFields().iterator(); i.hasNext();) { 109 FieldDefinition lookupField = (FieldDefinition) i.next(); 110 lookupFieldsMap.set(buildLookupFieldMap(lookupField)); 111 } 112 113 return lookupFieldsMap; 114 } 115 116 private ExportMap buildLookupFieldMap(FieldDefinition lookupField) { 117 ExportMap lookupFieldMap = new ExportMap(lookupField.getAttributeName()); 118 119 lookupFieldMap.set("attributeName", lookupField.getAttributeName()); 120 lookupFieldMap.set("required", Boolean.toString(lookupField.isRequired())); 121 122 return lookupFieldMap; 123 } 124 125 private ExportMap buildResultFieldsMap(LookupDefinition lookupDefinition) { 126 ExportMap resultFieldsMap = new ExportMap("resultFields"); 127 128 for (Iterator i = lookupDefinition.getResultFields().iterator(); i.hasNext();) { 129 FieldDefinition resultField = (FieldDefinition) i.next(); 130 resultFieldsMap.set(MapperUtils.buildFieldMap(resultField)); 131 } 132 133 return resultFieldsMap; 134 } 135 136}