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.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 | |
|
33 | |
|
34 | |
|
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 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
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 | |
|
90 | |
|
91 | |
public Class getBusinessObjectClass() { |
92 | 0 | return this.businessObjectClass; |
93 | |
} |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public void setBusinessObjectClass(Class businessObjectClass) { |
99 | 0 | this.businessObjectClass = businessObjectClass; |
100 | 0 | } |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
public boolean isIncludeKeyInDescription() { |
106 | 0 | return this.includeKeyInDescription; |
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public void setIncludeKeyInDescription(boolean includeKeyInDescription) { |
113 | 0 | this.includeKeyInDescription = includeKeyInDescription; |
114 | 0 | } |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
public String getKeyAttributeName() { |
120 | 0 | return this.keyAttributeName; |
121 | |
} |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
public void setKeyAttributeName(String keyAttributeName) { |
127 | 0 | this.keyAttributeName = keyAttributeName; |
128 | 0 | } |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
public String getLabelAttributeName() { |
134 | 0 | return this.labelAttributeName; |
135 | |
} |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
public void setLabelAttributeName(String labelAttributeName) { |
141 | 0 | this.labelAttributeName = labelAttributeName; |
142 | 0 | } |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
public boolean isIncludeBlankRow() { |
148 | 0 | return this.includeBlankRow; |
149 | |
} |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
public void setIncludeBlankRow(boolean includeBlankRow) { |
155 | 0 | this.includeBlankRow = includeBlankRow; |
156 | 0 | } |
157 | |
|
158 | |
} |