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 private boolean redirectedLookup;
60
61 public LookupForm() {
62 super();
63
64 setViewTypeName(ViewType.LOOKUP);
65 atLeastOneRowReturnable = false;
66 atLeastOneRowHasActions = false;
67 multipleValuesSelect = false;
68 redirectedLookup = false;
69
70 criteriaFields = new HashMap<String, String>();
71 fieldConversions = new HashMap<String, String>();
72 }
73
74
75
76
77
78 @Override
79 public void postBind(HttpServletRequest request) {
80 super.postBind(request);
81
82 try {
83 Lookupable lookupable = getLookupable();
84 if (lookupable == null) {
85
86 return;
87 }
88
89 if (StringUtils.isBlank(getDataObjectClassName())) {
90 setDataObjectClassName(((LookupView) getView()).getDataObjectClassName().getName());
91 }
92
93
94 Class<?> dataObjectClass = Class.forName(getDataObjectClassName());
95 lookupable.setDataObjectClass(dataObjectClass);
96
97
98
99 if (!((LookupView) getView()).isShowMaintenanceLinks()) {
100
101 if (StringUtils.contains(getReturnLocation(), "/" + KRADConstants.PORTAL_ACTION) ||
102 StringUtils.contains(getReturnLocation(), "/index.html")) {
103 ((LookupView) getView()).setShowMaintenanceLinks(true);
104 }
105 }
106
107
108 lookupable.setReadOnlyFieldsList(getReadOnlyFieldsList());
109
110
111 if (request.getParameter(KRADConstants.CONVERSION_FIELDS_PARAMETER) != null) {
112 String conversionFields = request.getParameter(KRADConstants.CONVERSION_FIELDS_PARAMETER);
113 setFieldConversions(KRADUtils.convertStringParameterToMap(conversionFields));
114 lookupable.setFieldConversions(getFieldConversions());
115 }
116
117
118 Map<String, String> fieldValues = new HashMap<String, String>();
119 Map<String, String> formFields = getCriteriaFields();
120
121 if (formFields != null) {
122 for (Map.Entry<String, String> entry : formFields.entrySet()) {
123
124 fieldValues.put(entry.getKey(),
125 LookupUtils.forceUppercase(dataObjectClass, entry.getKey(), entry.getValue()));
126 }
127 }
128
129
130
131 if (StringUtils.isNotBlank(getDocNum())) {
132 fieldValues.put(KRADConstants.DOC_NUM, getDocNum());
133 }
134
135 this.setCriteriaFields(fieldValues);
136 } catch (ClassNotFoundException e) {
137 LOG.error("Object class " + getDataObjectClassName() + " not found");
138 throw new RuntimeException("Object class " + getDataObjectClassName() + " not found", e);
139 }
140 }
141
142 public Lookupable getLookupable() {
143 if ((getView() != null) && Lookupable.class.isAssignableFrom(getView().getViewHelperService().getClass())) {
144 return (Lookupable) getView().getViewHelperService();
145 }
146
147 return null;
148 }
149
150 public String getDataObjectClassName() {
151 return this.dataObjectClassName;
152 }
153
154 public void setDataObjectClassName(String dataObjectClassName) {
155 this.dataObjectClassName = dataObjectClassName;
156 }
157
158 public String getDocNum() {
159 return this.docNum;
160 }
161
162 public void setDocNum(String docNum) {
163 this.docNum = docNum;
164 }
165
166 public String getReferencesToRefresh() {
167 return referencesToRefresh;
168 }
169
170 public void setReferencesToRefresh(String referencesToRefresh) {
171 this.referencesToRefresh = referencesToRefresh;
172 }
173
174
175
176
177
178
179
180
181
182
183
184 public boolean isMultipleValuesSelect() {
185 return multipleValuesSelect;
186 }
187
188
189
190
191
192
193 public void setMultipleValuesSelect(boolean multipleValuesSelect) {
194 this.multipleValuesSelect = multipleValuesSelect;
195 }
196
197
198
199
200
201
202
203 public String getLookupCollectionName() {
204 return lookupCollectionName;
205 }
206
207
208
209
210
211
212 public void setLookupCollectionName(String lookupCollectionName) {
213 this.lookupCollectionName = lookupCollectionName;
214 }
215
216 public Map<String, String> getCriteriaFields() {
217 return this.criteriaFields;
218 }
219
220 public void setCriteriaFields(Map<String, String> criteriaFields) {
221 this.criteriaFields = criteriaFields;
222 }
223
224 public Map<String, String> getFieldConversions() {
225 return this.fieldConversions;
226 }
227
228 public void setFieldConversions(Map<String, String> fieldConversions) {
229 this.fieldConversions = fieldConversions;
230 }
231
232 public Collection<?> getSearchResults() {
233 return this.searchResults;
234 }
235
236 public void setSearchResults(Collection<?> searchResults) {
237 this.searchResults = searchResults;
238 }
239
240 public boolean isAtLeastOneRowReturnable() {
241 return atLeastOneRowReturnable;
242 }
243
244 public void setAtLeastOneRowReturnable(boolean atLeastOneRowReturnable) {
245 this.atLeastOneRowReturnable = atLeastOneRowReturnable;
246 }
247
248 public boolean isAtLeastOneRowHasActions() {
249 return atLeastOneRowHasActions;
250 }
251
252 public void setAtLeastOneRowHasActions(boolean atLeastOneRowHasActions) {
253 this.atLeastOneRowHasActions = atLeastOneRowHasActions;
254 }
255
256
257
258
259
260
261
262 public boolean isRedirectedLookup() {
263 return redirectedLookup;
264 }
265
266
267
268
269
270
271 public void setRedirectedLookup(boolean redirectedLookup) {
272 this.redirectedLookup = redirectedLookup;
273 }
274 }