Coverage Report - org.kuali.rice.kns.service.impl.RiceApplicationConfigurationServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RiceApplicationConfigurationServiceImpl
0%
0/77
0%
0/52
3.4
 
 1  
 /*
 2  
  * Copyright 2005-2009 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in
 5  
  * compliance with the License. You may obtain a copy of the License at
 6  
  * 
 7  
  * http://www.opensource.org/licenses/ecl2.php
 8  
  * 
 9  
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS
 10  
  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
 11  
  * language governing permissions and limitations under the License.
 12  
  */
 13  
 package org.kuali.rice.kns.service.impl;
 14  
 
 15  
 import java.util.ArrayList;
 16  
 import java.util.Collections;
 17  
 import java.util.HashMap;
 18  
 import java.util.List;
 19  
 import java.util.Map;
 20  
 
 21  
 import org.kuali.rice.kns.bo.BusinessObject;
 22  
 import org.kuali.rice.kns.bo.ParameterDetailType;
 23  
 import org.kuali.rice.kns.datadictionary.AttributeDefinition;
 24  
 import org.kuali.rice.kns.datadictionary.BusinessObjectEntry;
 25  
 import org.kuali.rice.kns.datadictionary.DocumentEntry;
 26  
 import org.kuali.rice.kns.datadictionary.TransactionalDocumentEntry;
 27  
 import org.kuali.rice.kns.document.TransactionalDocument;
 28  
 import org.kuali.rice.kns.lookup.LookupUtils;
 29  
 import org.kuali.rice.kns.service.DataDictionaryService;
 30  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 31  
 import org.kuali.rice.kns.service.KualiConfigurationService;
 32  
 import org.kuali.rice.kns.service.ParameterService;
 33  
 import org.kuali.rice.kns.service.RiceApplicationConfigurationService;
 34  
 import org.kuali.rice.kns.service.ParameterConstants.COMPONENT;
 35  
 import org.kuali.rice.kns.util.KNSConstants;
 36  
 import org.kuali.rice.kns.util.KNSUtils;
 37  
 
 38  
 //@Transactional
 39  0
 public class RiceApplicationConfigurationServiceImpl implements RiceApplicationConfigurationService {
 40  0
     private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RiceApplicationConfigurationServiceImpl.class);
 41  
     
 42  0
     protected List<ParameterDetailType> components = new ArrayList<ParameterDetailType>();
 43  0
     protected List<String> packagePrefixes = new ArrayList<String>();
 44  
     private KualiConfigurationService kualiConfigurationService;
 45  
     private ParameterService parameterService;    
 46  
     private DataDictionaryService dataDictionaryService;
 47  
     
 48  
     public String getConfigurationParameter( String parameterName ){
 49  0
             return getKualiConfigurationService().getPropertyString(parameterName);
 50  
     }
 51  
     
 52  
     /**
 53  
      * This method derived ParameterDetailedTypes from the DataDictionary for all BusinessObjects and Documents and from Spring for
 54  
      * all batch Steps.
 55  
      * 
 56  
      * @return List<ParameterDetailedType> containing the detailed types derived from the data dictionary and Spring
 57  
      */
 58  
     public List<ParameterDetailType> getNonDatabaseComponents() {
 59  0
         if (components.isEmpty()) {
 60  0
             Map<String, ParameterDetailType> uniqueParameterDetailTypeMap = new HashMap<String, ParameterDetailType>();
 61  
                         
 62  0
             DataDictionaryService dataDictionaryService = KNSServiceLocator.getDataDictionaryService();
 63  
             
 64  
             //dataDictionaryService.getDataDictionary().forceCompleteDataDictionaryLoad();
 65  0
             for (BusinessObjectEntry businessObjectEntry : dataDictionaryService.getDataDictionary().getBusinessObjectEntries().values()) {
 66  
                 try {
 67  0
                     ParameterDetailType parameterDetailType = getParameterDetailType((businessObjectEntry.getBaseBusinessObjectClass() != null) ? businessObjectEntry.getBaseBusinessObjectClass() : businessObjectEntry.getBusinessObjectClass());
 68  0
                     uniqueParameterDetailTypeMap.put(parameterDetailType.getParameterDetailTypeCode(), parameterDetailType);
 69  
                 }
 70  0
                 catch (Exception e) {
 71  0
                     LOG.error("The getDataDictionaryAndSpringComponents method of ParameterUtils encountered an exception while trying to create the detail type for business object class: " + businessObjectEntry.getBusinessObjectClass(), e);
 72  0
                 }
 73  
             }
 74  0
             for (DocumentEntry documentEntry : dataDictionaryService.getDataDictionary().getDocumentEntries().values()) {
 75  0
                 if (documentEntry instanceof TransactionalDocumentEntry) {
 76  
                     try {
 77  0
                         ParameterDetailType parameterDetailType = getParameterDetailType((documentEntry.getBaseDocumentClass() != null) ? documentEntry.getBaseDocumentClass() : documentEntry.getDocumentClass());
 78  0
                         uniqueParameterDetailTypeMap.put(parameterDetailType.getParameterDetailTypeCode(), parameterDetailType);
 79  
                     }
 80  0
                     catch (Exception e) {
 81  0
                         LOG.error("The getNonDatabaseDetailTypes method of ParameterServiceImpl encountered an exception while trying to create the detail type for transactional document class: " +
 82  
                                         ((documentEntry.getBaseDocumentClass() != null) ? documentEntry.getBaseDocumentClass() : documentEntry.getDocumentClass()), e);
 83  0
                     }
 84  
                 }
 85  
             }
 86  0
             components.addAll(uniqueParameterDetailTypeMap.values());
 87  
         }
 88  0
         return Collections.unmodifiableList(components);
 89  
     }
 90  
     
 91  
     @SuppressWarnings("unchecked")
 92  
         protected ParameterDetailType getParameterDetailType(Class documentOrStepClass) {
 93  0
         String detailTypeString = getParameterService().getDetailType(documentOrStepClass);
 94  0
         String detailTypeName = getDetailTypeName(documentOrStepClass);
 95  0
         ParameterDetailType detailType = new ParameterDetailType(getParameterService().getNamespace(documentOrStepClass), detailTypeString, (detailTypeName == null) ? detailTypeString : detailTypeName);
 96  0
         detailType.refreshNonUpdateableReferences();
 97  0
         return detailType;
 98  
     }
 99  
 
 100  
     @SuppressWarnings("unchecked")
 101  
     /**
 102  
      * This method derived ParameterDetailedTypes from the DataDictionary for all BusinessObjects and Transactional Documents Entries and from Spring for
 103  
      * all batch Steps.
 104  
      * 
 105  
      * @return String containing the detailed type name derived from the data dictionary/Business Object
 106  
      */
 107  
         protected String getDetailTypeName(Class documentOrStepClass) {
 108  0
         if (documentOrStepClass == null) {
 109  0
             throw new IllegalArgumentException("The getDetailTypeName method of ParameterServiceImpl requires non-null documentOrStepClass");
 110  
         }
 111  
         
 112  
         /* 
 113  
          * Some business objects have a Component annotation that sets the value
 114  
          * of the classes annotaion.  This if block will test to see if it is there, try to get the 
 115  
          * component value from the Data Dictionary if the BusinessObjectEntry exists, if it doesn't
 116  
          * exist, it will fall back to the annotation's value.
 117  
          */
 118  0
         if (documentOrStepClass.isAnnotationPresent(COMPONENT.class)) {
 119  0
             BusinessObjectEntry boe = getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(documentOrStepClass.getName());
 120  0
             if (boe != null) {
 121  0
                 return boe.getObjectLabel();
 122  
             }
 123  
             else {
 124  0
                 return ((COMPONENT) documentOrStepClass.getAnnotation(COMPONENT.class)).component();
 125  
             }
 126  
         }
 127  
 
 128  
         /*
 129  
          * If block that determines if the class is either a BusinessObject or a TransactionalDocument
 130  
          * return calls try to either get the BusinessObjectEntry's ObjectLable, or grabbing the 
 131  
          * data dictionary's BusinessTitleForClass if it is a BusinessObject, or the DocumentLabel if it is a
 132  
          * TransactionalDocument
 133  
          */
 134  0
         if (TransactionalDocument.class.isAssignableFrom(documentOrStepClass)) {
 135  0
             return getDataDictionaryService().getDocumentLabelByClass(documentOrStepClass);
 136  
         }
 137  0
         else if (BusinessObject.class.isAssignableFrom(documentOrStepClass) ) {
 138  0
             BusinessObjectEntry boe = getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(documentOrStepClass.getName());
 139  0
             if (boe != null) {
 140  0
                 return boe.getObjectLabel();
 141  
             }
 142  
             else {
 143  0
                 return KNSUtils.getBusinessTitleForClass(documentOrStepClass);
 144  
             }
 145  
         }
 146  0
         throw new IllegalArgumentException("The getDetailTypeName method of ParameterServiceImpl requires TransactionalDocument, BusinessObject, or Step class. Was: " + documentOrStepClass.getName() );
 147  
     }
 148  
     
 149  
     protected KualiConfigurationService getKualiConfigurationService() {
 150  0
                 if (kualiConfigurationService == null) {
 151  0
                         kualiConfigurationService = KNSServiceLocator.getKualiConfigurationService();
 152  
                 }
 153  0
                 return kualiConfigurationService;
 154  
         }
 155  
     
 156  
     protected ParameterService getParameterService() {
 157  0
             if (parameterService == null) {
 158  0
                     parameterService = KNSServiceLocator.getParameterService();
 159  
             }
 160  0
             return parameterService;
 161  
     }
 162  
 
 163  
     protected DataDictionaryService getDataDictionaryService() {
 164  0
             if (dataDictionaryService == null) {
 165  0
                     dataDictionaryService = KNSServiceLocator.getDataDictionaryService();
 166  
             }
 167  0
             return dataDictionaryService;
 168  
     }
 169  
 
 170  
         /**
 171  
          * @see org.kuali.rice.kns.service.RiceApplicationConfigurationService#getBaseInquiryUrl(java.lang.String)
 172  
          */
 173  
         public String getBaseInquiryUrl(String businessObjectClassName) {
 174  0
                 return LookupUtils.getBaseInquiryUrl();
 175  
         }
 176  
 
 177  
         /**
 178  
          * @see org.kuali.rice.kns.service.RiceApplicationConfigurationService#getBaseLookupUrl(java.lang.String)
 179  
          */
 180  
         public String getBaseLookupUrl(String businessObjectClassName) {
 181  
                 // all Rice applications share the same type of lookup URL
 182  0
                 return LookupUtils.getBaseLookupUrl(false);
 183  
         }
 184  
         
 185  
         public String getBaseHelpUrl(String businessObjectClassName) {
 186  0
                 return KNSServiceLocator.getKualiConfigurationService().getPropertyString(KNSConstants.APPLICATION_URL_KEY) + "/kr/help.do";
 187  
         }
 188  
 
 189  
         /**
 190  
          * @see org.kuali.rice.kns.service.RiceApplicationConfigurationService#isResponsibleForPackage(java.lang.String)
 191  
          */
 192  
         public boolean isResponsibleForPackage(String packageName) {
 193  0
                 if ( LOG.isDebugEnabled() ) {
 194  0
                         LOG.debug( "Checking if application ("+packagePrefixes+") is responsible for package: " + packageName );
 195  
                 }
 196  0
                 for ( String prefix : packagePrefixes ) {
 197  0
                         if ( packageName.startsWith(prefix) ) {
 198  0
                                 if ( LOG.isDebugEnabled() ) {
 199  0
                                         LOG.debug("Found match ("+prefix+") - returning true");
 200  
                                 }
 201  0
                                 return true;
 202  
                         }
 203  
                 }
 204  0
                 if ( LOG.isDebugEnabled() ) {
 205  0
                         LOG.debug("No Match Found: packageName="+packageName+" / prefix list=" + packagePrefixes);
 206  
                 }
 207  0
                 return false;
 208  
         }
 209  
         
 210  
         /**
 211  
          * @see org.kuali.rice.kns.service.RiceApplicationConfigurationService#supportsBusinessObjectClass(java.lang.String)
 212  
          */
 213  
         public boolean supportsBusinessObjectClass(String businessObjectClassName) {
 214  0
                 return getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(businessObjectClassName) != null;
 215  
         }
 216  
         
 217  
         /**
 218  
          * @see org.kuali.rice.kns.service.RiceApplicationConfigurationService#getBusinessObjectAttributeDefinition(java.lang.String, java.lang.String)
 219  
          */
 220  
         public AttributeDefinition getBusinessObjectAttributeDefinition( String businessObjectClassName, String attributeName) {
 221  0
                 if ( LOG.isDebugEnabled() ) {
 222  0
                         LOG.debug( "Asking ("+packagePrefixes+") for BO AttributeDefinition: " + businessObjectClassName + " / " + attributeName );
 223  
                 }
 224  0
                 BusinessObjectEntry boe = getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(businessObjectClassName);
 225  0
                 if ( boe == null ) {
 226  0
                         if ( LOG.isInfoEnabled() ) {
 227  0
                                 LOG.info( "No BusinessObjectEntry found for class name: " + businessObjectClassName );
 228  
                         }
 229  0
                         return null;
 230  
                 }
 231  0
                 return boe.getAttributeDefinition(attributeName);
 232  
         }
 233  
 
 234  
         /**
 235  
          * @return the packagePrefixes
 236  
          */
 237  
         public List<String> getPackagePrefixes() {
 238  0
                 return this.packagePrefixes;
 239  
         }
 240  
 
 241  
         /**
 242  
          * @param packagePrefixes the packagePrefixes to set
 243  
          */
 244  
         public void setPackagePrefixes(List<String> packagePrefixes) {
 245  0
                 this.packagePrefixes = packagePrefixes;
 246  0
         }
 247  
 }