Coverage Report - org.kuali.rice.ksb.messaging.quartz.QuartzConfigPropertiesFactoryBean
 
Classes in this File Line Coverage Branch Coverage Complexity
QuartzConfigPropertiesFactoryBean
0%
0/16
0%
0/14
3.667
 
 1  
 /**
 2  
  * Copyright 2005-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  
 package org.kuali.rice.ksb.messaging.quartz;
 17  
 
 18  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 19  
 import org.kuali.rice.ksb.util.KSBConstants;
 20  
 import org.springframework.beans.factory.config.AbstractFactoryBean;
 21  
 
 22  
 import java.util.Properties;
 23  
 
 24  
 /**
 25  
  * A factory bean which reads quartz-related properties from the Config system and
 26  
  * generates a Properites instance for use when configuration quartz.
 27  
  * 
 28  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 29  
  *
 30  
  */
 31  0
 public class QuartzConfigPropertiesFactoryBean extends AbstractFactoryBean {
 32  
 
 33  
     private static final String QUARTZ_PREFIX = "ksb.org.quartz";
 34  
     private static final String QUARTZ_IS_CLUSTERED = QUARTZ_PREFIX + ".jobStore.isClustered";
 35  
     private static final String QUARTZ_TABLE_PREFIX = QUARTZ_PREFIX + ".jobStore.tablePrefix";
 36  
     
 37  
     @Override
 38  
     protected Object createInstance() throws Exception {
 39  0
         Properties properties = new Properties();
 40  0
         Properties configProps = ConfigContext.getCurrentContextConfig().getProperties();
 41  0
         boolean useQuartzDatabase = Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.USE_QUARTZ_DATABASE));
 42  0
         for (Object keyObj : configProps.keySet()) {
 43  0
             if (keyObj instanceof String) {
 44  0
                     String key = (String)keyObj;
 45  0
                     if (key.startsWith(QUARTZ_PREFIX) && !propertyShouldBeFiltered(useQuartzDatabase, key)) {
 46  0
                             properties.put(key.substring(4), configProps.get(key));
 47  
                     }
 48  0
             }
 49  
         }
 50  0
         return properties;
 51  
     }
 52  
     
 53  
     /**
 54  
      * When we aren't using the quartz database, prevents some of the parameters for quartz database mode from
 55  
      * being passed to quartz.  If we pass these to quartz when it's using a RAMJobStore, we get an error.  So
 56  
      * in order to allow us to provide good defaults in common-config-defaults.xml, we will filter these out
 57  
      * if useQuartzDatabase=false
 58  
      */
 59  
     protected boolean propertyShouldBeFiltered(boolean useQuartzDatabase, String propertyName) {
 60  0
             if (!useQuartzDatabase) {
 61  0
                     if (propertyName.startsWith(QUARTZ_TABLE_PREFIX) || propertyName.startsWith(QUARTZ_IS_CLUSTERED)) {
 62  0
                             return true;
 63  
                     }
 64  
             }
 65  0
             return false;
 66  
     }
 67  
     
 68  
     
 69  
     @Override
 70  
     public Class getObjectType() {
 71  0
         return Properties.class;
 72  
     }
 73  
 
 74  
 }