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