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.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.view.ViewDictionaryIndex,
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#getViewByTypeIndex(UifDictionaryIndex,
268      *      java.lang.String, java.util.Map)
269      */
270     public View getViewByTypeIndex(UifDictionaryIndex index, UifConstants.ViewType viewTypeName,
271             Map<String, String> indexKey) {
272         if (viewTypeName == null) {
273             throw new IllegalArgumentException("invalid (blank) view type name");
274         }
275         if ((indexKey == null) || indexKey.isEmpty()) {
276             throw new IllegalArgumentException("index key must have at least one entry");
277         }
278 
279         return index.getViewByTypeIndex(viewTypeName, indexKey);
280     }
281 
282     /**
283      * @see org.kuali.rice.krad.datadictionary.DataDictionaryIndexMapper#viewByTypeExist(UifDictionaryIndex,
284      *      java.lang.String, java.util.Map)
285      */
286     public boolean viewByTypeExist(UifDictionaryIndex index, UifConstants.ViewType viewTypeName,
287             Map<String, String> indexKey) {
288         if (viewTypeName == null) {
289             throw new IllegalArgumentException("invalid (blank) view type name");
290         }
291         if ((indexKey == null) || indexKey.isEmpty()) {
292             throw new IllegalArgumentException("index key must have at least one entry");
293         }
294 
295         return index.viewByTypeExist(viewTypeName, indexKey);
296     }
297 
298     /**
299      * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getViewPropertiesById(org.kuali.rice.krad.datadictionary.view.ViewDictionaryIndex,
300      *      java.lang.String)
301      */
302     public PropertyValues getViewPropertiesById(UifDictionaryIndex index, String viewId) {
303         if (StringUtils.isBlank(viewId)) {
304             throw new IllegalArgumentException("invalid (blank) view id");
305         }
306 
307         return index.getViewPropertiesById(viewId);
308     }
309 
310     /**
311      * @see org.kuali.rice.krad.datadictionary.DataDictionaryIndexMapper#getViewPropertiesByType(UifDictionaryIndex,
312      *      java.lang.String, java.util.Map)
313      */
314     public PropertyValues getViewPropertiesByType(UifDictionaryIndex index, UifConstants.ViewType viewTypeName,
315             Map<String, String> indexKey) {
316         if (viewTypeName == null) {
317             throw new IllegalArgumentException("invalid (blank) view type name");
318         }
319         if ((indexKey == null) || indexKey.isEmpty()) {
320             throw new IllegalArgumentException("index key must have at least one entry");
321         }
322 
323         return index.getViewPropertiesByType(viewTypeName, indexKey);
324     }
325 
326     /**
327      * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getViewsForType(UifDictionaryIndex,
328      *      java.lang.String)
329      */
330     public List<View> getViewsForType(UifDictionaryIndex index, UifConstants.ViewType viewTypeName) {
331         if (viewTypeName == null) {
332             throw new IllegalArgumentException("invalid (blank) view type name");
333         }
334 
335         return index.getViewsForType(viewTypeName);
336     }
337 
338 }