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 |
40 | 0 | public class PersistableBusinessObjectValuesFinder <T extends PersistableBusinessObject> extends KeyValuesBase { |
41 | |
|
42 | 0 | private static final Log LOG = LogFactory.getLog(PersistableBusinessObjectValuesFinder.class); |
43 | |
|
44 | |
private Class<T> businessObjectClass; |
45 | |
private String keyAttributeName; |
46 | |
private String labelAttributeName; |
47 | 0 | private boolean includeKeyInDescription = false; |
48 | 0 | private boolean includeBlankRow = false; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
@Override |
58 | |
public List<KeyValue> getKeyValues() { |
59 | 0 | List<KeyValue> labels = new ArrayList<KeyValue>(); |
60 | |
|
61 | |
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 | 0 | } |
75 | 0 | } 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 | 0 | } 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 | 0 | } 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 | 0 | } |
88 | |
|
89 | 0 | return labels; |
90 | |
} |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
public Class<T> getBusinessObjectClass() { |
96 | 0 | return this.businessObjectClass; |
97 | |
} |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
public void setBusinessObjectClass(Class<T> businessObjectClass) { |
103 | 0 | this.businessObjectClass = businessObjectClass; |
104 | 0 | } |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
public boolean isIncludeKeyInDescription() { |
110 | 0 | return this.includeKeyInDescription; |
111 | |
} |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
public void setIncludeKeyInDescription(boolean includeKeyInDescription) { |
117 | 0 | this.includeKeyInDescription = includeKeyInDescription; |
118 | 0 | } |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
public String getKeyAttributeName() { |
124 | 0 | return this.keyAttributeName; |
125 | |
} |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
public void setKeyAttributeName(String keyAttributeName) { |
131 | 0 | this.keyAttributeName = keyAttributeName; |
132 | 0 | } |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
public String getLabelAttributeName() { |
138 | 0 | return this.labelAttributeName; |
139 | |
} |
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
public void setLabelAttributeName(String labelAttributeName) { |
145 | 0 | this.labelAttributeName = labelAttributeName; |
146 | 0 | } |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
public boolean isIncludeBlankRow() { |
152 | 0 | return this.includeBlankRow; |
153 | |
} |
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
public void setIncludeBlankRow(boolean includeBlankRow) { |
159 | 0 | this.includeBlankRow = includeBlankRow; |
160 | 0 | } |
161 | |
|
162 | |
} |