Clover Coverage Report - krad-web-framework 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
32   162   16   2.91
4   86   0.5   11
11     1.45  
1    
 
  PersistableBusinessObjectValuesFinder       Line # 40 32 0% 16 47 0% 0.0
 
No Tests
 
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.KeyValue;
27    import org.kuali.rice.core.util.ConcreteKeyValue;
28    import org.kuali.rice.kns.bo.PersistableBusinessObject;
29    import org.kuali.rice.kns.service.KNSServiceLocator;
30    import org.kuali.rice.kns.service.KNSServiceLocatorWeb;
31    import org.kuali.rice.kns.service.KeyValuesService;
32    import org.springframework.transaction.annotation.Transactional;
33   
34    /**
35    * This class is a Generic ValuesFinder that builds the list of KeyValuePairs it returns
36    * in getKeyValues() based on a BO along with a keyAttributeName and labelAttributeName
37    * that are specified.
38    */
39    @Transactional
 
40    public class PersistableBusinessObjectValuesFinder <T extends PersistableBusinessObject> extends KeyValuesBase {
41   
42    private static final Log LOG = LogFactory.getLog(PersistableBusinessObjectValuesFinder.class);
43   
44    private Class<T> businessObjectClass;
45    private String keyAttributeName;
46    private String labelAttributeName;
47    private boolean includeKeyInDescription = false;
48    private boolean includeBlankRow = false;
49   
50    /**
51    * Build the list of KeyValues using the key (keyAttributeName) and
52    * label (labelAttributeName) of the list of all business objects found
53    * for the BO class specified.
54    *
55    * @see org.kuali.keyvalues.KeyValuesFinder#getKeyValues()
56    */
 
57  0 toggle @Override
58    public List<KeyValue> getKeyValues() {
59  0 List<KeyValue> labels = new ArrayList<KeyValue>();
60   
61  0 try {
62  0 KeyValuesService boService = KNSServiceLocator.getKeyValuesService();
63  0 Collection<T> objects = boService.findAll(businessObjectClass);
64  0 if(includeBlankRow) {
65  0 labels.add(new ConcreteKeyValue("", ""));
66    }
67  0 for (T object : objects) {
68  0 Object key = PropertyUtils.getProperty(object, keyAttributeName);
69  0 String label = (String)PropertyUtils.getProperty(object, labelAttributeName);
70  0 if (includeKeyInDescription) {
71  0 label = key + " - " + label;
72    }
73  0 labels.add(new ConcreteKeyValue(key.toString(), label));
74    }
75    } catch (IllegalAccessException e) {
76  0 LOG.debug(e.getMessage(), e);
77  0 LOG.error(e.getMessage());
78  0 throw new RuntimeException("IllegalAccessException occurred while trying to build keyValues List. businessObjectClass: " + businessObjectClass + "; keyAttributeName: " + keyAttributeName + "; labelAttributeName: " + labelAttributeName + "; includeKeyInDescription: " + includeKeyInDescription, e);
79    } catch (InvocationTargetException e) {
80  0 LOG.debug(e.getMessage(), e);
81  0 LOG.error(e.getMessage());
82  0 throw new RuntimeException("InvocationTargetException occurred while trying to build keyValues List. businessObjectClass: " + businessObjectClass + "; keyAttributeName: " + keyAttributeName + "; labelAttributeName: " + labelAttributeName + "; includeKeyInDescription: " + includeKeyInDescription, e);
83    } catch (NoSuchMethodException e) {
84  0 LOG.debug(e.getMessage(), e);
85  0 LOG.error(e.getMessage());
86  0 throw new RuntimeException("NoSuchMethodException occurred while trying to build keyValues List. businessObjectClass: " + businessObjectClass + "; keyAttributeName: " + keyAttributeName + "; labelAttributeName: " + labelAttributeName + "; includeKeyInDescription: " + includeKeyInDescription, e);
87    }
88   
89  0 return labels;
90    }
91   
92    /**
93    * @return the businessObjectClass
94    */
 
95  0 toggle public Class<T> getBusinessObjectClass() {
96  0 return this.businessObjectClass;
97    }
98   
99    /**
100    * @param businessObjectClass the businessObjectClass to set
101    */
 
102  0 toggle public void setBusinessObjectClass(Class<T> businessObjectClass) {
103  0 this.businessObjectClass = businessObjectClass;
104    }
105   
106    /**
107    * @return the includeKeyInDescription
108    */
 
109  0 toggle public boolean isIncludeKeyInDescription() {
110  0 return this.includeKeyInDescription;
111    }
112   
113    /**
114    * @param includeKeyInDescription the includeKeyInDescription to set
115    */
 
116  0 toggle public void setIncludeKeyInDescription(boolean includeKeyInDescription) {
117  0 this.includeKeyInDescription = includeKeyInDescription;
118    }
119   
120    /**
121    * @return the keyAttributeName
122    */
 
123  0 toggle public String getKeyAttributeName() {
124  0 return this.keyAttributeName;
125    }
126   
127    /**
128    * @param keyAttributeName the keyAttributeName to set
129    */
 
130  0 toggle public void setKeyAttributeName(String keyAttributeName) {
131  0 this.keyAttributeName = keyAttributeName;
132    }
133   
134    /**
135    * @return the labelAttributeName
136    */
 
137  0 toggle public String getLabelAttributeName() {
138  0 return this.labelAttributeName;
139    }
140   
141    /**
142    * @param labelAttributeName the labelAttributeName to set
143    */
 
144  0 toggle public void setLabelAttributeName(String labelAttributeName) {
145  0 this.labelAttributeName = labelAttributeName;
146    }
147   
148    /**
149    * @return the includeBlankRow
150    */
 
151  0 toggle public boolean isIncludeBlankRow() {
152  0 return this.includeBlankRow;
153    }
154   
155    /**
156    * @param includeBlankRow the includeBlankRow to set
157    */
 
158  0 toggle public void setIncludeBlankRow(boolean includeBlankRow) {
159  0 this.includeBlankRow = includeBlankRow;
160    }
161   
162    }