Coverage Report - org.kuali.rice.krad.bo.ModuleConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
ModuleConfiguration
0%
0/81
0%
0/32
1.6
 
 1  
 /*
 2  
  * Copyright 2007-2008 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.bo;
 17  
 
 18  
 import java.lang.reflect.Modifier;
 19  
 import java.util.ArrayList;
 20  
 import java.util.Collections;
 21  
 import java.util.List;
 22  
 import java.util.Map;
 23  
 
 24  
 import javax.persistence.EntityManager;
 25  
 
 26  
 import org.kuali.rice.krad.datadictionary.spring.DataDictionaryLocationConfigurer;
 27  
 import org.kuali.rice.krad.service.DataDictionaryService;
 28  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 29  
 import org.kuali.rice.krad.service.PersistenceService;
 30  
 import org.springframework.beans.factory.InitializingBean;
 31  
 import org.springframework.context.ApplicationContext;
 32  
 import org.springframework.context.ApplicationContextAware;
 33  
 
 34  
 /**
 35  
  * This is a description of what this class does - bhargavp don't forget to fill this in.
 36  
  *
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  *
 39  
  */
 40  
 public class ModuleConfiguration implements InitializingBean, ApplicationContextAware {
 41  
 
 42  
         //protected static Logger LOG = Logger.getLogger(ModuleConfiguration.class);
 43  
 
 44  
         protected String namespaceCode;
 45  
         protected ApplicationContext applicationContext;
 46  
 
 47  
         protected List<String> packagePrefixes;
 48  
 
 49  
         protected List<String> databaseRepositoryFilePaths;
 50  
 
 51  
         protected List<String> dataDictionaryPackages;
 52  
 
 53  
         protected List<String> scriptConfigurationFilePaths;
 54  
 
 55  
         protected List<String> jobNames;
 56  
 
 57  
         protected List<String> triggerNames;
 58  
 
 59  
         //optional
 60  
         protected String dataSourceName;
 61  
 
 62  
         //optional
 63  
         protected EntityManager entityManager;
 64  
 
 65  
         protected Map<Class, Class> externalizableBusinessObjectImplementations;
 66  
 
 67  
         protected boolean initializeDataDictionary;
 68  
 
 69  
         protected PersistenceService persistenceService;
 70  
 
 71  
         protected DataDictionaryService dataDictionaryService;
 72  
 
 73  0
         public ModuleConfiguration() {
 74  0
                 databaseRepositoryFilePaths = new ArrayList<String>();
 75  0
                 dataDictionaryPackages = new ArrayList<String>();
 76  0
                 scriptConfigurationFilePaths = new ArrayList<String>();
 77  0
                 jobNames = new ArrayList<String>();
 78  0
                 triggerNames = new ArrayList<String>();
 79  0
         }
 80  
 
 81  
         /**
 82  
          * @return the databaseRepositoryFilePaths
 83  
          */
 84  
         public List<String> getDatabaseRepositoryFilePaths() {
 85  0
                 return this.databaseRepositoryFilePaths;
 86  
         }
 87  
 
 88  
         /**
 89  
          * @param databaseRepositoryFilePaths the databaseRepositoryFilePaths to set
 90  
          */
 91  
         public void setDatabaseRepositoryFilePaths(
 92  
                         List<String> databaseRepositoryFilePaths) {
 93  0
                 this.trimList(databaseRepositoryFilePaths);        
 94  0
                 this.databaseRepositoryFilePaths = databaseRepositoryFilePaths;
 95  0
         }
 96  
 
 97  
         /**
 98  
          * @return the dataDictionaryPackages
 99  
          */
 100  
         public List<String> getDataDictionaryPackages() {
 101  0
                 return this.dataDictionaryPackages;
 102  
         }
 103  
 
 104  
         /**
 105  
          * @param dataDictionaryPackages the dataDictionaryPackages to set
 106  
          */
 107  
         public void setDataDictionaryPackages(List<String> dataDictionaryPackages) {
 108  0
                 this.trimList(dataDictionaryPackages);                        
 109  0
                 this.dataDictionaryPackages = dataDictionaryPackages;                
 110  0
         }        
 111  
         
 112  
         /**
 113  
          * @return the externalizableBusinessObjectImplementations
 114  
          */
 115  
         public Map<Class, Class> getExternalizableBusinessObjectImplementations() {
 116  0
                 if (this.externalizableBusinessObjectImplementations == null)
 117  0
                         return null;
 118  0
                 return Collections.unmodifiableMap(this.externalizableBusinessObjectImplementations);
 119  
         }
 120  
 
 121  
         /**
 122  
          * @param externalizableBusinessObjectImplementations the externalizableBusinessObjectImplementations to set
 123  
          */
 124  
         public void setExternalizableBusinessObjectImplementations(
 125  
                         Map<Class, Class> externalizableBusinessObjectImplementations) {
 126  0
                 if (externalizableBusinessObjectImplementations != null) {
 127  0
                         for (Class implClass : externalizableBusinessObjectImplementations.values()) {
 128  0
                                 int implModifiers = implClass.getModifiers();
 129  0
                                 if (Modifier.isInterface(implModifiers) || Modifier.isAbstract(implModifiers)) {
 130  0
                                         throw new RuntimeException("Externalizable business object implementation class " +
 131  
                                                         implClass.getName() + " must be a non-interface, non-abstract class");
 132  
                                 }
 133  0
                         }
 134  
                 }
 135  0
                 this.externalizableBusinessObjectImplementations = externalizableBusinessObjectImplementations;
 136  0
         }
 137  
 
 138  
         public List<String> getPackagePrefixes(){
 139  0
                 return this.packagePrefixes;
 140  
         }
 141  
 
 142  
         public void setPackagePrefixes(List<String> packagePrefixes){
 143  0
                 this.trimList(packagePrefixes);
 144  0
                 this.packagePrefixes = packagePrefixes;
 145  0
         }
 146  
 
 147  
         public void setInitializeDataDictionary(boolean initializeDataDictionary){
 148  0
                 this.initializeDataDictionary = initializeDataDictionary;
 149  0
         }
 150  
 
 151  
         public List<String> getScriptConfigurationFilePaths(){
 152  0
                 return this.scriptConfigurationFilePaths;
 153  
         }
 154  
 
 155  
         /**
 156  
          * @return the jobNames
 157  
          */
 158  
         public List<String> getJobNames() {
 159  0
                 return this.jobNames;
 160  
         }
 161  
 
 162  
         /**
 163  
          * @param jobNames the jobNames to set
 164  
          */
 165  
         public void setJobNames(List<String> jobNames) {
 166  0
                 this.jobNames = jobNames;
 167  0
         }
 168  
 
 169  
 
 170  
         /**
 171  
          * @return the triggerNames
 172  
          */
 173  
         public List<String> getTriggerNames() {
 174  0
                 return this.triggerNames;
 175  
         }
 176  
 
 177  
         /**
 178  
          * @param triggerNames the triggerNames to set
 179  
          */
 180  
         public void setTriggerNames(List<String> triggerNames) {
 181  0
                 this.triggerNames = triggerNames;
 182  0
         }
 183  
 
 184  
         /**
 185  
          * @return the initializeDataDictionary
 186  
          */
 187  
         public boolean isInitializeDataDictionary() {
 188  0
                 return this.initializeDataDictionary;
 189  
         }
 190  
 
 191  
         /**
 192  
          * @param scriptConfigurationFilePaths the scriptConfigurationFilePaths to set
 193  
          */
 194  
         public void setScriptConfigurationFilePaths(
 195  
                         List<String> scriptConfigurationFilePaths) {
 196  0
                 this.scriptConfigurationFilePaths = scriptConfigurationFilePaths;
 197  0
         }
 198  
 
 199  
         @Override
 200  
         public void afterPropertiesSet() throws Exception {
 201  0
                 if (isInitializeDataDictionary() && getDataDictionaryPackages() != null && !getDataDictionaryPackages().isEmpty() ) {
 202  0
                         if ( getDataDictionaryService() == null ) {
 203  0
                                 setDataDictionaryService(KRADServiceLocatorWeb.getDataDictionaryService());
 204  
                         }
 205  0
                         if ( getDataDictionaryService() == null ) {
 206  0
                                 setDataDictionaryService((DataDictionaryService)applicationContext.getBean( KRADServiceLocatorWeb.DATA_DICTIONARY_SERVICE ));
 207  
                         }
 208  0
                         DataDictionaryLocationConfigurer ddl = new DataDictionaryLocationConfigurer( getDataDictionaryService() );
 209  0
                         ddl.setDataDictionaryPackages(getDataDictionaryPackages());
 210  0
                         ddl.afterPropertiesSet();
 211  
                 }
 212  0
                 if (getDatabaseRepositoryFilePaths() != null) {
 213  0
                     for (String repositoryLocation : getDatabaseRepositoryFilePaths()) {
 214  
                                 // Need the OJB persistence service because it is the only one ever using the database repository files
 215  0
                             if (getPersistenceService() == null) {
 216  0
                                     setPersistenceService(KRADServiceLocatorWeb.getPersistenceServiceOjb());
 217  
                             }
 218  0
                             if ( persistenceService == null ) {
 219  0
                                     setPersistenceService((PersistenceService)applicationContext.getBean( KRADServiceLocatorWeb.PERSISTENCE_SERVICE_OJB  ));
 220  
                             }
 221  0
                             getPersistenceService().loadRepositoryDescriptor( repositoryLocation );
 222  
                         }
 223  
                 }
 224  0
         }
 225  
 
 226  
         /**
 227  
          * @return the namespaceCode
 228  
          */
 229  
         public String getNamespaceCode() {
 230  0
                 return this.namespaceCode;
 231  
         }
 232  
 
 233  
         /**
 234  
          * @param namespaceCode the namespaceCode to set
 235  
          */
 236  
         public void setNamespaceCode(String namespaceCode) {
 237  0
                 this.namespaceCode = namespaceCode;
 238  0
         }
 239  
 
 240  
         @Override
 241  
         public void setApplicationContext(ApplicationContext applicationContext) {
 242  0
                 this.applicationContext = applicationContext;
 243  0
         }
 244  
 
 245  
         /**
 246  
          * @return the dataDictionaryService
 247  
          */
 248  
         public DataDictionaryService getDataDictionaryService() {
 249  0
                 return this.dataDictionaryService;
 250  
         }
 251  
 
 252  
         /**
 253  
          * @param dataDictionaryService the dataDictionaryService to set
 254  
          */
 255  
         public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
 256  0
                 this.dataDictionaryService = dataDictionaryService;
 257  0
         }
 258  
 
 259  
         /**
 260  
          * @return the persistenceService
 261  
          */
 262  
         public PersistenceService getPersistenceService() {
 263  0
                 return this.persistenceService;
 264  
         }
 265  
 
 266  
         /**
 267  
          * @param persistenceService the persistenceService to set
 268  
          */
 269  
         public void setPersistenceService(PersistenceService persistenceService) {
 270  0
                 this.persistenceService = persistenceService;
 271  0
         }
 272  
 
 273  
     public String getDataSourceName() {
 274  0
         return this.dataSourceName;
 275  
     }
 276  
 
 277  
     public void setDataSourceName(String dataSourceName) {
 278  0
         this.dataSourceName = dataSourceName;
 279  0
     }
 280  
 
 281  
     public EntityManager getEntityManager() {
 282  0
         return this.entityManager;
 283  
     }
 284  
 
 285  
     public void setEntityManager(EntityManager entityManager) {
 286  0
         this.entityManager = entityManager;
 287  0
     }
 288  
     
 289  
     /**
 290  
          * 
 291  
          * This method passes by reference. It will alter the list passed in.
 292  
          * 
 293  
          * @param stringList
 294  
          */
 295  
         protected void trimList(List<String> stringList){
 296  0
                 if(stringList != null){
 297  
                         // we need to trim whitespace from the stringList. Because trim() creates a new string 
 298  
                         // we have to explicitly put the new string back into the list
 299  0
                         for(int i=0; i<stringList.size(); i++){
 300  0
                                 String elmt = stringList.get(i);                                
 301  0
                                 elmt = elmt.trim();
 302  0
                                 stringList.set(i, elmt);
 303  
                         }                        
 304  
                 }
 305  0
         }
 306  
 
 307  
 }