1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.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.krad.bo.PersistableBusinessObject; |
29 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
30 | |
import org.kuali.rice.krad.service.KeyValuesService; |
31 | |
import org.springframework.transaction.annotation.Transactional; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
@Transactional |
39 | 0 | public class PersistableBusinessObjectValuesFinder <T extends PersistableBusinessObject> extends KeyValuesBase { |
40 | |
|
41 | 0 | private static final Log LOG = LogFactory.getLog(PersistableBusinessObjectValuesFinder.class); |
42 | |
|
43 | |
private Class<T> businessObjectClass; |
44 | |
private String keyAttributeName; |
45 | |
private String labelAttributeName; |
46 | 0 | private boolean includeKeyInDescription = false; |
47 | 0 | private boolean includeBlankRow = false; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
@Override |
57 | |
public List<KeyValue> getKeyValues() { |
58 | 0 | List<KeyValue> labels = new ArrayList<KeyValue>(); |
59 | |
|
60 | |
try { |
61 | 0 | KeyValuesService boService = KRADServiceLocator.getKeyValuesService(); |
62 | 0 | Collection<T> objects = boService.findAll(businessObjectClass); |
63 | 0 | if(includeBlankRow) { |
64 | 0 | labels.add(new ConcreteKeyValue("", "")); |
65 | |
} |
66 | 0 | for (T object : objects) { |
67 | 0 | Object key = PropertyUtils.getProperty(object, keyAttributeName); |
68 | 0 | String label = (String)PropertyUtils.getProperty(object, labelAttributeName); |
69 | 0 | if (includeKeyInDescription) { |
70 | 0 | label = key + " - " + label; |
71 | |
} |
72 | 0 | labels.add(new ConcreteKeyValue(key.toString(), label)); |
73 | 0 | } |
74 | 0 | } catch (IllegalAccessException e) { |
75 | 0 | LOG.debug(e.getMessage(), e); |
76 | 0 | LOG.error(e.getMessage()); |
77 | 0 | throw new RuntimeException("IllegalAccessException occurred while trying to build keyValues List. businessObjectClass: " + businessObjectClass + "; keyAttributeName: " + keyAttributeName + "; labelAttributeName: " + labelAttributeName + "; includeKeyInDescription: " + includeKeyInDescription, e); |
78 | 0 | } catch (InvocationTargetException e) { |
79 | 0 | LOG.debug(e.getMessage(), e); |
80 | 0 | LOG.error(e.getMessage()); |
81 | 0 | throw new RuntimeException("InvocationTargetException occurred while trying to build keyValues List. businessObjectClass: " + businessObjectClass + "; keyAttributeName: " + keyAttributeName + "; labelAttributeName: " + labelAttributeName + "; includeKeyInDescription: " + includeKeyInDescription, e); |
82 | 0 | } catch (NoSuchMethodException e) { |
83 | 0 | LOG.debug(e.getMessage(), e); |
84 | 0 | LOG.error(e.getMessage()); |
85 | 0 | throw new RuntimeException("NoSuchMethodException occurred while trying to build keyValues List. businessObjectClass: " + businessObjectClass + "; keyAttributeName: " + keyAttributeName + "; labelAttributeName: " + labelAttributeName + "; includeKeyInDescription: " + includeKeyInDescription, e); |
86 | 0 | } |
87 | |
|
88 | 0 | return labels; |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public Class<T> getBusinessObjectClass() { |
95 | 0 | return this.businessObjectClass; |
96 | |
} |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public void setBusinessObjectClass(Class<T> businessObjectClass) { |
102 | 0 | this.businessObjectClass = businessObjectClass; |
103 | 0 | } |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
public boolean isIncludeKeyInDescription() { |
109 | 0 | return this.includeKeyInDescription; |
110 | |
} |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
public void setIncludeKeyInDescription(boolean includeKeyInDescription) { |
116 | 0 | this.includeKeyInDescription = includeKeyInDescription; |
117 | 0 | } |
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
public String getKeyAttributeName() { |
123 | 0 | return this.keyAttributeName; |
124 | |
} |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
public void setKeyAttributeName(String keyAttributeName) { |
130 | 0 | this.keyAttributeName = keyAttributeName; |
131 | 0 | } |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
public String getLabelAttributeName() { |
137 | 0 | return this.labelAttributeName; |
138 | |
} |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
public void setLabelAttributeName(String labelAttributeName) { |
144 | 0 | this.labelAttributeName = labelAttributeName; |
145 | 0 | } |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
public boolean isIncludeBlankRow() { |
151 | 0 | return this.includeBlankRow; |
152 | |
} |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
public void setIncludeBlankRow(boolean includeBlankRow) { |
158 | 0 | this.includeBlankRow = includeBlankRow; |
159 | 0 | } |
160 | |
|
161 | |
} |