1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.web.form;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.lookup.LookupUtils;
20 import org.kuali.rice.krad.lookup.Lookupable;
21 import org.kuali.rice.krad.uif.UifConstants.ViewType;
22 import org.kuali.rice.krad.uif.view.LookupView;
23 import org.kuali.rice.krad.uif.service.ViewHelperService;
24 import org.kuali.rice.krad.util.KRADConstants;
25 import org.kuali.rice.krad.util.KRADUtils;
26
27 import javax.servlet.http.HttpServletRequest;
28 import java.util.ArrayList;
29 import java.util.Collection;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33
34
35
36
37
38
39 public class LookupForm extends UifFormBase {
40 private static final long serialVersionUID = -7323484966538685327L;
41
42 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LookupForm.class);
43
44 private String dataObjectClassName;
45 private String docNum;
46 private String referencesToRefresh;
47
48 private boolean multipleValuesSelect;
49 private String lookupCollectionName;
50
51 private Map<String, String> criteriaFields;
52 private Map<String, String> fieldConversions;
53
54 private boolean atLeastOneRowReturnable;
55 private boolean atLeastOneRowHasActions;
56
57 private Collection<?> searchResults;
58
59 public LookupForm() {
60 super();
61
62 setViewTypeName(ViewType.LOOKUP);
63 atLeastOneRowReturnable = false;
64 atLeastOneRowHasActions = false;
65 multipleValuesSelect = false;
66
67 criteriaFields = new HashMap<String, String>();
68 fieldConversions = new HashMap<String, String>();
69 }
70
71
72
73
74
75 @Override
76 public void postBind(HttpServletRequest request) {
77 super.postBind(request);
78
79 try {
80 Lookupable lookupable = getLookupable();
81 if (lookupable == null) {
82 LOG.error("Lookupable not found for view id " + getView().getId());
83 throw new RuntimeException("Lookupable not found for view id " + getView().getId());
84 }
85
86 if (StringUtils.isBlank(getDataObjectClassName())) {
87 setDataObjectClassName(((LookupView) getView()).getDataObjectClassName().getName());
88 }
89
90
91 Class<?> dataObjectClass = Class.forName(getDataObjectClassName());
92 lookupable.setDataObjectClass(dataObjectClass);
93
94
95
96 if (!((LookupView) getView()).isShowMaintenanceLinks()) {
97
98 if (StringUtils.contains(getReturnLocation(), "/" + KRADConstants.PORTAL_ACTION) ||
99 StringUtils.contains(getReturnLocation(), "/index.html")) {
100 ((LookupView) getView()).setShowMaintenanceLinks(true);
101 }
102 }
103
104
105 lookupable.setReadOnlyFieldsList(getReadOnlyFieldsList());
106
107
108 if (request.getParameter(KRADConstants.CONVERSION_FIELDS_PARAMETER) != null) {
109 String conversionFields = request.getParameter(KRADConstants.CONVERSION_FIELDS_PARAMETER);
110 setFieldConversions(KRADUtils.convertStringParameterToMap(conversionFields));
111 lookupable.setFieldConversions(getFieldConversions());
112 }
113
114
115 Map<String, String> fieldValues = new HashMap<String, String>();
116 Map<String, String> formFields = getCriteriaFields();
117
118 if (formFields != null) {
119 for (Map.Entry<String, String> entry : formFields.entrySet()) {
120
121 fieldValues.put(entry.getKey(),
122 LookupUtils.forceUppercase(dataObjectClass, entry.getKey(), entry.getValue()));
123 }
124 }
125
126
127
128 if (StringUtils.isNotBlank(getDocNum())) {
129 fieldValues.put(KRADConstants.DOC_NUM, getDocNum());
130 }
131
132 this.setCriteriaFields(fieldValues);
133 } catch (ClassNotFoundException e) {
134 LOG.error("Object class " + getDataObjectClassName() + " not found");
135 throw new RuntimeException("Object class " + getDataObjectClassName() + " not found", e);
136 }
137 }
138
139 public Lookupable getLookupable() {
140 ViewHelperService viewHelperService = getView().getViewHelperService();
141 if (viewHelperService == null) {
142 LOG.error("ViewHelperService is null.");
143 throw new RuntimeException("ViewHelperService is null.");
144 }
145
146 if (!Lookupable.class.isAssignableFrom(viewHelperService.getClass())) {
147 LOG.error("ViewHelperService class '" + viewHelperService.getClass().getName() +
148 "' is not assignable from '" + Lookupable.class + "'");
149 throw new RuntimeException("ViewHelperService class '" + viewHelperService.getClass().getName() +
150 "' is not assignable from '" + Lookupable.class + "'");
151 }
152
153 return (Lookupable) viewHelperService;
154 }
155
156 protected Boolean processBooleanParameter(String parameterValue) {
157 if (StringUtils.isNotBlank(parameterValue)) {
158 if ("YES".equals(parameterValue.toUpperCase())) {
159 return Boolean.TRUE;
160 }
161 return new Boolean(parameterValue);
162 }
163 return null;
164 }
165
166 public String getDataObjectClassName() {
167 return this.dataObjectClassName;
168 }
169
170 public void setDataObjectClassName(String dataObjectClassName) {
171 this.dataObjectClassName = dataObjectClassName;
172 }
173
174 public String getDocNum() {
175 return this.docNum;
176 }
177
178 public void setDocNum(String docNum) {
179 this.docNum = docNum;
180 }
181
182 public String getReferencesToRefresh() {
183 return referencesToRefresh;
184 }
185
186 public void setReferencesToRefresh(String referencesToRefresh) {
187 this.referencesToRefresh = referencesToRefresh;
188 }
189
190
191
192
193
194
195
196
197
198
199
200 public boolean isMultipleValuesSelect() {
201 return multipleValuesSelect;
202 }
203
204
205
206
207
208
209 public void setMultipleValuesSelect(boolean multipleValuesSelect) {
210 this.multipleValuesSelect = multipleValuesSelect;
211 }
212
213
214
215
216
217
218
219 public String getLookupCollectionName() {
220 return lookupCollectionName;
221 }
222
223
224
225
226
227
228 public void setLookupCollectionName(String lookupCollectionName) {
229 this.lookupCollectionName = lookupCollectionName;
230 }
231
232 public Map<String, String> getCriteriaFields() {
233 return this.criteriaFields;
234 }
235
236 public void setCriteriaFields(Map<String, String> criteriaFields) {
237 this.criteriaFields = criteriaFields;
238 }
239
240 public Map<String, String> getFieldConversions() {
241 return this.fieldConversions;
242 }
243
244 public void setFieldConversions(Map<String, String> fieldConversions) {
245 this.fieldConversions = fieldConversions;
246 }
247
248 public Collection<?> getSearchResults() {
249 return this.searchResults;
250 }
251
252 public void setSearchResults(Collection<?> searchResults) {
253 this.searchResults = searchResults;
254 }
255
256 public boolean isAtLeastOneRowReturnable() {
257 return atLeastOneRowReturnable;
258 }
259
260 public void setAtLeastOneRowReturnable(boolean atLeastOneRowReturnable) {
261 this.atLeastOneRowReturnable = atLeastOneRowReturnable;
262 }
263
264 public boolean isAtLeastOneRowHasActions() {
265 return atLeastOneRowHasActions;
266 }
267
268 public void setAtLeastOneRowHasActions(boolean atLeastOneRowHasActions) {
269 this.atLeastOneRowHasActions = atLeastOneRowHasActions;
270 }
271 }