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