Coverage Report - org.kuali.rice.krad.datadictionary.DataDictionaryIndexMapper
 
Classes in this File Line Coverage Branch Coverage Complexity
DataDictionaryIndexMapper
1%
2/105
0%
0/72
4.056
 
 1  
 /**
 2  
  * Copyright 2005-2011 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  5
 public class DataDictionaryIndexMapper implements DataDictionaryMapper {
 39  1
         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  0
         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  0
                 List classNames = new ArrayList();
 53  0
                 classNames.addAll(index.getBusinessObjectEntries().keySet());
 54  
 
 55  0
                 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  0
                 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  0
             if (StringUtils.isBlank(className)) {
 71  0
             throw new IllegalArgumentException("invalid (blank) className");
 72  
         }
 73  0
         if ( LOG.isDebugEnabled() ) {
 74  0
             LOG.debug("calling getDataObjectEntry '" + className + "'");
 75  
         }
 76  
         
 77  0
         String trimmedClassName = className;
 78  0
         int index = className.indexOf("$$");
 79  0
         if (index >= 0) {
 80  0
             trimmedClassName = className.substring(0, index);
 81  
         }
 82  0
         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  0
                 if (StringUtils.isBlank(className)) {
 90  0
                         throw new IllegalArgumentException("invalid (blank) className");
 91  
                 }
 92  0
                 if ( LOG.isDebugEnabled() ) {
 93  0
                     LOG.debug("calling getBusinessObjectEntry '" + className + "'");
 94  
                 }
 95  0
                 int index = className.indexOf("$$");
 96  0
                 if (index >= 0) {
 97  0
                         className = className.substring(0, index);
 98  
                 }
 99  0
                 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  0
                 if (StringUtils.isBlank(className)) {
 107  0
                         throw new IllegalArgumentException("invalid (blank) className");
 108  
                 }
 109  0
                 if ( LOG.isDebugEnabled() ) {
 110  0
                     LOG.debug("calling getDictionaryObjectEntry '" + className + "'");
 111  
                 }
 112  0
                 int index = className.indexOf("$$");
 113  0
                 if (index >= 0) {
 114  0
                         className = className.substring(0, index);
 115  
                 }
 116  
 
 117  
                 // look in the JSTL key cache
 118  0
                 DataDictionaryEntry entry = ddIndex.getEntriesByJstlKey().get(className);
 119  
                 
 120  
                 // check the Object list
 121  0
                 if (entry == null){
 122  0
                         entry = ddIndex.getDataObjectEntries().get(className);
 123  
                 }
 124  
                 // check the document list
 125  0
                 if ( entry == null ) {
 126  0
                     entry = getDocumentEntry(ddIndex, className);
 127  
                 }
 128  0
                 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  0
             DataObjectEntry entry = getDataObjectEntryForConcreteClass(index, className);
 137  
             
 138  0
         if (entry == null) {
 139  0
             Class<?> boClass = null;
 140  
             try{
 141  0
                 boClass = Class.forName(className);
 142  0
                 ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass);
 143  0
                 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)) {
 144  0
                     entry = responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass);
 145  
                 }
 146  0
             } catch(ClassNotFoundException cnfex){
 147  
                 // swallow so we can return null
 148  0
             }
 149  
         }
 150  
         
 151  0
         return entry;
 152  
     }
 153  
 
 154  
         public BusinessObjectEntry getBusinessObjectEntry(DataDictionaryIndex index, String className ) {
 155  0
                 BusinessObjectEntry entry = getBusinessObjectEntryForConcreteClass(index, className);
 156  0
                 if (entry == null) {
 157  0
                         Class boClass = null;
 158  
                         try{
 159  0
                                 boClass = Class.forName(className);
 160  0
                                 ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass);
 161  0
                                 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)) {
 162  0
                                         return responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass);
 163  
                                 }
 164  0
                         } catch(ClassNotFoundException cnfex){
 165  0
                         }
 166  0
                         return null;
 167  
                 }
 168  
                 else {
 169  0
                         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  0
                 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  0
                 if (StringUtils.isBlank(documentTypeDDKey)) {
 186  0
                         throw new IllegalArgumentException("invalid (blank) documentTypeName");
 187  
                 }
 188  0
                 if ( LOG.isDebugEnabled() ) {
 189  0
                     LOG.debug("calling getDocumentEntry by documentTypeName '" + documentTypeDDKey + "'");
 190  
                 }
 191  
 
 192  0
                 DocumentEntry de = index.getDocumentEntries().get(documentTypeDDKey);        
 193  
                 
 194  0
                 if ( de == null ) {
 195  
                     try {
 196  0
                         Class<?> clazz = Class.forName( documentTypeDDKey );
 197  0
                         de = index.getDocumentEntriesByBusinessObjectClass().get(clazz);
 198  0
                         if ( de == null ) {
 199  0
                             de = index.getDocumentEntriesByMaintainableClass().get(clazz);
 200  
                         }
 201  0
                     } catch ( ClassNotFoundException ex ) {
 202  0
                         LOG.warn( "Unable to find document entry for key: " + documentTypeDDKey );
 203  0
                     }
 204  
                 }
 205  
                 
 206  0
         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  0
                 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  0
                 if (businessObjectClass == null) {
 223  0
                         throw new IllegalArgumentException("invalid (null) dataObjectClass");
 224  
                 }
 225  0
                 if ( LOG.isDebugEnabled() ) {
 226  0
                     LOG.debug("calling getDocumentEntry by dataObjectClass '" + businessObjectClass + "'");
 227  
                 }
 228  
 
 229  0
                 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  0
                 if (StringUtils.isBlank(viewId)) {
 238  0
                         throw new IllegalArgumentException("invalid (blank) view id");
 239  
                 }
 240  0
                 if (LOG.isDebugEnabled()) {
 241  0
                         LOG.debug("calling getViewById by id '" + viewId + "'");
 242  
                 }
 243  
 
 244  0
                 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  0
                 if (viewTypeName == null) {
 253  0
                         throw new IllegalArgumentException("invalid (blank) view type name");
 254  
                 }
 255  0
                 if ((indexKey == null) || indexKey.isEmpty()) {
 256  0
                         throw new IllegalArgumentException("index key must have at least one entry");
 257  
                 }
 258  
 
 259  0
                 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  0
         if (viewTypeName == null) {
 269  0
             throw new IllegalArgumentException("invalid (blank) view type name");
 270  
         }
 271  0
         if ((indexKey == null) || indexKey.isEmpty()) {
 272  0
             throw new IllegalArgumentException("index key must have at least one entry");
 273  
         }
 274  
 
 275  0
         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  0
         if (StringUtils.isBlank(viewId)) {
 284  0
             throw new IllegalArgumentException("invalid (blank) view id");
 285  
         }
 286  
 
 287  0
         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  0
         if (viewTypeName == null) {
 297  0
             throw new IllegalArgumentException("invalid (blank) view type name");
 298  
         }
 299  0
         if ((indexKey == null) || indexKey.isEmpty()) {
 300  0
             throw new IllegalArgumentException("index key must have at least one entry");
 301  
         }
 302  
 
 303  0
         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  0
                 if (viewTypeName == null) {
 312  0
                         throw new IllegalArgumentException("invalid (blank) view type name");
 313  
                 }
 314  
 
 315  0
                 return index.getViewsForType(viewTypeName);
 316  
         }
 317  
 
 318  
 }