| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 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 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
@Transactional |
|
|
|
| 0% |
Uncovered Elements: 47 (47) |
Complexity: 16 |
Complexity Density: 0.5 |
|
| 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 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
@see |
| 56 |
|
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 6 |
Complexity Density: 0.27 |
|
| 57 |
0
|
@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 |
| 94 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 95 |
0
|
public Class<T> getBusinessObjectClass() {... |
| 96 |
0
|
return this.businessObjectClass; |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
|
| 100 |
|
@param |
| 101 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 102 |
0
|
public void setBusinessObjectClass(Class<T> businessObjectClass) {... |
| 103 |
0
|
this.businessObjectClass = businessObjectClass; |
| 104 |
|
} |
| 105 |
|
|
| 106 |
|
|
| 107 |
|
@return |
| 108 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 109 |
0
|
public boolean isIncludeKeyInDescription() {... |
| 110 |
0
|
return this.includeKeyInDescription; |
| 111 |
|
} |
| 112 |
|
|
| 113 |
|
|
| 114 |
|
@param |
| 115 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 116 |
0
|
public void setIncludeKeyInDescription(boolean includeKeyInDescription) {... |
| 117 |
0
|
this.includeKeyInDescription = includeKeyInDescription; |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
|
| 121 |
|
@return |
| 122 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 123 |
0
|
public String getKeyAttributeName() {... |
| 124 |
0
|
return this.keyAttributeName; |
| 125 |
|
} |
| 126 |
|
|
| 127 |
|
|
| 128 |
|
@param |
| 129 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 130 |
0
|
public void setKeyAttributeName(String keyAttributeName) {... |
| 131 |
0
|
this.keyAttributeName = keyAttributeName; |
| 132 |
|
} |
| 133 |
|
|
| 134 |
|
|
| 135 |
|
@return |
| 136 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 137 |
0
|
public String getLabelAttributeName() {... |
| 138 |
0
|
return this.labelAttributeName; |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
|
| 142 |
|
@param |
| 143 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 144 |
0
|
public void setLabelAttributeName(String labelAttributeName) {... |
| 145 |
0
|
this.labelAttributeName = labelAttributeName; |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
|
| 149 |
|
@return |
| 150 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 151 |
0
|
public boolean isIncludeBlankRow() {... |
| 152 |
0
|
return this.includeBlankRow; |
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
|
| 156 |
|
@param |
| 157 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 158 |
0
|
public void setIncludeBlankRow(boolean includeBlankRow) {... |
| 159 |
0
|
this.includeBlankRow = includeBlankRow; |
| 160 |
|
} |
| 161 |
|
|
| 162 |
|
} |