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