View Javadoc

1   /**
2    * Copyright 2005-2013 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.krad.datadictionary;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.log4j.Logger;
20  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
21  import org.kuali.rice.krad.service.ModuleService;
22  import org.kuali.rice.krad.uif.UifConstants;
23  import org.kuali.rice.krad.uif.view.View;
24  import org.springframework.beans.PropertyValues;
25  
26  import java.util.ArrayList;
27  import java.util.Collections;
28  import java.util.List;
29  import java.util.Map;
30  import java.util.Set;
31  
32  /**
33   * A DataDictionaryMapper that simply consults the statically initialized
34   * DataDictionaryIndex mappings
35   * 
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public class DataDictionaryIndexMapper implements DataDictionaryMapper {
39  	private static final Logger LOG = Logger.getLogger(DataDictionaryIndexMapper.class);
40  
41  	/**
42  	 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getAllInactivationBlockingMetadatas(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.Class)
43  	 */
44  	public Set<InactivationBlockingMetadata> getAllInactivationBlockingMetadatas(DataDictionaryIndex index, Class<?> blockedClass) {
45          return index.getInactivationBlockersForClass().get(blockedClass);
46  	}
47  
48  	/**
49  	 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getBusinessObjectClassNames(org.kuali.rice.krad.datadictionary.DataDictionaryIndex)
50  	 */
51  	public List<String> getBusinessObjectClassNames(DataDictionaryIndex index) {
52  		List classNames = new ArrayList();
53  		classNames.addAll(index.getBusinessObjectEntries().keySet());
54  
55  		return Collections.unmodifiableList(classNames);
56  	}
57  
58  	/**
59  	 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getBusinessObjectEntries(org.kuali.rice.krad.datadictionary.DataDictionaryIndex)
60  	 */
61  	public Map<String, BusinessObjectEntry> getBusinessObjectEntries(DataDictionaryIndex index) {
62  		return index.getBusinessObjectEntries();
63  	}
64  
65  	/**
66       * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDataObjectEntryForConcreteClass(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.String)
67       */
68  	@Override
69      public DataObjectEntry getDataObjectEntryForConcreteClass(DataDictionaryIndex ddIndex, String className) {
70  	    if (StringUtils.isBlank(className)) {
71              throw new IllegalArgumentException("invalid (blank) className");
72          }
73          if ( LOG.isDebugEnabled() ) {
74              LOG.debug("calling getDataObjectEntry '" + className + "'");
75          }
76          
77          String trimmedClassName = className;
78          int index = className.indexOf("$$");
79          if (index >= 0) {
80              trimmedClassName = className.substring(0, index);
81          }
82          return ddIndex.getDataObjectEntries().get(trimmedClassName);
83      }
84  
85      /**
86  	 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getBusinessObjectEntryForConcreteClass(java.lang.String)
87  	 */
88  	public BusinessObjectEntry getBusinessObjectEntryForConcreteClass(DataDictionaryIndex ddIndex, String className) {
89  		if (StringUtils.isBlank(className)) {
90  			throw new IllegalArgumentException("invalid (blank) className");
91  		}
92  		if ( LOG.isDebugEnabled() ) {
93  		    LOG.debug("calling getBusinessObjectEntry '" + className + "'");
94  		}
95  		int index = className.indexOf("$$");
96  		if (index >= 0) {
97  			className = className.substring(0, index);
98  		}
99  		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         // KULRICE-8005 Breaks when override business object classes
125         // check the BO list
126         if ( entry == null ) {
127             entry = getBusinessObjectEntry(ddIndex, className);
128         }
129         // check the document list
130         if ( entry == null ) {
131             entry = getDocumentEntry(ddIndex, className);
132         }
133 
134 		return entry;
135 	}
136 
137 	/**
138      * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDataObjectEntry(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.String)
139      */
140 	@Override
141     public DataObjectEntry getDataObjectEntry(DataDictionaryIndex index, String className) {
142 	    DataObjectEntry entry = getDataObjectEntryForConcreteClass(index, className);
143 	    
144         if (entry == null) {
145             Class<?> boClass = null;
146             try{
147                 boClass = Class.forName(className);
148                 ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass);
149                 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)) {
150                     entry = responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass);
151                 }
152             } catch(ClassNotFoundException cnfex){
153                 // swallow so we can return null
154             }
155         }
156         
157         return entry;
158     }
159 
160 	public BusinessObjectEntry getBusinessObjectEntry(DataDictionaryIndex index, String className ) {
161 		BusinessObjectEntry entry = getBusinessObjectEntryForConcreteClass(index, className);
162 		if (entry == null) {
163 			Class boClass = null;
164 			try{
165 				boClass = Class.forName(className);
166 				ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass);
167 				if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)) {
168 					return responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass);
169 				}
170 			} catch(ClassNotFoundException cnfex){
171 			}
172 			return null;
173 		}
174 		else {
175 			return entry;
176 		}
177 	}
178 	
179 	/**
180 	 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDocumentEntries(org.kuali.rice.krad.datadictionary.DataDictionaryIndex)
181 	 */
182 	public Map<String, DocumentEntry> getDocumentEntries(DataDictionaryIndex index) {
183 		return Collections.unmodifiableMap(index.getDocumentEntries());
184 	}
185 
186 	/**
187 	 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDocumentEntry(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.String)
188 	 */
189 	public DocumentEntry getDocumentEntry(DataDictionaryIndex index, String documentTypeDDKey) {
190 
191 		if (StringUtils.isBlank(documentTypeDDKey)) {
192 			throw new IllegalArgumentException("invalid (blank) documentTypeName");
193 		}
194 		if ( LOG.isDebugEnabled() ) {
195 		    LOG.debug("calling getDocumentEntry by documentTypeName '" + documentTypeDDKey + "'");
196 		}
197 
198 		DocumentEntry de = index.getDocumentEntries().get(documentTypeDDKey);	
199 		
200 		if ( de == null ) {
201 		    try {
202     		    Class<?> clazz = Class.forName( documentTypeDDKey );
203     		    de = index.getDocumentEntriesByBusinessObjectClass().get(clazz);
204     		    if ( de == null ) {
205     		        de = index.getDocumentEntriesByMaintainableClass().get(clazz);
206     		    }
207 		    } catch ( ClassNotFoundException ex ) {
208 		        LOG.warn( "Unable to find document entry for key: " + documentTypeDDKey );
209 		    }
210 		}
211 		
212         return de;
213 	}
214 
215 	/**
216 	 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDocumentTypeName(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.String)
217 	 */
218 	public String getDocumentTypeName(DataDictionaryIndex index,
219 			String documentTypeName) {
220 		// TODO arh14 - THIS METHOD NEEDS JAVADOCS
221 		return null;
222 	}
223 
224 	/**
225 	 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getMaintenanceDocumentEntryForBusinessObjectClass(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.Class)
226 	 */
227 	public MaintenanceDocumentEntry getMaintenanceDocumentEntryForBusinessObjectClass(DataDictionaryIndex index, Class<?> businessObjectClass) {
228 		if (businessObjectClass == null) {
229 			throw new IllegalArgumentException("invalid (null) dataObjectClass");
230 		}
231 		if ( LOG.isDebugEnabled() ) {
232 		    LOG.debug("calling getDocumentEntry by dataObjectClass '" + businessObjectClass + "'");
233 		}
234 
235 		return (MaintenanceDocumentEntry) index.getDocumentEntriesByBusinessObjectClass().get(businessObjectClass);
236 	}
237 	
238 	/**
239 	 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getViewById(org.kuali.rice.krad.datadictionary.view.ViewDictionaryIndex,
240 	 *      java.lang.String)
241 	 */
242 	public View getViewById(UifDictionaryIndex index, String viewId) {
243 		if (StringUtils.isBlank(viewId)) {
244 			throw new IllegalArgumentException("invalid (blank) view id");
245 		}
246 		if (LOG.isDebugEnabled()) {
247 			LOG.debug("calling getViewById by id '" + viewId + "'");
248 		}
249 
250 		return index.getViewById(viewId);
251 	}
252 
253 	/**
254 	 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getViewByTypeIndex(UifDictionaryIndex,
255 	 *      java.lang.String, java.util.Map)
256 	 */
257 	public View getViewByTypeIndex(UifDictionaryIndex index, UifConstants.ViewType viewTypeName, Map<String, String> indexKey) {
258 		if (viewTypeName == null) {
259 			throw new IllegalArgumentException("invalid (blank) view type name");
260 		}
261 		if ((indexKey == null) || indexKey.isEmpty()) {
262 			throw new IllegalArgumentException("index key must have at least one entry");
263 		}
264 
265 		return index.getViewByTypeIndex(viewTypeName, indexKey);
266 	}
267 
268     /**
269      * @see org.kuali.rice.krad.datadictionary.DataDictionaryIndexMapper#viewByTypeExist(UifDictionaryIndex,
270      *      java.lang.String, java.util.Map)
271      */
272     public boolean viewByTypeExist(UifDictionaryIndex index, UifConstants.ViewType viewTypeName,
273             Map<String, String> indexKey) {
274         if (viewTypeName == null) {
275             throw new IllegalArgumentException("invalid (blank) view type name");
276         }
277         if ((indexKey == null) || indexKey.isEmpty()) {
278             throw new IllegalArgumentException("index key must have at least one entry");
279         }
280 
281         return index.viewByTypeExist(viewTypeName, indexKey);
282     }
283 
284     /**
285      * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getViewPropertiesById(org.kuali.rice.krad.datadictionary.view.ViewDictionaryIndex,
286      *      java.lang.String)
287      */
288     public PropertyValues getViewPropertiesById(UifDictionaryIndex index, String viewId) {
289         if (StringUtils.isBlank(viewId)) {
290             throw new IllegalArgumentException("invalid (blank) view id");
291         }
292 
293         return index.getViewPropertiesById(viewId);
294     }
295 
296     /**
297      * @see org.kuali.rice.krad.datadictionary.DataDictionaryIndexMapper#getViewPropertiesByType(UifDictionaryIndex,
298      *      java.lang.String, java.util.Map)
299      */
300     public PropertyValues getViewPropertiesByType(UifDictionaryIndex index, UifConstants.ViewType viewTypeName,
301             Map<String, String> indexKey) {
302         if (viewTypeName == null) {
303             throw new IllegalArgumentException("invalid (blank) view type name");
304         }
305         if ((indexKey == null) || indexKey.isEmpty()) {
306             throw new IllegalArgumentException("index key must have at least one entry");
307         }
308 
309         return index.getViewPropertiesByType(viewTypeName, indexKey);
310     }
311 
312     /**
313 	 * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getViewsForType(UifDictionaryIndex,
314 	 *      java.lang.String)
315 	 */
316 	public List<View> getViewsForType(UifDictionaryIndex index, UifConstants.ViewType viewTypeName) {
317 		if (viewTypeName == null) {
318 			throw new IllegalArgumentException("invalid (blank) view type name");
319 		}
320 
321 		return index.getViewsForType(viewTypeName);
322 	}
323 
324 }