Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
UifFormBase |
|
| 1.0892857142857142;1.089 |
1 | /* | |
2 | * Copyright 2007 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 1.0 (the | |
5 | * "License"); you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl1.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
13 | * License for the specific language governing permissions and limitations under | |
14 | * the License. | |
15 | */ | |
16 | package org.kuali.rice.krad.web.form; | |
17 | ||
18 | import org.kuali.rice.krad.service.KRADServiceLocatorWeb; | |
19 | import org.kuali.rice.krad.uif.container.View; | |
20 | import org.kuali.rice.krad.uif.history.History; | |
21 | import org.kuali.rice.krad.uif.service.ViewService; | |
22 | import org.springframework.web.multipart.MultipartFile; | |
23 | ||
24 | import javax.servlet.http.HttpServletRequest; | |
25 | import java.io.Serializable; | |
26 | import java.util.HashMap; | |
27 | import java.util.Map; | |
28 | import java.util.Properties; | |
29 | import java.util.UUID; | |
30 | ||
31 | /** | |
32 | * Base form class for views within the KRAD User Interface Framework | |
33 | * | |
34 | * <p> | |
35 | * Holds properties necessary to determine the <code>View</code> instance that | |
36 | * will be used to render the UI | |
37 | * </p> | |
38 | * | |
39 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
40 | */ | |
41 | public class UifFormBase implements Serializable { | |
42 | private static final long serialVersionUID = 8432543267099454434L; | |
43 | ||
44 | private History formHistory; | |
45 | ||
46 | // current view | |
47 | protected String viewId; | |
48 | protected String viewName; | |
49 | protected String viewTypeName; | |
50 | protected String pageId; | |
51 | protected String methodToCall; | |
52 | protected String formKey; | |
53 | protected String jumpToId; | |
54 | protected String jumpToName; | |
55 | protected String focusId; | |
56 | protected String formPostUrl; | |
57 | ||
58 | protected boolean defaultsApplied; | |
59 | ||
60 | protected View view; | |
61 | protected View previousView; | |
62 | protected Map<String, String> viewRequestParameters; | |
63 | ||
64 | protected Map<String, Object> newCollectionLines; | |
65 | protected Map<String, String> actionParameters; | |
66 | ||
67 | protected MultipartFile attachmentFile; | |
68 | ||
69 | // navigation | |
70 | protected String returnLocation; | |
71 | protected String returnFormKey; | |
72 | protected String hubLocation; | |
73 | protected String hubFormKey; | |
74 | protected String homeLocation; | |
75 | ||
76 | protected boolean renderFullView; | |
77 | protected boolean validateDirty; | |
78 | ||
79 | 0 | public UifFormBase() { |
80 | 0 | formKey = generateFormKey(); |
81 | 0 | renderFullView = true; |
82 | 0 | defaultsApplied = false; |
83 | ||
84 | 0 | viewRequestParameters = new HashMap<String, String>(); |
85 | 0 | newCollectionLines = new HashMap<String, Object>(); |
86 | 0 | actionParameters = new HashMap<String, String>(); |
87 | 0 | } |
88 | ||
89 | /** | |
90 | * Creates the unique id used to store this "conversation" in the session. | |
91 | * The default method generates a java UUID. | |
92 | * | |
93 | * @return | |
94 | */ | |
95 | protected String generateFormKey() { | |
96 | 0 | return UUID.randomUUID().toString(); |
97 | } | |
98 | ||
99 | /** | |
100 | * Called after Spring binds the request to the form and before the | |
101 | * controller method is invoked. | |
102 | * | |
103 | * @param request | |
104 | * - request object containing the query parameters | |
105 | */ | |
106 | public void postBind(HttpServletRequest request) { | |
107 | // default form post URL to request URL | |
108 | 0 | formPostUrl = request.getRequestURL().toString(); |
109 | 0 | } |
110 | ||
111 | /** | |
112 | * Unique Id for the <code>View</code> instance. This is specified for a | |
113 | * view in its definition by setting the 'id' property. | |
114 | * | |
115 | * @return String view id | |
116 | */ | |
117 | public String getViewId() { | |
118 | 0 | return this.viewId; |
119 | } | |
120 | ||
121 | /** | |
122 | * Setter for the unique view id | |
123 | * | |
124 | * @param viewId | |
125 | */ | |
126 | public void setViewId(String viewId) { | |
127 | 0 | this.viewId = viewId; |
128 | 0 | } |
129 | ||
130 | /** | |
131 | * Name for the <code>View</code> instance. This is specified for a view in | |
132 | * its definition by setting the 'id' property. The name is not necessary | |
133 | * unique and cannot be used by itself to retrieve a view. Typically it is | |
134 | * used with other parameters to identify a view with a certain type (view | |
135 | * type) | |
136 | * | |
137 | * @return String view name | |
138 | */ | |
139 | public String getViewName() { | |
140 | 0 | return this.viewName; |
141 | } | |
142 | ||
143 | /** | |
144 | * Setter for the view name | |
145 | * | |
146 | * @param viewName | |
147 | */ | |
148 | public void setViewName(String viewName) { | |
149 | 0 | this.viewName = viewName; |
150 | 0 | } |
151 | ||
152 | /** | |
153 | * Name for the type of view being requested. This can be used to find | |
154 | * <code>View</code> instances by request parameters (not necessary the | |
155 | * unique id) | |
156 | * | |
157 | * @return String view type name | |
158 | */ | |
159 | public String getViewTypeName() { | |
160 | 0 | return this.viewTypeName; |
161 | } | |
162 | ||
163 | /** | |
164 | * Setter for the view type name | |
165 | * | |
166 | * @param viewTypeName | |
167 | */ | |
168 | public void setViewTypeName(String viewTypeName) { | |
169 | 0 | this.viewTypeName = viewTypeName; |
170 | 0 | } |
171 | ||
172 | /** | |
173 | * Id for the current page being displayed within the view | |
174 | * | |
175 | * @return String page id | |
176 | */ | |
177 | public String getPageId() { | |
178 | 0 | return this.pageId; |
179 | } | |
180 | ||
181 | /** | |
182 | * Setter for the current page id | |
183 | * | |
184 | * @param pageId | |
185 | */ | |
186 | public void setPageId(String pageId) { | |
187 | 0 | this.pageId = pageId; |
188 | 0 | } |
189 | ||
190 | public String getFormPostUrl() { | |
191 | 0 | return this.formPostUrl; |
192 | } | |
193 | ||
194 | public void setFormPostUrl(String formPostUrl) { | |
195 | 0 | this.formPostUrl = formPostUrl; |
196 | 0 | } |
197 | ||
198 | public String getReturnLocation() { | |
199 | 0 | return this.returnLocation; |
200 | } | |
201 | ||
202 | public void setReturnLocation(String returnLocation) { | |
203 | 0 | this.returnLocation = returnLocation; |
204 | 0 | } |
205 | ||
206 | public String getReturnFormKey() { | |
207 | 0 | return this.returnFormKey; |
208 | } | |
209 | ||
210 | public void setReturnFormKey(String returnFormKey) { | |
211 | 0 | this.returnFormKey = returnFormKey; |
212 | 0 | } |
213 | ||
214 | public String getHubLocation() { | |
215 | 0 | return this.hubLocation; |
216 | } | |
217 | ||
218 | public void setHubLocation(String hubLocation) { | |
219 | 0 | this.hubLocation = hubLocation; |
220 | 0 | } |
221 | ||
222 | public String getHubFormKey() { | |
223 | 0 | return this.hubFormKey; |
224 | } | |
225 | ||
226 | public void setHubFormKey(String hubFormKey) { | |
227 | 0 | this.hubFormKey = hubFormKey; |
228 | 0 | } |
229 | ||
230 | public String getHomeLocation() { | |
231 | 0 | return this.homeLocation; |
232 | } | |
233 | ||
234 | public void setHomeLocation(String homeLocation) { | |
235 | 0 | this.homeLocation = homeLocation; |
236 | 0 | } |
237 | ||
238 | /** | |
239 | * Identifies the controller method that should be invoked to fulfill a | |
240 | * request. The value will be matched up against the 'params' setting on the | |
241 | * <code>RequestMapping</code> annotation for the controller method | |
242 | * | |
243 | * @return String method to call | |
244 | */ | |
245 | public String getMethodToCall() { | |
246 | 0 | return this.methodToCall; |
247 | } | |
248 | ||
249 | /** | |
250 | * Setter for the method to call | |
251 | * | |
252 | * @param methodToCall | |
253 | */ | |
254 | public void setMethodToCall(String methodToCall) { | |
255 | 0 | this.methodToCall = methodToCall; |
256 | 0 | } |
257 | ||
258 | /** | |
259 | * Map of parameters that was used to configured the <code>View</code>. | |
260 | * Maintained on the form to rebuild the view on posts and session timeout | |
261 | * | |
262 | * @return Map<String, String> view parameters | |
263 | * @see org.kuali.rice.krad.uif.container.View.getViewRequestParameters() | |
264 | */ | |
265 | public Map<String, String> getViewRequestParameters() { | |
266 | 0 | return this.viewRequestParameters; |
267 | } | |
268 | ||
269 | /** | |
270 | * Setter for the view's request parameter map | |
271 | * | |
272 | * @param viewRequestParameters | |
273 | */ | |
274 | public void setViewRequestParameters(Map<String, String> viewRequestParameters) { | |
275 | 0 | this.viewRequestParameters = viewRequestParameters; |
276 | 0 | } |
277 | ||
278 | /** | |
279 | * Holds instances for collection add lines. The key of the Map gives the | |
280 | * collection name the line instance applies to, the Map value is an | |
281 | * instance of the collection object class that holds the new line data | |
282 | * | |
283 | * @return Map<String, Object> new collection lines | |
284 | */ | |
285 | public Map<String, Object> getNewCollectionLines() { | |
286 | 0 | return this.newCollectionLines; |
287 | } | |
288 | ||
289 | /** | |
290 | * Setter for the new collection lines Map | |
291 | * | |
292 | * @param newCollectionLines | |
293 | */ | |
294 | public void setNewCollectionLines(Map<String, Object> newCollectionLines) { | |
295 | 0 | this.newCollectionLines = newCollectionLines; |
296 | 0 | } |
297 | ||
298 | /** | |
299 | * Map of parameters sent for the invoked action | |
300 | * <p> | |
301 | * Many times besides just setting the method to call actions need to send | |
302 | * additional parameters. For instance the method being called might do a | |
303 | * redirect, in which case the action needs to send parameters for the | |
304 | * redirect URL. An example of this is redirecting to a <code>Lookup</code> | |
305 | * view. In some cases the parameters that need to be sent conflict with | |
306 | * properties already on the form, and putting all the action parameters as | |
307 | * form properties would grow massive (in addition to adds an additional | |
308 | * step from the XML config). So this general map solves those issues. | |
309 | * </p> | |
310 | * | |
311 | * @return Map<String, String> action parameters | |
312 | */ | |
313 | public Map<String, String> getActionParameters() { | |
314 | 0 | return this.actionParameters; |
315 | } | |
316 | ||
317 | /** | |
318 | * Returns the action parameters map as a <code>Properties</code> instance | |
319 | * | |
320 | * @return Properties action parameters | |
321 | */ | |
322 | public Properties getActionParametersAsProperties() { | |
323 | 0 | Properties actionProperties = new Properties(); |
324 | ||
325 | 0 | if (actionParameters != null) { |
326 | 0 | for (Map.Entry<String, String> actionParameter : actionParameters.entrySet()) { |
327 | 0 | actionProperties.put(actionParameter.getKey(), actionParameter.getValue()); |
328 | } | |
329 | } | |
330 | ||
331 | 0 | return actionProperties; |
332 | } | |
333 | ||
334 | /** | |
335 | * Setter for the action parameters map | |
336 | * | |
337 | * @param actionParameters | |
338 | */ | |
339 | public void setActionParameters(Map<String, String> actionParameters) { | |
340 | 0 | this.actionParameters = actionParameters; |
341 | 0 | } |
342 | ||
343 | /** | |
344 | * Retrieves the value for the given action parameter, or empty string if | |
345 | * not found | |
346 | * | |
347 | * @param actionParameterName | |
348 | * - name of the action parameter to retrieve value for | |
349 | * @return String parameter value or empty string | |
350 | */ | |
351 | public String getActionParamaterValue(String actionParameterName) { | |
352 | 0 | if ((actionParameters != null) && actionParameters.containsKey(actionParameterName)) { |
353 | 0 | return actionParameters.get(actionParameterName); |
354 | } | |
355 | ||
356 | 0 | return ""; |
357 | } | |
358 | ||
359 | /** | |
360 | * Key string that identifies the form instance in session storage | |
361 | * <p> | |
362 | * When the view is posted, the previous form instance is retrieved and then | |
363 | * populated from the request parameters. This key string is retrieve the | |
364 | * session form from the session service | |
365 | * </p> | |
366 | * | |
367 | * @return String form session key | |
368 | */ | |
369 | public String getFormKey() { | |
370 | 0 | return this.formKey; |
371 | } | |
372 | ||
373 | /** | |
374 | * Setter for the form's session key | |
375 | * | |
376 | * @param formKey | |
377 | */ | |
378 | public void setFormKey(String formKey) { | |
379 | 0 | this.formKey = formKey; |
380 | 0 | } |
381 | ||
382 | /** | |
383 | * Indicates whether the form has had default values from the configured | |
384 | * <code>View</code> applied. This happens only once for each form instance | |
385 | * | |
386 | * @return boolean true if default values have been applied, false if not | |
387 | */ | |
388 | public boolean isDefaultsApplied() { | |
389 | 0 | return this.defaultsApplied; |
390 | } | |
391 | ||
392 | /** | |
393 | * Setter for the defaults applied indicator | |
394 | * | |
395 | * @param defaultsApplied | |
396 | */ | |
397 | public void setDefaultsApplied(boolean defaultsApplied) { | |
398 | 0 | this.defaultsApplied = defaultsApplied; |
399 | 0 | } |
400 | ||
401 | /** | |
402 | * Holder for files that are attached through the view | |
403 | * | |
404 | * @return MultipartFile representing the attachment | |
405 | */ | |
406 | public MultipartFile getAttachmentFile() { | |
407 | 0 | return this.attachmentFile; |
408 | } | |
409 | ||
410 | /** | |
411 | * Setter for the form's attachment file | |
412 | * | |
413 | * @param attachmentFile | |
414 | */ | |
415 | public void setAttachmentFile(MultipartFile attachmentFile) { | |
416 | 0 | this.attachmentFile = attachmentFile; |
417 | 0 | } |
418 | ||
419 | /** | |
420 | * @return the renderFullView | |
421 | */ | |
422 | public boolean isRenderFullView() { | |
423 | 0 | return this.renderFullView; |
424 | } | |
425 | ||
426 | /** | |
427 | * @param renderFullView | |
428 | */ | |
429 | public void setRenderFullView(boolean renderFullView) { | |
430 | 0 | this.renderFullView = renderFullView; |
431 | 0 | } |
432 | ||
433 | /** | |
434 | * View instance associated with the form. Used to render the user interface | |
435 | * | |
436 | * @return View | |
437 | */ | |
438 | public View getView() { | |
439 | 0 | return this.view; |
440 | } | |
441 | ||
442 | /** | |
443 | * Setter for the view instance | |
444 | * | |
445 | * @param view | |
446 | */ | |
447 | public void setView(View view) { | |
448 | 0 | this.view = view; |
449 | 0 | } |
450 | ||
451 | /** | |
452 | * View instance for the page that made a request. Since a new view instance | |
453 | * gets initialized for each request before the controller logic is invoked, | |
454 | * any state about the previous view is lost. This could be needed to read | |
455 | * metadata from the view for such things as collection processing. When | |
456 | * this is necessary the previous view instance can be retrieved | |
457 | * | |
458 | * @return View instance | |
459 | */ | |
460 | public View getPreviousView() { | |
461 | 0 | return this.previousView; |
462 | } | |
463 | ||
464 | /** | |
465 | * Setter for the previous view instance | |
466 | * | |
467 | * @param previousView | |
468 | */ | |
469 | public void setPreviousView(View previousView) { | |
470 | 0 | this.previousView = previousView; |
471 | 0 | } |
472 | ||
473 | /** | |
474 | * Instance of the <code>ViewService</code> that can be used to retrieve | |
475 | * <code>View</code> instances | |
476 | * | |
477 | * @return ViewService implementation | |
478 | */ | |
479 | protected ViewService getViewService() { | |
480 | 0 | return KRADServiceLocatorWeb.getViewService(); |
481 | } | |
482 | ||
483 | /** | |
484 | * The jumpToId for this form, the element with this id will be jumped to automatically | |
485 | * when the form is loaded in the view. | |
486 | * Using "TOP" or "BOTTOM" will jump to the top or the bottom of the resulting page. | |
487 | * jumpToId always takes precedence over jumpToName, if set. | |
488 | * | |
489 | * @return the jumpToId | |
490 | */ | |
491 | public String getJumpToId() { | |
492 | 0 | return this.jumpToId; |
493 | } | |
494 | ||
495 | /** | |
496 | * @param jumpToId the jumpToId to set | |
497 | */ | |
498 | public void setJumpToId(String jumpToId) { | |
499 | 0 | this.jumpToId = jumpToId; |
500 | 0 | } |
501 | ||
502 | /** | |
503 | * The jumpToName for this form, the element with this name will be jumped to automatically | |
504 | * when the form is loaded in the view. | |
505 | * WARNING: jumpToId always takes precedence over jumpToName, if set. | |
506 | * | |
507 | * @return the jumpToName | |
508 | */ | |
509 | public String getJumpToName() { | |
510 | 0 | return this.jumpToName; |
511 | } | |
512 | ||
513 | /** | |
514 | * @param jumpToName the jumpToName to set | |
515 | */ | |
516 | public void setJumpToName(String jumpToName) { | |
517 | 0 | this.jumpToName = jumpToName; |
518 | 0 | } |
519 | ||
520 | /** | |
521 | * Field to place focus on when the page loads | |
522 | * An empty focusId will result in focusing on the first visible input element by default. | |
523 | * | |
524 | * @return the focusId | |
525 | */ | |
526 | public String getFocusId() { | |
527 | 0 | return this.focusId; |
528 | } | |
529 | ||
530 | /** | |
531 | * @param focusId the focusId to set | |
532 | */ | |
533 | public void setFocusId(String focusId) { | |
534 | 0 | this.focusId = focusId; |
535 | 0 | } |
536 | ||
537 | /** | |
538 | * History parameter representing the History of views that have come before the | |
539 | * viewing of the current view. Used for breadcrumb widget generation on the view. | |
540 | * | |
541 | * @param history the history to set | |
542 | */ | |
543 | public void setFormHistory(History history) { | |
544 | 0 | this.formHistory = history; |
545 | 0 | } |
546 | ||
547 | /** | |
548 | * @return the history | |
549 | */ | |
550 | public History getFormHistory() { | |
551 | 0 | return formHistory; |
552 | } | |
553 | ||
554 | public boolean isValidateDirty() { | |
555 | 0 | return this.validateDirty; |
556 | } | |
557 | ||
558 | /** | |
559 | * Setter for dirty validation. | |
560 | */ | |
561 | public void setValidateDirty(boolean validateDirty) { | |
562 | 0 | this.validateDirty = validateDirty; |
563 | 0 | } |
564 | ||
565 | } |