Coverage Report - org.kuali.rice.kns.lookup.keyvalues.PersistableBusinessObjectValuesFinder
 
Classes in this File Line Coverage Branch Coverage Complexity
PersistableBusinessObjectValuesFinder
0%
0/45
0%
0/6
1.818
 
 1  
 /*
 2  
  * Copyright 2006-2007 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.kns.lookup.keyvalues;
 17  
 
 18  
 import java.lang.reflect.InvocationTargetException;
 19  
 import java.util.ArrayList;
 20  
 import java.util.Collection;
 21  
 import java.util.List;
 22  
 
 23  
 import org.apache.commons.beanutils.PropertyUtils;
 24  
 import org.apache.commons.logging.Log;
 25  
 import org.apache.commons.logging.LogFactory;
 26  
 import org.kuali.rice.core.util.KeyLabelPair;
 27  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 28  
 import org.kuali.rice.kns.service.KeyValuesService;
 29  
 import org.springframework.transaction.annotation.Transactional;
 30  
 
 31  
 /**
 32  
  * This class is a Generic ValuesFinder that builds the list of KeyValuePairs it returns
 33  
  * in getKeyValues() based on a BO along with a keyAttributeName and labelAttributeName
 34  
  * that are specified.
 35  
  */
 36  
 @Transactional
 37  0
 public class PersistableBusinessObjectValuesFinder extends KeyValuesBase {
 38  
 
 39  0
     private static final Log LOG = LogFactory.getLog(PersistableBusinessObjectValuesFinder.class);
 40  
 
 41  
     private Class businessObjectClass;
 42  
     private String keyAttributeName;
 43  
     private String labelAttributeName;
 44  0
     private boolean includeKeyInDescription = false;
 45  0
     private boolean includeBlankRow = false;
 46  
 
 47  
     /**
 48  
      * Build the list of KeyLabelPairs using the key (keyAttributeName) and
 49  
      * label (labelAttributeName) of the list of all business objects found
 50  
      * for the BO class specified.
 51  
      *
 52  
      * @see org.kuali.keyvalues.KeyValuesFinder#getKeyValues()
 53  
      */
 54  
     public List<KeyLabelPair> getKeyValues() {
 55  0
             List<KeyLabelPair> labels = new ArrayList<KeyLabelPair>();
 56  
 
 57  
             try {
 58  0
                 KeyValuesService boService = KNSServiceLocator.getKeyValuesService();
 59  0
             Collection objects = boService.findAll(businessObjectClass);
 60  0
             if(includeBlankRow) {
 61  0
                     labels.add(new KeyLabelPair("", ""));
 62  
             }
 63  0
             for (Object object : objects) {
 64  0
                     Object key = PropertyUtils.getProperty(object, keyAttributeName);
 65  0
                     String label = (String)PropertyUtils.getProperty(object, labelAttributeName);
 66  0
                     if (includeKeyInDescription) {
 67  0
                         label = key + " - " + label;
 68  
                     }
 69  0
                     labels.add(new KeyLabelPair(key, label));
 70  0
                 }
 71  0
             } catch (IllegalAccessException e) {
 72  0
             LOG.debug(e.getMessage(), e);
 73  0
             LOG.error(e.getMessage());
 74  0
             throw new RuntimeException("IllegalAccessException occurred while trying to build keyValues List. businessObjectClass: " + businessObjectClass + "; keyAttributeName: " + keyAttributeName + "; labelAttributeName: " + labelAttributeName + "; includeKeyInDescription: " + includeKeyInDescription, e);
 75  0
             } catch (InvocationTargetException e) {
 76  0
             LOG.debug(e.getMessage(), e);
 77  0
             LOG.error(e.getMessage());
 78  0
             throw new RuntimeException("InvocationTargetException occurred while trying to build keyValues List. businessObjectClass: " + businessObjectClass + "; keyAttributeName: " + keyAttributeName + "; labelAttributeName: " + labelAttributeName + "; includeKeyInDescription: " + includeKeyInDescription, e);
 79  0
             } catch (NoSuchMethodException e) {
 80  0
             LOG.debug(e.getMessage(), e);
 81  0
             LOG.error(e.getMessage());
 82  0
             throw new RuntimeException("NoSuchMethodException occurred while trying to build keyValues List. businessObjectClass: " + businessObjectClass + "; keyAttributeName: " + keyAttributeName + "; labelAttributeName: " + labelAttributeName + "; includeKeyInDescription: " + includeKeyInDescription, e);
 83  0
             }
 84  
 
 85  0
         return labels;
 86  
     }
 87  
 
 88  
     /**
 89  
      * @return the businessObjectClass
 90  
      */
 91  
     public Class getBusinessObjectClass() {
 92  0
         return this.businessObjectClass;
 93  
     }
 94  
 
 95  
     /**
 96  
      * @param businessObjectClass the businessObjectClass to set
 97  
      */
 98  
     public void setBusinessObjectClass(Class businessObjectClass) {
 99  0
         this.businessObjectClass = businessObjectClass;
 100  0
     }
 101  
 
 102  
     /**
 103  
      * @return the includeKeyInDescription
 104  
      */
 105  
     public boolean isIncludeKeyInDescription() {
 106  0
         return this.includeKeyInDescription;
 107  
     }
 108  
 
 109  
     /**
 110  
      * @param includeKeyInDescription the includeKeyInDescription to set
 111  
      */
 112  
     public void setIncludeKeyInDescription(boolean includeKeyInDescription) {
 113  0
         this.includeKeyInDescription = includeKeyInDescription;
 114  0
     }
 115  
 
 116  
     /**
 117  
      * @return the keyAttributeName
 118  
      */
 119  
     public String getKeyAttributeName() {
 120  0
         return this.keyAttributeName;
 121  
     }
 122  
 
 123  
     /**
 124  
      * @param keyAttributeName the keyAttributeName to set
 125  
      */
 126  
     public void setKeyAttributeName(String keyAttributeName) {
 127  0
         this.keyAttributeName = keyAttributeName;
 128  0
     }
 129  
 
 130  
     /**
 131  
      * @return the labelAttributeName
 132  
      */
 133  
     public String getLabelAttributeName() {
 134  0
         return this.labelAttributeName;
 135  
     }
 136  
 
 137  
     /**
 138  
      * @param labelAttributeName the labelAttributeName to set
 139  
      */
 140  
     public void setLabelAttributeName(String labelAttributeName) {
 141  0
         this.labelAttributeName = labelAttributeName;
 142  0
     }
 143  
 
 144  
         /**
 145  
          * @return the includeBlankRow
 146  
          */
 147  
         public boolean isIncludeBlankRow() {
 148  0
                 return this.includeBlankRow;
 149  
         }
 150  
 
 151  
         /**
 152  
          * @param includeBlankRow the includeBlankRow to set
 153  
          */
 154  
         public void setIncludeBlankRow(boolean includeBlankRow) {
 155  0
                 this.includeBlankRow = includeBlankRow;
 156  0
         }
 157  
 
 158  
 }