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