001 /** 002 * Copyright 2005-2012 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 */ 016 package org.kuali.rice.krad.datadictionary; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.apache.log4j.Logger; 020 import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 021 import org.kuali.rice.krad.service.ModuleService; 022 import org.kuali.rice.krad.uif.UifConstants; 023 import org.kuali.rice.krad.uif.view.View; 024 import org.springframework.beans.PropertyValues; 025 026 import java.util.ArrayList; 027 import java.util.Collections; 028 import java.util.List; 029 import java.util.Map; 030 import java.util.Set; 031 032 /** 033 * A DataDictionaryMapper that simply consults the statically initialized 034 * DataDictionaryIndex mappings 035 * 036 * @author Kuali Rice Team (rice.collab@kuali.org) 037 */ 038 public class DataDictionaryIndexMapper implements DataDictionaryMapper { 039 private static final Logger LOG = Logger.getLogger(DataDictionaryIndexMapper.class); 040 041 /** 042 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getAllInactivationBlockingMetadatas(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.Class) 043 */ 044 public Set<InactivationBlockingMetadata> getAllInactivationBlockingMetadatas(DataDictionaryIndex index, Class<?> blockedClass) { 045 return index.getInactivationBlockersForClass().get(blockedClass); 046 } 047 048 /** 049 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getBusinessObjectClassNames(org.kuali.rice.krad.datadictionary.DataDictionaryIndex) 050 */ 051 public List<String> getBusinessObjectClassNames(DataDictionaryIndex index) { 052 List classNames = new ArrayList(); 053 classNames.addAll(index.getBusinessObjectEntries().keySet()); 054 055 return Collections.unmodifiableList(classNames); 056 } 057 058 /** 059 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getBusinessObjectEntries(org.kuali.rice.krad.datadictionary.DataDictionaryIndex) 060 */ 061 public Map<String, BusinessObjectEntry> getBusinessObjectEntries(DataDictionaryIndex index) { 062 return index.getBusinessObjectEntries(); 063 } 064 065 /** 066 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDataObjectEntryForConcreteClass(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.String) 067 */ 068 @Override 069 public DataObjectEntry getDataObjectEntryForConcreteClass(DataDictionaryIndex ddIndex, String className) { 070 if (StringUtils.isBlank(className)) { 071 throw new IllegalArgumentException("invalid (blank) className"); 072 } 073 if ( LOG.isDebugEnabled() ) { 074 LOG.debug("calling getDataObjectEntry '" + className + "'"); 075 } 076 077 String trimmedClassName = className; 078 int index = className.indexOf("$$"); 079 if (index >= 0) { 080 trimmedClassName = className.substring(0, index); 081 } 082 return ddIndex.getDataObjectEntries().get(trimmedClassName); 083 } 084 085 /** 086 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getBusinessObjectEntryForConcreteClass(java.lang.String) 087 */ 088 public BusinessObjectEntry getBusinessObjectEntryForConcreteClass(DataDictionaryIndex ddIndex, String className) { 089 if (StringUtils.isBlank(className)) { 090 throw new IllegalArgumentException("invalid (blank) className"); 091 } 092 if ( LOG.isDebugEnabled() ) { 093 LOG.debug("calling getBusinessObjectEntry '" + className + "'"); 094 } 095 int index = className.indexOf("$$"); 096 if (index >= 0) { 097 className = className.substring(0, index); 098 } 099 return ddIndex.getBusinessObjectEntries().get(className); 100 } 101 102 /** 103 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDictionaryObjectEntry(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.String) 104 */ 105 public DataDictionaryEntry getDictionaryObjectEntry(DataDictionaryIndex ddIndex, String className) { 106 if (StringUtils.isBlank(className)) { 107 throw new IllegalArgumentException("invalid (blank) className"); 108 } 109 if ( LOG.isDebugEnabled() ) { 110 LOG.debug("calling getDictionaryObjectEntry '" + className + "'"); 111 } 112 int index = className.indexOf("$$"); 113 if (index >= 0) { 114 className = className.substring(0, index); 115 } 116 117 // look in the JSTL key cache 118 DataDictionaryEntry entry = ddIndex.getEntriesByJstlKey().get(className); 119 120 // check the Object list 121 if (entry == null){ 122 entry = ddIndex.getDataObjectEntries().get(className); 123 } 124 // check the document list 125 if ( entry == null ) { 126 entry = getDocumentEntry(ddIndex, className); 127 } 128 return entry; 129 } 130 131 /** 132 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDataObjectEntry(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.String) 133 */ 134 @Override 135 public DataObjectEntry getDataObjectEntry(DataDictionaryIndex index, String className) { 136 DataObjectEntry entry = getDataObjectEntryForConcreteClass(index, className); 137 138 if (entry == null) { 139 Class<?> boClass = null; 140 try{ 141 boClass = Class.forName(className); 142 ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass); 143 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)) { 144 entry = responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass); 145 } 146 } catch(ClassNotFoundException cnfex){ 147 // swallow so we can return null 148 } 149 } 150 151 return entry; 152 } 153 154 public BusinessObjectEntry getBusinessObjectEntry(DataDictionaryIndex index, String className ) { 155 BusinessObjectEntry entry = getBusinessObjectEntryForConcreteClass(index, className); 156 if (entry == null) { 157 Class boClass = null; 158 try{ 159 boClass = Class.forName(className); 160 ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass); 161 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)) { 162 return responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass); 163 } 164 } catch(ClassNotFoundException cnfex){ 165 } 166 return null; 167 } 168 else { 169 return entry; 170 } 171 } 172 173 /** 174 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDocumentEntries(org.kuali.rice.krad.datadictionary.DataDictionaryIndex) 175 */ 176 public Map<String, DocumentEntry> getDocumentEntries(DataDictionaryIndex index) { 177 return Collections.unmodifiableMap(index.getDocumentEntries()); 178 } 179 180 /** 181 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDocumentEntry(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.String) 182 */ 183 public DocumentEntry getDocumentEntry(DataDictionaryIndex index, String documentTypeDDKey) { 184 185 if (StringUtils.isBlank(documentTypeDDKey)) { 186 throw new IllegalArgumentException("invalid (blank) documentTypeName"); 187 } 188 if ( LOG.isDebugEnabled() ) { 189 LOG.debug("calling getDocumentEntry by documentTypeName '" + documentTypeDDKey + "'"); 190 } 191 192 DocumentEntry de = index.getDocumentEntries().get(documentTypeDDKey); 193 194 if ( de == null ) { 195 try { 196 Class<?> clazz = Class.forName( documentTypeDDKey ); 197 de = index.getDocumentEntriesByBusinessObjectClass().get(clazz); 198 if ( de == null ) { 199 de = index.getDocumentEntriesByMaintainableClass().get(clazz); 200 } 201 } catch ( ClassNotFoundException ex ) { 202 LOG.warn( "Unable to find document entry for key: " + documentTypeDDKey ); 203 } 204 } 205 206 return de; 207 } 208 209 /** 210 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDocumentTypeName(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.String) 211 */ 212 public String getDocumentTypeName(DataDictionaryIndex index, 213 String documentTypeName) { 214 // TODO arh14 - THIS METHOD NEEDS JAVADOCS 215 return null; 216 } 217 218 /** 219 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getMaintenanceDocumentEntryForBusinessObjectClass(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.Class) 220 */ 221 public MaintenanceDocumentEntry getMaintenanceDocumentEntryForBusinessObjectClass(DataDictionaryIndex index, Class<?> businessObjectClass) { 222 if (businessObjectClass == null) { 223 throw new IllegalArgumentException("invalid (null) dataObjectClass"); 224 } 225 if ( LOG.isDebugEnabled() ) { 226 LOG.debug("calling getDocumentEntry by dataObjectClass '" + businessObjectClass + "'"); 227 } 228 229 return (MaintenanceDocumentEntry) index.getDocumentEntriesByBusinessObjectClass().get(businessObjectClass); 230 } 231 232 /** 233 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getViewById(org.kuali.rice.krad.datadictionary.view.ViewDictionaryIndex, 234 * java.lang.String) 235 */ 236 public View getViewById(UifDictionaryIndex index, String viewId) { 237 if (StringUtils.isBlank(viewId)) { 238 throw new IllegalArgumentException("invalid (blank) view id"); 239 } 240 if (LOG.isDebugEnabled()) { 241 LOG.debug("calling getViewById by id '" + viewId + "'"); 242 } 243 244 return index.getViewById(viewId); 245 } 246 247 /** 248 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getViewByTypeIndex(UifDictionaryIndex, 249 * java.lang.String, java.util.Map) 250 */ 251 public View getViewByTypeIndex(UifDictionaryIndex index, UifConstants.ViewType viewTypeName, Map<String, String> indexKey) { 252 if (viewTypeName == null) { 253 throw new IllegalArgumentException("invalid (blank) view type name"); 254 } 255 if ((indexKey == null) || indexKey.isEmpty()) { 256 throw new IllegalArgumentException("index key must have at least one entry"); 257 } 258 259 return index.getViewByTypeIndex(viewTypeName, indexKey); 260 } 261 262 /** 263 * @see org.kuali.rice.krad.datadictionary.DataDictionaryIndexMapper#viewByTypeExist(UifDictionaryIndex, 264 * java.lang.String, java.util.Map) 265 */ 266 public boolean viewByTypeExist(UifDictionaryIndex index, UifConstants.ViewType viewTypeName, 267 Map<String, String> indexKey) { 268 if (viewTypeName == null) { 269 throw new IllegalArgumentException("invalid (blank) view type name"); 270 } 271 if ((indexKey == null) || indexKey.isEmpty()) { 272 throw new IllegalArgumentException("index key must have at least one entry"); 273 } 274 275 return index.viewByTypeExist(viewTypeName, indexKey); 276 } 277 278 /** 279 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getViewPropertiesById(org.kuali.rice.krad.datadictionary.view.ViewDictionaryIndex, 280 * java.lang.String) 281 */ 282 public PropertyValues getViewPropertiesById(UifDictionaryIndex index, String viewId) { 283 if (StringUtils.isBlank(viewId)) { 284 throw new IllegalArgumentException("invalid (blank) view id"); 285 } 286 287 return index.getViewPropertiesById(viewId); 288 } 289 290 /** 291 * @see org.kuali.rice.krad.datadictionary.DataDictionaryIndexMapper#getViewPropertiesByType(UifDictionaryIndex, 292 * java.lang.String, java.util.Map) 293 */ 294 public PropertyValues getViewPropertiesByType(UifDictionaryIndex index, UifConstants.ViewType viewTypeName, 295 Map<String, String> indexKey) { 296 if (viewTypeName == null) { 297 throw new IllegalArgumentException("invalid (blank) view type name"); 298 } 299 if ((indexKey == null) || indexKey.isEmpty()) { 300 throw new IllegalArgumentException("index key must have at least one entry"); 301 } 302 303 return index.getViewPropertiesByType(viewTypeName, indexKey); 304 } 305 306 /** 307 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getViewsForType(UifDictionaryIndex, 308 * java.lang.String) 309 */ 310 public List<View> getViewsForType(UifDictionaryIndex index, UifConstants.ViewType viewTypeName) { 311 if (viewTypeName == null) { 312 throw new IllegalArgumentException("invalid (blank) view type name"); 313 } 314 315 return index.getViewsForType(viewTypeName); 316 } 317 318 }