1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.web.struts.action;
17
18 import org.apache.commons.lang.ObjectUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.apache.struts.action.ActionForm;
21 import org.apache.struts.action.ActionForward;
22 import org.apache.struts.action.ActionMapping;
23 import org.apache.struts.actions.DispatchAction;
24 import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
25 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
26 import org.kuali.rice.core.api.CoreApiServiceLocator;
27 import org.kuali.rice.core.api.encryption.EncryptionService;
28 import org.kuali.rice.core.api.util.RiceConstants;
29 import org.kuali.rice.kew.api.KewApiConstants;
30 import org.kuali.rice.kim.api.KimConstants;
31 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
32 import org.kuali.rice.kns.document.authorization.DocumentAuthorizerBase;
33 import org.kuali.rice.kns.lookup.LookupUtils;
34 import org.kuali.rice.kns.service.BusinessObjectAuthorizationService;
35 import org.kuali.rice.kns.service.KNSServiceLocator;
36 import org.kuali.rice.kns.util.KNSGlobalVariables;
37 import org.kuali.rice.kns.util.WebUtils;
38 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
39 import org.kuali.rice.kns.web.struts.form.KualiForm;
40 import org.kuali.rice.kns.web.struts.form.LookupForm;
41 import org.kuali.rice.kns.web.struts.form.pojo.PojoForm;
42 import org.kuali.rice.kns.web.struts.form.pojo.PojoFormBase;
43 import org.kuali.rice.krad.bo.BusinessObject;
44 import org.kuali.rice.krad.exception.AuthorizationException;
45 import org.kuali.rice.krad.service.KRADServiceLocator;
46 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
47 import org.kuali.rice.krad.service.KualiModuleService;
48 import org.kuali.rice.krad.service.ModuleService;
49 import org.kuali.rice.krad.util.GlobalVariables;
50 import org.kuali.rice.krad.util.KRADConstants;
51 import org.kuali.rice.krad.util.KRADUtils;
52 import org.kuali.rice.krad.util.UrlFactory;
53
54 import javax.servlet.http.HttpServletRequest;
55 import javax.servlet.http.HttpServletResponse;
56 import java.util.Arrays;
57 import java.util.Enumeration;
58 import java.util.HashMap;
59 import java.util.HashSet;
60 import java.util.Map;
61 import java.util.Properties;
62 import java.util.Set;
63
64
65
66
67
68
69
70
71
72
73
74 public abstract class KualiAction extends DispatchAction {
75 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KualiAction.class);
76
77 private static KualiModuleService kualiModuleService = null;
78 private static BusinessObjectAuthorizationService businessObjectAuthorizationService = null;
79 private static EncryptionService encryptionService = null;
80 private static Boolean OUTPUT_ENCRYPTION_WARNING = null;
81 private static String applicationBaseUrl = null;
82
83 private Set<String> methodToCallsToNotCheckAuthorization = new HashSet<String>();
84
85 {
86 methodToCallsToNotCheckAuthorization.add( "performLookup" );
87 methodToCallsToNotCheckAuthorization.add( "performQuestion" );
88 methodToCallsToNotCheckAuthorization.add( "performQuestionWithInput" );
89 methodToCallsToNotCheckAuthorization.add( "performQuestionWithInputAgainBecauseOfErrors" );
90 methodToCallsToNotCheckAuthorization.add( "performQuestionWithoutInput" );
91 methodToCallsToNotCheckAuthorization.add( "performWorkgroupLookup" );
92 }
93
94
95
96
97
98
99
100
101
102
103
104 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
105 ActionForward returnForward = null;
106
107 String methodToCall = findMethodToCall(form, request);
108
109 if(isModuleLocked(form, methodToCall, request)) {
110 return mapping.findForward(RiceConstants.MODULE_LOCKED_MAPPING);
111 }
112
113 if (form instanceof KualiForm && StringUtils.isNotEmpty(((KualiForm) form).getMethodToCall())) {
114 if (StringUtils.isNotBlank(getImageContext(request, KRADConstants.ANCHOR))) {
115 ((KualiForm) form).setAnchor(getImageContext(request, KRADConstants.ANCHOR));
116 }
117 else if (StringUtils.isNotBlank(request.getParameter(KRADConstants.ANCHOR))) {
118 ((KualiForm) form).setAnchor(request.getParameter(KRADConstants.ANCHOR));
119 }
120 else {
121 ((KualiForm) form).setAnchor(KRADConstants.ANCHOR_TOP_OF_FORM);
122 }
123 }
124
125 if (StringUtils.isNotBlank(methodToCall)) {
126 if ( LOG.isDebugEnabled() ) {
127 LOG.debug("methodToCall: '" + methodToCall+"'");
128 }
129 returnForward = dispatchMethod(mapping, form, request, response, methodToCall);
130 if ( returnForward!=null && returnForward.getRedirect() && returnForward.getName()!=null && returnForward.getName().equals(KRADConstants.KRAD_INITIATED_DOCUMENT_VIEW_NAME)) {
131 return returnForward;
132 }
133 }
134 else {
135 returnForward = defaultDispatch(mapping, form, request, response);
136 }
137
138
139 if ( !methodToCallsToNotCheckAuthorization.contains(methodToCall) ) {
140 if ( LOG.isDebugEnabled() ) {
141 LOG.debug( "'" + methodToCall + "' not in set of excempt methods: " + methodToCallsToNotCheckAuthorization);
142 }
143 checkAuthorization(form, methodToCall);
144 } else {
145 if ( LOG.isDebugEnabled() ) {
146 LOG.debug("'" + methodToCall + "' is exempt from auth checks." );
147 }
148 }
149
150
151
152
153 if(KNSGlobalVariables.getKualiForm() == null) {
154 KNSGlobalVariables.setKualiForm((KualiForm)form);
155 }
156
157 return returnForward;
158 }
159
160
161
162
163
164 protected ActionForward defaultDispatch(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
165 return mapping.findForward(RiceConstants.MAPPING_BASIC);
166 }
167
168 @Override
169 protected ActionForward dispatchMethod(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String methodToCall) throws Exception {
170 GlobalVariables.getUserSession().addObject(DocumentAuthorizerBase.USER_SESSION_METHOD_TO_CALL_OBJECT_KEY, methodToCall);
171 return super.dispatchMethod(mapping, form, request, response, methodToCall);
172 }
173
174 protected String findMethodToCall(ActionForm form, HttpServletRequest request) throws Exception {
175 String methodToCall;
176 if (form instanceof KualiForm && StringUtils.isNotEmpty(((KualiForm) form).getMethodToCall())) {
177 methodToCall = ((KualiForm) form).getMethodToCall();
178 }
179 else {
180
181 methodToCall = WebUtils.parseMethodToCall(form, request);
182 }
183 return methodToCall;
184 }
185
186
187
188
189
190
191
192
193
194
195
196 public ActionForward toggleTab(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
197 KualiForm kualiForm = (KualiForm) form;
198 String tabToToggle = getTabToToggle(request);
199 if (StringUtils.isNotBlank(tabToToggle)) {
200 if (kualiForm.getTabState(tabToToggle).equals(KualiForm.TabState.OPEN.name())) {
201 kualiForm.getTabStates().remove(tabToToggle);
202 kualiForm.getTabStates().put(tabToToggle, KualiForm.TabState.CLOSE.name());
203 }
204 else {
205 kualiForm.getTabStates().remove(tabToToggle);
206 kualiForm.getTabStates().put(tabToToggle, KualiForm.TabState.OPEN.name());
207 }
208 }
209
210 doProcessingAfterPost( kualiForm, request );
211 return mapping.findForward(RiceConstants.MAPPING_BASIC);
212 }
213
214
215
216
217
218
219
220
221
222
223
224 public ActionForward showAllTabs(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
225 return this.doTabOpenOrClose(mapping, form, request, response, true);
226 }
227
228
229
230
231
232
233
234
235
236
237
238 public ActionForward hideAllTabs(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
239 return this.doTabOpenOrClose(mapping, form, request, response, false);
240 }
241
242
243
244
245
246
247
248
249
250
251
252
253 private ActionForward doTabOpenOrClose(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, boolean open) {
254 KualiForm kualiForm = (KualiForm) form;
255
256 Map<String, String> tabStates = kualiForm.getTabStates();
257 Map<String, String> newTabStates = new HashMap<String, String>();
258 for (String tabKey: tabStates.keySet()) {
259 newTabStates.put(tabKey, open ? "OPEN" : "CLOSE");
260 }
261 kualiForm.setTabStates(newTabStates);
262 doProcessingAfterPost( kualiForm, request );
263 return mapping.findForward(RiceConstants.MAPPING_BASIC);
264 }
265
266
267
268
269
270
271
272
273
274
275
276 public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
277 return mapping.findForward(RiceConstants.MAPPING_BASIC);
278 }
279
280
281
282
283
284
285
286
287 protected int getLineToDelete(HttpServletRequest request) {
288 return getSelectedLine(request);
289 }
290
291
292
293
294
295
296
297 protected int getLineToEdit(HttpServletRequest request) {
298 return getSelectedLine(request);
299 }
300
301
302
303
304
305
306
307 protected int getSelectedLine(HttpServletRequest request) {
308 int selectedLine = -1;
309 String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
310 if (StringUtils.isNotBlank(parameterName)) {
311 String lineNumber = StringUtils.substringBetween(parameterName, ".line", ".");
312 if (StringUtils.isEmpty(lineNumber)) {
313 return selectedLine;
314 }
315 selectedLine = Integer.parseInt(lineNumber);
316 }
317
318 return selectedLine;
319 }
320
321
322
323
324
325
326
327 protected String getTabToToggle(HttpServletRequest request) {
328 String tabToToggle = "";
329 String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
330 if (StringUtils.isNotBlank(parameterName)) {
331 tabToToggle = StringUtils.substringBetween(parameterName, ".tab", ".");
332 }
333
334 return tabToToggle;
335 }
336
337
338
339
340
341
342
343 protected String getHeaderTabNavigateTo(HttpServletRequest request) {
344 String headerTabNavigateTo = RiceConstants.MAPPING_BASIC;
345 String imageContext = getImageContext(request, KRADConstants.NAVIGATE_TO);
346 if (StringUtils.isNotBlank(imageContext)) {
347 headerTabNavigateTo = imageContext;
348 }
349 return headerTabNavigateTo;
350 }
351
352
353
354
355
356
357
358 protected String getHeaderTabDispatch(HttpServletRequest request) {
359 String headerTabDispatch = null;
360 String imageContext = getImageContext(request, KRADConstants.HEADER_DISPATCH);
361 if (StringUtils.isNotBlank(imageContext)) {
362 headerTabDispatch = imageContext;
363 }
364 else {
365
366 headerTabDispatch = request.getParameter(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
367 }
368 return headerTabDispatch;
369 }
370
371
372
373
374
375
376
377
378 protected String getImageContext(HttpServletRequest request, String contextKey) {
379 String imageContext = "";
380 String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
381 if (StringUtils.isBlank(parameterName)) {
382 parameterName = request.getParameter("methodToCallPath");
383 }
384 if (StringUtils.isNotBlank(parameterName)) {
385 imageContext = StringUtils.substringBetween(parameterName, contextKey, ".");
386 }
387 return imageContext;
388 }
389
390 protected String getReturnLocation(HttpServletRequest request, ActionMapping mapping) {
391 String mappingPath = mapping.getPath();
392 String basePath = getApplicationBaseUrl();
393 return basePath + ("/lookup".equals(mappingPath) || "/maintenance".equals(mappingPath) || "/multipleValueLookup".equals(mappingPath) ? "/kr" : "") + mappingPath + ".do";
394 }
395
396
397
398
399
400
401
402
403
404
405
406
407
408 protected String retrieveLookupParameterValue(Class<? extends BusinessObject> boClass, String parameterName, String parameterValuePropertyName, ActionForm form, HttpServletRequest request) throws Exception {
409 String value;
410 if (StringUtils.contains(parameterValuePropertyName, "'")) {
411 value = StringUtils.replace(parameterValuePropertyName, "'", "");
412 } else if (request.getParameterMap().containsKey(parameterValuePropertyName)) {
413 value = request.getParameter(parameterValuePropertyName);
414 } else if (request.getParameterMap().containsKey(KewApiConstants.DOCUMENT_ATTRIBUTE_FIELD_PREFIX + parameterValuePropertyName)) {
415 value = request.getParameter(KewApiConstants.DOCUMENT_ATTRIBUTE_FIELD_PREFIX + parameterValuePropertyName);
416 } else {
417 if (form instanceof KualiForm) {
418 value = ((KualiForm) form).retrieveFormValueForLookupInquiryParameters(parameterName, parameterValuePropertyName);
419 } else {
420 if (LOG.isDebugEnabled()) {
421 LOG.debug("Unable to retrieve lookup/inquiry parameter value for parameter name " + parameterName + " parameter value property " + parameterValuePropertyName);
422 }
423 value = null;
424 }
425 }
426
427 if (value != null && boClass != null && getBusinessObjectAuthorizationService().attributeValueNeedsToBeEncryptedOnFormsAndLinks(boClass, parameterName)) {
428 if(CoreApiServiceLocator.getEncryptionService().isEnabled()) {
429 value = getEncryptionService().encrypt(value) + EncryptionService.ENCRYPTION_POST_PREFIX;
430 }
431 }
432 return value;
433 }
434
435
436
437
438
439
440
441
442
443
444
445 @SuppressWarnings("unchecked")
446 public ActionForward performLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
447
448 String fullParameter = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
449 validateLookupInquiryFullParameter(request, form, fullParameter);
450
451 KualiForm kualiForm = (KualiForm) form;
452
453
454 kualiForm.registerEditableProperty(KRADConstants.DISPATCH_REQUEST_PARAMETER);
455
456
457 String baseLookupUrl = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM14_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM14_RIGHT_DEL);
458
459
460 String boClassName = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL, KRADConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL);
461 if (StringUtils.isBlank(boClassName)) {
462 throw new RuntimeException("Illegal call to perform lookup, no business object class name specified.");
463 }
464 Class boClass = null;
465
466 try{
467 boClass = Class.forName(boClassName);
468 } catch(ClassNotFoundException cnfex){
469 if ((StringUtils.isNotEmpty(baseLookupUrl) && baseLookupUrl.startsWith(getApplicationBaseUrl() + "/kr/"))
470 || StringUtils.isEmpty(baseLookupUrl)) {
471 throw new IllegalArgumentException("The class (" + boClassName + ") cannot be found by this particular "
472 + "application. " + "ApplicationBaseUrl: " + getApplicationBaseUrl()
473 + " ; baseLookupUrl: " + baseLookupUrl);
474 } else {
475 LOG.info("The class (" + boClassName + ") cannot be found by this particular application. "
476 + "ApplicationBaseUrl: " + getApplicationBaseUrl() + " ; baseLookupUrl: " + baseLookupUrl);
477 }
478 }
479
480
481 Properties parameters = new Properties();
482 String conversionFields = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
483 if (StringUtils.isNotBlank(conversionFields)) {
484 parameters.put(KRADConstants.CONVERSION_FIELDS_PARAMETER, conversionFields);
485
486
487 String[] fieldConversions = conversionFields.split(KRADConstants.FIELD_CONVERSIONS_SEPARATOR);
488 for (String fieldConversion : fieldConversions) {
489 String destination = fieldConversion.split(KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR, 2)[1];
490 kualiForm.registerEditableProperty(destination);
491 }
492 }
493
494
495 String parameterFields = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM2_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM2_RIGHT_DEL);
496 if ( LOG.isDebugEnabled() ) {
497 LOG.debug( "fullParameter: " + fullParameter );
498 LOG.debug( "parameterFields: " + parameterFields );
499 }
500 if (StringUtils.isNotBlank(parameterFields)) {
501 String[] lookupParams = parameterFields.split(KRADConstants.FIELD_CONVERSIONS_SEPARATOR);
502 if ( LOG.isDebugEnabled() ) {
503 LOG.debug( "lookupParams: " + Arrays.toString(lookupParams) );
504 }
505 for (String lookupParam : lookupParams) {
506 String[] keyValue = lookupParam.split(KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR, 2);
507 if (keyValue.length != 2) {
508 throw new RuntimeException("malformed field conversion pair: " + Arrays.toString(keyValue));
509 }
510
511 String lookupParameterValue = retrieveLookupParameterValue(boClass, keyValue[1], keyValue[0], form, request);
512 if (StringUtils.isNotBlank(lookupParameterValue)) {
513 parameters.put(keyValue[1], lookupParameterValue);
514 }
515
516 if ( LOG.isDebugEnabled() ) {
517 LOG.debug( "keyValue[0]: " + keyValue[0] );
518 LOG.debug( "keyValue[1]: " + keyValue[1] );
519 }
520 }
521 }
522
523
524 String readOnlyFields = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM8_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM8_RIGHT_DEL);
525 if (StringUtils.isNotBlank(readOnlyFields)) {
526 parameters.put(KRADConstants.LOOKUP_READ_ONLY_FIELDS, readOnlyFields);
527 }
528
529 if ( LOG.isDebugEnabled() ) {
530 LOG.debug( "fullParameter: " + fullParameter );
531 LOG.debug( "readOnlyFields: " + readOnlyFields );
532 }
533
534
535 String hideReturnLink = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM3_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM3_RIGHT_DEL);
536 if (StringUtils.isNotBlank(hideReturnLink)) {
537 parameters.put(KRADConstants.HIDE_LOOKUP_RETURN_LINK, hideReturnLink);
538 }
539
540
541 String extraButtonSource = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM4_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM4_RIGHT_DEL);
542 if (StringUtils.isNotBlank(extraButtonSource)) {
543 parameters.put(KRADConstants.EXTRA_BUTTON_SOURCE, extraButtonSource);
544 }
545 String extraButtonParams = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM5_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM5_RIGHT_DEL);
546 if (StringUtils.isNotBlank(extraButtonParams)) {
547 parameters.put(KRADConstants.EXTRA_BUTTON_PARAMS, extraButtonParams);
548 }
549
550 String lookupAction = KRADConstants.LOOKUP_ACTION;
551
552
553 boolean isMultipleValue = false;
554 String multipleValues = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM6_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM6_RIGHT_DEL);
555 if ((new Boolean(multipleValues).booleanValue())) {
556 parameters.put(KRADConstants.MULTIPLE_VALUE, multipleValues);
557 lookupAction = KRADConstants.MULTIPLE_VALUE_LOOKUP_ACTION;
558 isMultipleValue = true;
559 }
560
561
562 String lookedUpCollectionName = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM11_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM11_RIGHT_DEL);
563 if (StringUtils.isNotBlank(lookedUpCollectionName)) {
564 parameters.put(KRADConstants.LOOKED_UP_COLLECTION_NAME, lookedUpCollectionName);
565 }
566
567
568 String supressActions = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM7_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM7_RIGHT_DEL);
569 if (StringUtils.isNotBlank(supressActions)) {
570 parameters.put(KRADConstants.SUPPRESS_ACTIONS, supressActions);
571 }
572
573
574 String referencesToRefresh = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM10_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM10_RIGHT_DEL);
575 if (StringUtils.isNotBlank(referencesToRefresh)) {
576 parameters.put(KRADConstants.REFERENCES_TO_REFRESH, referencesToRefresh);
577 }
578
579
580 if (form instanceof KualiForm && StringUtils.isNotEmpty(((KualiForm) form).getAnchor())) {
581 parameters.put(KRADConstants.LOOKUP_ANCHOR, ((KualiForm) form).getAnchor());
582 }
583
584
585 parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "start");
586
587
588 String autoSearch = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM9_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM9_RIGHT_DEL);
589
590 if (StringUtils.isNotBlank(autoSearch)) {
591 parameters.put(KRADConstants.LOOKUP_AUTO_SEARCH, autoSearch);
592 if ("YES".equalsIgnoreCase(autoSearch)){
593 parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "search");
594 }
595 }
596
597 parameters.put(KRADConstants.DOC_FORM_KEY, GlobalVariables.getUserSession().addObjectWithGeneratedKey(form));
598 parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, boClassName);
599
600 parameters.put(KRADConstants.RETURN_LOCATION_PARAMETER, getReturnLocation(request, mapping));
601
602 if (form instanceof KualiDocumentFormBase) {
603 String docNum = ((KualiDocumentFormBase) form).getDocument().getDocumentNumber();
604 if(docNum != null){
605 parameters.put(KRADConstants.DOC_NUM, docNum);
606 }
607 }else if(form instanceof LookupForm){
608 String docNum = ((LookupForm) form).getDocNum();
609 if(docNum != null){
610 parameters.put(KRADConstants.DOC_NUM, ((LookupForm) form).getDocNum());
611 }
612 }
613
614 if (boClass != null) {
615 ModuleService responsibleModuleService = getKualiModuleService().getResponsibleModuleService(boClass);
616 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)){
617 Map<String, String> parameterMap = new HashMap<String, String>();
618 Enumeration<Object> e = parameters.keys();
619 while (e.hasMoreElements()) {
620 String paramName = (String) e.nextElement();
621 parameterMap.put(paramName, parameters.getProperty(paramName));
622 }
623 return new ActionForward(responsibleModuleService.getExternalizableBusinessObjectLookupUrl(boClass, parameterMap), true);
624 }
625 }
626
627 if (StringUtils.isBlank(baseLookupUrl)) {
628 baseLookupUrl = getApplicationBaseUrl() + "/kr/" + lookupAction;
629 } else {
630 if (isMultipleValue) {
631 LookupUtils.transformLookupUrlToMultiple(baseLookupUrl);
632 }
633 }
634 String lookupUrl = UrlFactory.parameterizeUrl(baseLookupUrl, parameters);
635 return new ActionForward(lookupUrl, true);
636 }
637
638 protected void validateLookupInquiryFullParameter(HttpServletRequest request, ActionForm form, String fullParameter){
639 PojoFormBase pojoFormBase = (PojoFormBase) form;
640 if(WebUtils.isFormSessionDocument((PojoFormBase) form)){
641 if(!pojoFormBase.isPropertyEditable(fullParameter)) {
642 throw new RuntimeException("The methodToCallAttribute is not registered as an editable property.");
643 }
644 }
645 }
646
647 @SuppressWarnings("unchecked")
648 public ActionForward performInquiry(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
649
650 String fullParameter = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
651 validateLookupInquiryFullParameter(request, form, fullParameter);
652
653
654
655 KualiForm kualiForm = (KualiForm) form;
656 kualiForm.registerEditableProperty(KRADConstants.DISPATCH_REQUEST_PARAMETER);
657
658
659 String boClassName = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL, KRADConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL);
660 if (StringUtils.isBlank(boClassName)) {
661 throw new RuntimeException("Illegal call to perform inquiry, no business object class name specified.");
662 }
663
664
665 Properties parameters = new Properties();
666 parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, boClassName);
667
668 parameters.put(KRADConstants.RETURN_LOCATION_PARAMETER, getReturnLocation(request, mapping));
669
670
671 String parameterFields = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM2_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM2_RIGHT_DEL);
672 if ( LOG.isDebugEnabled() ) {
673 LOG.debug( "fullParameter: " + fullParameter );
674 LOG.debug( "parameterFields: " + parameterFields );
675 }
676 if (StringUtils.isNotBlank(parameterFields)) {
677
678 String[] inquiryParams = parameterFields.split(KRADConstants.FIELD_CONVERSIONS_SEPARATOR);
679 if ( LOG.isDebugEnabled() ) {
680 LOG.debug( "inquiryParams: " + inquiryParams );
681 }
682 Class<? extends BusinessObject> boClass = (Class<? extends BusinessObject>) Class.forName(boClassName);
683 for (String inquiryParam : inquiryParams) {
684 String[] keyValue = inquiryParam.split(KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR, 2);
685
686 String inquiryParameterValue = retrieveLookupParameterValue(boClass, keyValue[1], keyValue[0], form, request);
687 if (inquiryParameterValue == null) {
688 parameters.put(keyValue[1], "directInquiryKeyNotSpecified");
689 }
690 else {
691 parameters.put(keyValue[1], inquiryParameterValue);
692 }
693
694 if ( LOG.isDebugEnabled() ) {
695 LOG.debug( "keyValue[0]: " + keyValue[0] );
696 LOG.debug( "keyValue[1]: " + keyValue[1] );
697 }
698 }
699 }
700 parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "start");
701 parameters.put(KRADConstants.DOC_FORM_KEY, GlobalVariables.getUserSession().addObjectWithGeneratedKey(form));
702 String inquiryUrl = null;
703 try {
704 Class.forName(boClassName);
705 inquiryUrl = getApplicationBaseUrl() + "/kr/" + KRADConstants.DIRECT_INQUIRY_ACTION;
706 } catch ( ClassNotFoundException ex ) {
707
708 LOG.warn("Class name does not represent a valid class which this application understands: " + boClassName);
709 }
710 inquiryUrl = UrlFactory.parameterizeUrl(inquiryUrl, parameters);
711 return new ActionForward(inquiryUrl, true);
712
713 }
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730 protected ActionForward performQuestionWithoutInput(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String questionId, String questionText, String questionType, String caller, String context) throws Exception {
731 return performQuestion(mapping, form, request, response, questionId, questionText, questionType, caller, context, false, "", "", "", "");
732 }
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749 protected ActionForward performQuestionWithInput(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String questionId, String questionText, String questionType, String caller, String context) throws Exception {
750 return performQuestion(mapping, form, request, response, questionId, questionText, questionType, caller, context, true, "", "", "", "");
751 }
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772 protected ActionForward performQuestionWithInputAgainBecauseOfErrors(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String questionId, String questionText, String questionType, String caller, String context, String reason, String errorKey, String errorPropertyName, String errorParameter) throws Exception {
773 return performQuestion(mapping, form, request, response, questionId, questionText, questionType, caller, context, true, reason, errorKey, errorPropertyName, errorParameter);
774 }
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796 private ActionForward performQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String questionId, String questionText, String questionType, String caller, String context, boolean showReasonField, String reason, String errorKey, String errorPropertyName, String errorParameter) throws Exception {
797 Properties parameters = new Properties();
798
799 parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "start");
800 parameters.put(KRADConstants.DOC_FORM_KEY, GlobalVariables.getUserSession().addObjectWithGeneratedKey(form));
801 parameters.put(KRADConstants.CALLING_METHOD, caller);
802 parameters.put(KRADConstants.QUESTION_INST_ATTRIBUTE_NAME, questionId);
803 parameters.put(KRADConstants.QUESTION_IMPL_ATTRIBUTE_NAME, questionType);
804
805 parameters.put(KRADConstants.RETURN_LOCATION_PARAMETER, getReturnLocation(request, mapping));
806 parameters.put(KRADConstants.QUESTION_CONTEXT, context);
807 parameters.put(KRADConstants.QUESTION_SHOW_REASON_FIELD, Boolean.toString(showReasonField));
808 parameters.put(KRADConstants.QUESTION_REASON_ATTRIBUTE_NAME, reason);
809 parameters.put(KRADConstants.QUESTION_ERROR_KEY, errorKey);
810 parameters.put(KRADConstants.QUESTION_ERROR_PROPERTY_NAME, errorPropertyName);
811 parameters.put(KRADConstants.QUESTION_ERROR_PARAMETER, errorParameter);
812 parameters.put(KRADConstants.QUESTION_ANCHOR, form instanceof KualiForm ? ObjectUtils.toString(((KualiForm) form).getAnchor()) : "");
813 Object methodToCallAttribute = request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
814 if (methodToCallAttribute != null) {
815 parameters.put(KRADConstants.METHOD_TO_CALL_PATH, methodToCallAttribute);
816 ((PojoForm) form).registerEditableProperty(String.valueOf(methodToCallAttribute));
817 }
818
819 if (form instanceof KualiDocumentFormBase) {
820 String docNum = ((KualiDocumentFormBase) form).getDocument().getDocumentNumber();
821 if(docNum != null){
822 parameters.put(KRADConstants.DOC_NUM, ((KualiDocumentFormBase) form)
823 .getDocument().getDocumentNumber());
824 }
825 }
826
827
828 String questionTextAttributeName = KRADConstants.QUESTION_TEXT_ATTRIBUTE_NAME + questionId;
829 GlobalVariables.getUserSession().addObject(questionTextAttributeName, (Object)questionText);
830
831 String questionUrl = UrlFactory.parameterizeUrl(getApplicationBaseUrl() + "/kr/" + KRADConstants.QUESTION_ACTION, parameters);
832 return new ActionForward(questionUrl, true);
833 }
834
835
836
837
838
839
840
841
842
843
844
845
846 public ActionForward performWorkgroupLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
847 String returnUrl = null;
848 if ("/kr".equals(mapping.getModuleConfig().getPrefix())) {
849 returnUrl = getApplicationBaseUrl() + mapping.getModuleConfig().getPrefix() + mapping.getPath() + ".do";
850 } else {
851 returnUrl = getApplicationBaseUrl() + mapping.getPath() + ".do";
852 }
853
854
855 String fullParameter = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
856 String conversionFields = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
857
858 String deploymentBaseUrl = KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
859 KRADConstants.WORKFLOW_URL_KEY);
860 String workgroupLookupUrl = deploymentBaseUrl + "/Lookup.do?lookupableImplServiceName=WorkGroupLookupableImplService&methodToCall=start&docFormKey=" + GlobalVariables.getUserSession().addObjectWithGeneratedKey(form);
861
862 if (conversionFields != null) {
863 workgroupLookupUrl += "&conversionFields=" + conversionFields;
864 }
865 if (form instanceof KualiDocumentFormBase) {
866 workgroupLookupUrl +="&docNum="+ ((KualiDocumentFormBase) form).getDocument().getDocumentNumber();
867 }
868
869 workgroupLookupUrl += "&returnLocation=" + returnUrl;
870
871 return new ActionForward(workgroupLookupUrl, true);
872 }
873
874
875
876
877
878
879
880
881
882
883
884 public ActionForward headerTab(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
885
886
887 String headerTabDispatch = getHeaderTabDispatch(request);
888 if (StringUtils.isNotEmpty(headerTabDispatch)) {
889 ActionForward forward = dispatchMethod(mapping, form, request, response, headerTabDispatch);
890 if (GlobalVariables.getMessageMap().getNumberOfPropertiesWithErrors() > 0) {
891 return mapping.findForward(RiceConstants.MAPPING_BASIC);
892 }
893 this.doTabOpenOrClose(mapping, form, request, response, false);
894 if (forward.getRedirect()) {
895 return forward;
896 }
897 }
898 return dispatchMethod(mapping, form, request, response, getHeaderTabNavigateTo(request));
899 }
900
901
902
903
904
905
906
907 protected void checkAuthorization( ActionForm form, String methodToCall) throws AuthorizationException
908 {
909 String principalId = GlobalVariables.getUserSession().getPrincipalId();
910 Map<String, String> roleQualifier = new HashMap<String, String>(getRoleQualification(form, methodToCall));
911 Map<String, String> permissionDetails = KRADUtils.getNamespaceAndActionClass(this.getClass());
912
913 if (!KimApiServiceLocator.getPermissionService().isAuthorizedByTemplate(principalId,
914 KRADConstants.KNS_NAMESPACE, KimConstants.PermissionTemplateNames.USE_SCREEN, permissionDetails,
915 roleQualifier))
916 {
917 throw new AuthorizationException(GlobalVariables.getUserSession().getPerson().getPrincipalName(),
918 methodToCall,
919 this.getClass().getSimpleName());
920 }
921 }
922
923
924
925
926 protected Map<String,String> getRoleQualification(ActionForm form, String methodToCall) {
927 return new HashMap<String,String>();
928 }
929
930 protected static KualiModuleService getKualiModuleService() {
931 if ( kualiModuleService == null ) {
932 kualiModuleService = KRADServiceLocatorWeb.getKualiModuleService();
933 }
934 return kualiModuleService;
935 }
936
937
938
939
940
941 public static final String TEXT_AREA_FIELD_NAME="textAreaFieldName";
942
943
944
945
946 public static final String TEXT_AREA_FIELD_LABEL="textAreaFieldLabel";
947
948
949
950
951 public static final String TEXT_AREA_READ_ONLY="textAreaReadOnly";
952
953
954
955
956 public static final String TEXT_AREA_FIELD_ANCHOR="textAreaFieldAnchor";
957
958
959
960
961 public static final String TEXT_AREA_MAX_LENGTH="textAreaMaxLength";
962
963
964
965
966 public static final String FORM_ACTION="htmlFormAction";
967
968
969
970
971 public static final String METHOD_TO_CALL="methodToCall";
972
973
974
975
976
977 public static final String FORWARD_TEXT_AREA_UPDATE="updateTextArea";
978
979
980
981
982 public static final String POST_TEXT_AREA_TO_PARENT="postTextAreaToParent";
983
984
985
986
987
988 public static final String FORWARD_NEXT="forwardNext";
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003 public ActionForward updateTextArea(ActionMapping mapping,
1004 ActionForm form,
1005 HttpServletRequest request,
1006 HttpServletResponse response) {
1007 if (LOG.isTraceEnabled()) {
1008 String lm=String.format("ENTRY %s%n%s", form.getClass().getSimpleName(),
1009 request.getRequestURI());
1010 LOG.trace(lm);
1011 }
1012
1013 final String[] keyValue = getTextAreaParams(request);
1014
1015 request.setAttribute(TEXT_AREA_FIELD_NAME, keyValue[0]);
1016 request.setAttribute(FORM_ACTION,keyValue[1]);
1017 request.setAttribute(TEXT_AREA_FIELD_LABEL,keyValue[2]);
1018 request.setAttribute(TEXT_AREA_READ_ONLY,keyValue[3]);
1019 request.setAttribute(TEXT_AREA_MAX_LENGTH,keyValue[4]);
1020 if (form instanceof KualiForm && StringUtils.isNotEmpty(((KualiForm) form).getAnchor())) {
1021 request.setAttribute(TEXT_AREA_FIELD_ANCHOR,((KualiForm) form).getAnchor());
1022 }
1023
1024
1025 String docWebScope=(String)request.getAttribute(KRADConstants.DOCUMENT_WEB_SCOPE);
1026 if (docWebScope != null && docWebScope.trim().length() >= 0) {
1027 request.setAttribute(KRADConstants.DOCUMENT_WEB_SCOPE, docWebScope);
1028 }
1029
1030 request.setAttribute(KRADConstants.DOC_FORM_KEY, GlobalVariables.getUserSession().addObjectWithGeneratedKey(form));
1031
1032 ActionForward forward=mapping.findForward(FORWARD_TEXT_AREA_UPDATE);
1033
1034 if (LOG.isTraceEnabled()) {
1035 String lm=String.format("EXIT %s", (forward==null)?"null":forward.getPath());
1036 LOG.trace(lm);
1037 }
1038
1039 return forward;
1040 }
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057 private String[] getTextAreaParams(HttpServletRequest request) {
1058
1059 String fullParameter = (String) request.getAttribute(
1060 KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
1061
1062
1063 String parameterFields = StringUtils.substringBetween(fullParameter,
1064 KRADConstants.METHOD_TO_CALL_PARM2_LEFT_DEL,
1065 KRADConstants.METHOD_TO_CALL_PARM2_RIGHT_DEL);
1066 if ( LOG.isDebugEnabled() ) {
1067 LOG.debug( "fullParameter: " + fullParameter );
1068 LOG.debug( "parameterFields: " + parameterFields );
1069 }
1070 String[] keyValue = null;
1071 if (StringUtils.isNotBlank(parameterFields)) {
1072 String[] textAreaParams = parameterFields.split(
1073 KRADConstants.FIELD_CONVERSIONS_SEPARATOR);
1074 if ( LOG.isDebugEnabled() ) {
1075 LOG.debug( "lookupParams: " + textAreaParams );
1076 }
1077 for (final String textAreaParam : textAreaParams) {
1078 keyValue = textAreaParam.split(KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR, 2);
1079
1080 if ( LOG.isDebugEnabled() ) {
1081 LOG.debug( "keyValue[0]: " + keyValue[0] );
1082 LOG.debug( "keyValue[1]: " + keyValue[1] );
1083 LOG.debug( "keyValue[2]: " + keyValue[2] );
1084 LOG.debug( "keyValue[3]: " + keyValue[3] );
1085 LOG.debug( "keyValue[4]: " + keyValue[4] );
1086 }
1087 }
1088 }
1089
1090 return keyValue;
1091 }
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105 public ActionForward postTextAreaToParent(ActionMapping mapping,
1106 ActionForm form,
1107 HttpServletRequest request,
1108 HttpServletResponse response) {
1109
1110 if (LOG.isTraceEnabled()) {
1111 String lm=String.format("ENTRY %s%n%s", form.getClass().getSimpleName(),
1112 request.getRequestURI());
1113 LOG.trace(lm);
1114 }
1115
1116 String forwardingId=request.getParameter(FORWARD_NEXT);
1117 if (forwardingId == null) {
1118 forwardingId=RiceConstants.MAPPING_BASIC;
1119 }
1120 ActionForward forward=mapping.findForward(forwardingId);
1121
1122 if (LOG.isTraceEnabled()) {
1123 String lm=String.format("EXIT %s", (forward==null)?"null":forward.getPath());
1124 LOG.trace(lm);
1125 }
1126
1127 return forward;
1128 }
1129
1130
1131
1132
1133
1134
1135 protected final void addMethodToCallToUncheckedList( String methodToCall ) {
1136 methodToCallsToNotCheckAuthorization.add(methodToCall);
1137 }
1138
1139
1140
1141
1142 protected void doProcessingAfterPost( KualiForm form, HttpServletRequest request ) {
1143
1144 }
1145
1146 protected BusinessObjectAuthorizationService getBusinessObjectAuthorizationService() {
1147 if (businessObjectAuthorizationService == null) {
1148 businessObjectAuthorizationService = KNSServiceLocator.getBusinessObjectAuthorizationService();
1149 }
1150 return businessObjectAuthorizationService;
1151 }
1152
1153 protected EncryptionService getEncryptionService() {
1154 if (encryptionService == null) {
1155 encryptionService = CoreApiServiceLocator.getEncryptionService();
1156 }
1157 return encryptionService;
1158 }
1159
1160 public static String getApplicationBaseUrl() {
1161 if ( applicationBaseUrl == null ) {
1162 applicationBaseUrl = KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
1163 KRADConstants.APPLICATION_URL_KEY);
1164 }
1165 return applicationBaseUrl;
1166 }
1167
1168 protected boolean isModuleLocked(ActionForm form, String methodToCall, HttpServletRequest request) {
1169 String boClass = request.getParameter(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE);
1170 ModuleService moduleService = null;
1171 if(StringUtils.isNotBlank(boClass)) {
1172 try {
1173 moduleService = getKualiModuleService().getResponsibleModuleService(Class.forName(boClass));
1174 } catch (ClassNotFoundException classNotFoundException) {
1175 LOG.warn("BO class not found: " + boClass, classNotFoundException);
1176 }
1177 } else {
1178 moduleService = getKualiModuleService().getResponsibleModuleService(this.getClass());
1179 }
1180 if(moduleService != null && moduleService.isLocked()) {
1181 String principalId = GlobalVariables.getUserSession().getPrincipalId();
1182 String namespaceCode = KRADConstants.KUALI_RICE_SYSTEM_NAMESPACE;
1183 String permissionName = KimConstants.PermissionNames.ACCESS_LOCKED_MODULE;
1184 Map<String, String> qualification = getRoleQualification(form, methodToCall);
1185 if(!KimApiServiceLocator.getPermissionService().isAuthorized(principalId, namespaceCode, permissionName, qualification)) {
1186 ParameterService parameterSerivce = CoreFrameworkServiceLocator.getParameterService();
1187 String messageParamNamespaceCode = moduleService.getModuleConfiguration().getNamespaceCode();
1188 String messageParamComponentCode = KRADConstants.DetailTypes.ALL_DETAIL_TYPE;
1189 String messageParamName = KRADConstants.SystemGroupParameterNames.OLTP_LOCKOUT_MESSAGE_PARM;
1190 String lockoutMessage = parameterSerivce.getParameterValueAsString(messageParamNamespaceCode, messageParamComponentCode, messageParamName);
1191
1192 if(StringUtils.isBlank(lockoutMessage)) {
1193 String defaultMessageParamName = KRADConstants.SystemGroupParameterNames.OLTP_LOCKOUT_DEFAULT_MESSAGE;
1194 lockoutMessage = parameterSerivce.getParameterValueAsString(KRADConstants.KNS_NAMESPACE, messageParamComponentCode, defaultMessageParamName);
1195 }
1196 request.setAttribute(KRADConstants.MODULE_LOCKED_MESSAGE_REQUEST_PARAMETER, lockoutMessage);
1197 return true;
1198 }
1199 }
1200 return false;
1201 }
1202 }