Coverage Report - org.kuali.rice.krad.datadictionary.DataDictionaryIndexMapper
 
Classes in this File Line Coverage Branch Coverage Complexity
DataDictionaryIndexMapper
0%
0/92
0%
0/58
3.867
 
 1  
 /*
 2  
  * Copyright 2007-2010 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.container.View;
 23  
 
 24  
 import java.util.ArrayList;
 25  
 import java.util.Collections;
 26  
 import java.util.List;
 27  
 import java.util.Map;
 28  
 import java.util.Set;
 29  
 
 30  
 /**
 31  
  * A DataDictionaryMapper that simply consults the statically initialized
 32  
  * DataDictionaryIndex mappings
 33  
  * 
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  */
 36  0
 public class DataDictionaryIndexMapper implements DataDictionaryMapper {
 37  0
         private static final Logger LOG = Logger.getLogger(DataDictionaryIndexMapper.class);
 38  
 
 39  
         /**
 40  
          * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getAllInactivationBlockingMetadatas(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.Class)
 41  
          */
 42  
         public Set<InactivationBlockingMetadata> getAllInactivationBlockingMetadatas(DataDictionaryIndex index, Class<?> blockedClass) {
 43  0
         return index.getInactivationBlockersForClass().get(blockedClass);
 44  
         }
 45  
 
 46  
         /**
 47  
          * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getBusinessObjectClassNames(org.kuali.rice.krad.datadictionary.DataDictionaryIndex)
 48  
          */
 49  
         public List<String> getBusinessObjectClassNames(DataDictionaryIndex index) {
 50  0
                 List classNames = new ArrayList();
 51  0
                 classNames.addAll(index.getBusinessObjectEntries().keySet());
 52  
 
 53  0
                 return Collections.unmodifiableList(classNames);
 54  
         }
 55  
 
 56  
         /**
 57  
          * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getBusinessObjectEntries(org.kuali.rice.krad.datadictionary.DataDictionaryIndex)
 58  
          */
 59  
         public Map<String, BusinessObjectEntry> getBusinessObjectEntries(DataDictionaryIndex index) {
 60  0
                 return index.getBusinessObjectEntries();
 61  
         }
 62  
 
 63  
         /**
 64  
      * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDataObjectEntryForConcreteClass(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.String)
 65  
      */
 66  
         @Override
 67  
     public DataObjectEntry getDataObjectEntryForConcreteClass(DataDictionaryIndex ddIndex, String className) {
 68  0
             if (StringUtils.isBlank(className)) {
 69  0
             throw new IllegalArgumentException("invalid (blank) className");
 70  
         }
 71  0
         if ( LOG.isDebugEnabled() ) {
 72  0
             LOG.debug("calling getDataObjectEntry '" + className + "'");
 73  
         }
 74  
         
 75  0
         String trimmedClassName = className;
 76  0
         int index = className.indexOf("$$");
 77  0
         if (index >= 0) {
 78  0
             trimmedClassName = className.substring(0, index);
 79  
         }
 80  0
         return ddIndex.getDataObjectEntries().get(trimmedClassName);
 81  
     }
 82  
 
 83  
     /**
 84  
          * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getBusinessObjectEntryForConcreteClass(java.lang.String)
 85  
          */
 86  
         public BusinessObjectEntry getBusinessObjectEntryForConcreteClass(DataDictionaryIndex ddIndex, String className) {
 87  0
                 if (StringUtils.isBlank(className)) {
 88  0
                         throw new IllegalArgumentException("invalid (blank) className");
 89  
                 }
 90  0
                 if ( LOG.isDebugEnabled() ) {
 91  0
                     LOG.debug("calling getBusinessObjectEntry '" + className + "'");
 92  
                 }
 93  0
                 int index = className.indexOf("$$");
 94  0
                 if (index >= 0) {
 95  0
                         className = className.substring(0, index);
 96  
                 }
 97  0
                 return ddIndex.getBusinessObjectEntries().get(className);
 98  
         }
 99  
 
 100  
         /**
 101  
          * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDictionaryObjectEntry(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.String)
 102  
          */
 103  
         public DataDictionaryEntry getDictionaryObjectEntry(DataDictionaryIndex ddIndex, String className) {
 104  0
                 if (StringUtils.isBlank(className)) {
 105  0
                         throw new IllegalArgumentException("invalid (blank) className");
 106  
                 }
 107  0
                 if ( LOG.isDebugEnabled() ) {
 108  0
                     LOG.debug("calling getDictionaryObjectEntry '" + className + "'");
 109  
                 }
 110  0
                 int index = className.indexOf("$$");
 111  0
                 if (index >= 0) {
 112  0
                         className = className.substring(0, index);
 113  
                 }
 114  
 
 115  
                 // look in the JSTL key cache
 116  0
                 DataDictionaryEntry entry = ddIndex.getEntriesByJstlKey().get(className);
 117  
                 
 118  
                 // check the Object list
 119  0
                 if (entry == null){
 120  0
                         entry = ddIndex.getDataObjectEntries().get(className);
 121  
                 }
 122  
                 // check the document list
 123  0
                 if ( entry == null ) {
 124  0
                     entry = getDocumentEntry(ddIndex, className);
 125  
                 }
 126  0
                 return entry;
 127  
         }
 128  
 
 129  
         /**
 130  
      * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDataObjectEntry(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.String)
 131  
      */
 132  
         @Override
 133  
     public DataObjectEntry getDataObjectEntry(DataDictionaryIndex index, String className) {
 134  0
             DataObjectEntry entry = getDataObjectEntryForConcreteClass(index, className);
 135  
             
 136  0
         if (entry == null) {
 137  0
             Class<?> boClass = null;
 138  
             try{
 139  0
                 boClass = Class.forName(className);
 140  0
                 ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass);
 141  0
                 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)) {
 142  0
                     entry = responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass);
 143  
                 }
 144  0
             } catch(ClassNotFoundException cnfex){
 145  
                 // swallow so we can return null
 146  0
             }
 147  
         }
 148  
         
 149  0
         return entry;
 150  
     }
 151  
 
 152  
         public BusinessObjectEntry getBusinessObjectEntry(DataDictionaryIndex index, String className ) {
 153  0
                 BusinessObjectEntry entry = getBusinessObjectEntryForConcreteClass(index, className);
 154  0
                 if (entry == null) {
 155  0
                         Class boClass = null;
 156  
                         try{
 157  0
                                 boClass = Class.forName(className);
 158  0
                                 ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass);
 159  0
                                 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)) {
 160  0
                                         return responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass);
 161  
                                 }
 162  0
                         } catch(ClassNotFoundException cnfex){
 163  0
                         }
 164  0
                         return null;
 165  
                 }
 166  
                 else {
 167  0
                         return entry;
 168  
                 }
 169  
         }
 170  
         
 171  
         /**
 172  
          * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDocumentEntries(org.kuali.rice.krad.datadictionary.DataDictionaryIndex)
 173  
          */
 174  
         public Map<String, DocumentEntry> getDocumentEntries(DataDictionaryIndex index) {
 175  0
                 return Collections.unmodifiableMap(index.getDocumentEntries());
 176  
         }
 177  
 
 178  
         /**
 179  
          * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDocumentEntry(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.String)
 180  
          */
 181  
         public DocumentEntry getDocumentEntry(DataDictionaryIndex index, String documentTypeDDKey) {
 182  
 
 183  0
                 if (StringUtils.isBlank(documentTypeDDKey)) {
 184  0
                         throw new IllegalArgumentException("invalid (blank) documentTypeName");
 185  
                 }
 186  0
                 if ( LOG.isDebugEnabled() ) {
 187  0
                     LOG.debug("calling getDocumentEntry by documentTypeName '" + documentTypeDDKey + "'");
 188  
                 }
 189  
 
 190  0
                 DocumentEntry de = index.getDocumentEntries().get(documentTypeDDKey);        
 191  
                 
 192  0
                 if ( de == null ) {
 193  
                     try {
 194  0
                         Class<?> clazz = Class.forName( documentTypeDDKey );
 195  0
                         de = index.getDocumentEntriesByBusinessObjectClass().get(clazz);
 196  0
                         if ( de == null ) {
 197  0
                             de = index.getDocumentEntriesByMaintainableClass().get(clazz);
 198  
                         }
 199  0
                     } catch ( ClassNotFoundException ex ) {
 200  0
                         LOG.warn( "Unable to find document entry for key: " + documentTypeDDKey );
 201  0
                     }
 202  
                 }
 203  
                 
 204  0
         return de;
 205  
         }
 206  
 
 207  
         /**
 208  
          * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getDocumentTypeName(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.String)
 209  
          */
 210  
         public String getDocumentTypeName(DataDictionaryIndex index,
 211  
                         String documentTypeName) {
 212  
                 // TODO arh14 - THIS METHOD NEEDS JAVADOCS
 213  0
                 return null;
 214  
         }
 215  
 
 216  
         /**
 217  
          * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getMaintenanceDocumentEntryForBusinessObjectClass(org.kuali.rice.krad.datadictionary.DataDictionaryIndex, java.lang.Class)
 218  
          */
 219  
         public MaintenanceDocumentEntry getMaintenanceDocumentEntryForBusinessObjectClass(DataDictionaryIndex index, Class<?> businessObjectClass) {
 220  0
                 if (businessObjectClass == null) {
 221  0
                         throw new IllegalArgumentException("invalid (null) dataObjectClass");
 222  
                 }
 223  0
                 if ( LOG.isDebugEnabled() ) {
 224  0
                     LOG.debug("calling getDocumentEntry by dataObjectClass '" + businessObjectClass + "'");
 225  
                 }
 226  
 
 227  0
                 return (MaintenanceDocumentEntry) index.getDocumentEntriesByBusinessObjectClass().get(businessObjectClass);
 228  
         }
 229  
         
 230  
         /**
 231  
          * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getViewById(org.kuali.rice.krad.datadictionary.view.ViewDictionaryIndex,
 232  
          *      java.lang.String)
 233  
          */
 234  
         public View getViewById(UifDictionaryIndex index, String viewId) {
 235  0
                 if (StringUtils.isBlank(viewId)) {
 236  0
                         throw new IllegalArgumentException("invalid (blank) view id");
 237  
                 }
 238  0
                 if (LOG.isDebugEnabled()) {
 239  0
                         LOG.debug("calling getViewById by id '" + viewId + "'");
 240  
                 }
 241  
 
 242  0
                 return index.getViewById(viewId);
 243  
         }
 244  
 
 245  
         /**
 246  
          * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getViewByTypeIndex(UifDictionaryIndex,
 247  
          *      java.lang.String, java.util.Map)
 248  
          */
 249  
         public View getViewByTypeIndex(UifDictionaryIndex index, String viewTypeName, Map<String, String> indexKey) {
 250  0
                 if (StringUtils.isBlank(viewTypeName)) {
 251  0
                         throw new IllegalArgumentException("invalid (blank) view type name");
 252  
                 }
 253  0
                 if ((indexKey == null) || indexKey.isEmpty()) {
 254  0
                         throw new IllegalArgumentException("index key must have at least one entry");
 255  
                 }
 256  
 
 257  0
                 return index.getViewByTypeIndex(viewTypeName, indexKey);
 258  
         }
 259  
 
 260  
         /**
 261  
          * @see org.kuali.rice.krad.datadictionary.DataDictionaryMapper#getViewsForType(UifDictionaryIndex,
 262  
          *      java.lang.String)
 263  
          */
 264  
         public List<View> getViewsForType(UifDictionaryIndex index, String viewTypeName) {
 265  0
                 if (StringUtils.isBlank(viewTypeName)) {
 266  0
                         throw new IllegalArgumentException("invalid (blank) view type name");
 267  
                 }
 268  
 
 269  0
                 return index.getViewsForType(viewTypeName);
 270  
         }
 271  
 
 272  
 }