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