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.util.KRADConstants;
24 import org.kuali.rice.krad.util.KRADUtils;
25
26 import javax.servlet.http.HttpServletRequest;
27 import java.util.Collection;
28 import java.util.HashMap;
29 import java.util.Map;
30
31
32
33
34
35
36 public class LookupForm extends UifFormBase {
37 private static final long serialVersionUID = -7323484966538685327L;
38
39 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LookupForm.class);
40
41 private String dataObjectClassName;
42 private String docNum;
43 private String referencesToRefresh;
44
45 private boolean multipleValuesSelect;
46 private String lookupCollectionName;
47
48 private Map<String, String> lookupCriteria;
49 private Map<String, String> fieldConversions;
50
51 private Collection<?> lookupResults;
52
53 private boolean atLeastOneRowReturnable;
54 private boolean atLeastOneRowHasActions;
55
56 private boolean redirectedLookup;
57
58 public LookupForm() {
59 super();
60
61 setViewTypeName(ViewType.LOOKUP);
62 atLeastOneRowReturnable = false;
63 atLeastOneRowHasActions = false;
64 multipleValuesSelect = false;
65 redirectedLookup = false;
66
67 lookupCriteria = 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
83 return;
84 }
85
86 if (StringUtils.isBlank(getDataObjectClassName())) {
87 setDataObjectClassName(((LookupView) getView()).getDataObjectClassName().getName());
88 }
89 Class<?> dataObjectClass = Class.forName(getDataObjectClassName());
90 lookupable.setDataObjectClass(dataObjectClass);
91
92 if (request.getMethod().equals("GET")) {
93
94 if (request.getParameter(KRADConstants.CONVERSION_FIELDS_PARAMETER) != null) {
95 String conversionFields = request.getParameter(KRADConstants.CONVERSION_FIELDS_PARAMETER);
96 setFieldConversions(KRADUtils.convertStringParameterToMap(conversionFields));
97 }
98
99
100 Map<String, String> fieldValues = new HashMap<String, String>();
101 if (getLookupCriteria() != null) {
102 for (Map.Entry<String, String> entry : getLookupCriteria().entrySet()) {
103
104 fieldValues.put(entry.getKey(), LookupUtils.forceUppercase(dataObjectClass, entry.getKey(),
105 entry.getValue()));
106 }
107 }
108
109 if (StringUtils.isNotBlank(getDocNum())) {
110 fieldValues.put(KRADConstants.DOC_NUM, getDocNum());
111 }
112
113 this.setLookupCriteria(fieldValues);
114 }
115 } catch (ClassNotFoundException e) {
116 LOG.error("Object class " + getDataObjectClassName() + " not found");
117 throw new RuntimeException("Object class " + getDataObjectClassName() + " not found", e);
118 }
119 }
120
121 public Lookupable getLookupable() {
122 if ((getView() != null) && (getView().getViewHelperService() != null) && Lookupable.class.isAssignableFrom(
123 getView().getViewHelperService().getClass())) {
124 return (Lookupable) getView().getViewHelperService();
125 } else if ((getPostedView() != null) && (getPostedView().getViewHelperService() != null) && Lookupable.class
126 .isAssignableFrom(getPostedView().getViewHelperService().getClass())) {
127 return (Lookupable) getPostedView().getViewHelperService();
128 }
129
130 return null;
131 }
132
133 public String getDataObjectClassName() {
134 return this.dataObjectClassName;
135 }
136
137 public void setDataObjectClassName(String dataObjectClassName) {
138 this.dataObjectClassName = dataObjectClassName;
139 }
140
141 public String getDocNum() {
142 return this.docNum;
143 }
144
145 public void setDocNum(String docNum) {
146 this.docNum = docNum;
147 }
148
149 public String getReferencesToRefresh() {
150 return referencesToRefresh;
151 }
152
153 public void setReferencesToRefresh(String referencesToRefresh) {
154 this.referencesToRefresh = referencesToRefresh;
155 }
156
157
158
159
160
161
162
163
164
165
166
167 public boolean isMultipleValuesSelect() {
168 return multipleValuesSelect;
169 }
170
171
172
173
174
175
176 public void setMultipleValuesSelect(boolean multipleValuesSelect) {
177 this.multipleValuesSelect = multipleValuesSelect;
178 }
179
180
181
182
183
184
185
186 public String getLookupCollectionName() {
187 return lookupCollectionName;
188 }
189
190
191
192
193
194
195 public void setLookupCollectionName(String lookupCollectionName) {
196 this.lookupCollectionName = lookupCollectionName;
197 }
198
199 public Map<String, String> getLookupCriteria() {
200 return this.lookupCriteria;
201 }
202
203 public void setLookupCriteria(Map<String, String> lookupCriteria) {
204 this.lookupCriteria = lookupCriteria;
205 }
206
207 public Map<String, String> getFieldConversions() {
208 return this.fieldConversions;
209 }
210
211 public void setFieldConversions(Map<String, String> fieldConversions) {
212 this.fieldConversions = fieldConversions;
213 }
214
215 public Collection<?> getLookupResults() {
216 return this.lookupResults;
217 }
218
219 public void setLookupResults(Collection<?> lookupResults) {
220 this.lookupResults = lookupResults;
221 }
222
223 public boolean isAtLeastOneRowReturnable() {
224 return atLeastOneRowReturnable;
225 }
226
227 public void setAtLeastOneRowReturnable(boolean atLeastOneRowReturnable) {
228 this.atLeastOneRowReturnable = atLeastOneRowReturnable;
229 }
230
231 public boolean isAtLeastOneRowHasActions() {
232 return atLeastOneRowHasActions;
233 }
234
235 public void setAtLeastOneRowHasActions(boolean atLeastOneRowHasActions) {
236 this.atLeastOneRowHasActions = atLeastOneRowHasActions;
237 }
238
239
240
241
242
243
244
245 public boolean isRedirectedLookup() {
246 return redirectedLookup;
247 }
248
249
250
251
252
253
254 public void setRedirectedLookup(boolean redirectedLookup) {
255 this.redirectedLookup = redirectedLookup;
256 }
257 }