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