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