1 package org.kuali.ole.select.document.web;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.struts.action.ActionForm;
5 import org.apache.struts.action.ActionForward;
6 import org.apache.struts.action.ActionMapping;
7 import org.kuali.ole.sys.OLEConstants;
8 import org.kuali.rice.core.api.util.RiceConstants;
9 import org.kuali.rice.kns.web.struts.action.KualiAction;
10 import org.kuali.rice.krad.exception.AuthorizationException;
11 import org.kuali.rice.krad.util.GlobalVariables;
12 import org.kuali.rice.krad.util.KRADConstants;
13 import org.kuali.rice.krad.util.UrlFactory;
14
15 import javax.servlet.http.HttpServletRequest;
16 import javax.servlet.http.HttpServletResponse;
17 import java.util.Properties;
18
19
20
21
22
23
24
25
26 public class OLEReqPOAskQuestionAction extends KualiAction {
27
28
29 @Override
30 protected void checkAuthorization(ActionForm form, String methodToCall)
31 throws AuthorizationException {
32
33 }
34
35 public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
36
37 processErrorMessages(request);
38
39 return mapping.findForward(RiceConstants.MAPPING_BASIC);
40 }
41
42
43 public ActionForward processAnswer(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
44 OLEReqPOAskQuestionForm oleReqPOAskQuestionForm = (OLEReqPOAskQuestionForm) form;
45
46 Properties parameters = new Properties();
47
48 parameters.put(KRADConstants.DOC_FORM_KEY, oleReqPOAskQuestionForm.getFormKey());
49 parameters.put(KRADConstants.QUESTION_CLICKED_BUTTON, getSelectedButton(request));
50 parameters.put(KRADConstants.METHOD_TO_CALL_ATTRIBUTE, oleReqPOAskQuestionForm.getCaller());
51 parameters.put(KRADConstants.REFRESH_CALLER, KRADConstants.QUESTION_REFRESH);
52 parameters.put(KRADConstants.QUESTION_INST_ATTRIBUTE_NAME, oleReqPOAskQuestionForm.getQuestionIndex());
53 if(oleReqPOAskQuestionForm.getDocNum() != null){
54 parameters.put(KRADConstants.DOC_NUM, oleReqPOAskQuestionForm.getDocNum());
55 }
56
57 if (StringUtils.isNotBlank(oleReqPOAskQuestionForm.getQuestionAnchor())) {
58 parameters.put(KRADConstants.ANCHOR, oleReqPOAskQuestionForm.getQuestionAnchor());
59 }
60
61 String context = oleReqPOAskQuestionForm.getContext();
62 if (StringUtils.isNotBlank(context)) {
63 parameters.put(KRADConstants.QUESTION_CONTEXT, context);
64 }
65
66 if (StringUtils.isNotBlank(oleReqPOAskQuestionForm.getCancellationReason()) || StringUtils.isNotBlank(oleReqPOAskQuestionForm.getReason())) {
67 String reason = oleReqPOAskQuestionForm.getCancellationReason()+ OLEConstants.BLANK_SPACE + "/" + OLEConstants.BLANK_SPACE + oleReqPOAskQuestionForm.getReason();
68 parameters.put(KRADConstants.QUESTION_REASON_ATTRIBUTE_NAME, reason);
69 }
70
71 if (StringUtils.isNotBlank(oleReqPOAskQuestionForm.getMethodToCallPath())) {
72
73 parameters.put(oleReqPOAskQuestionForm.getMethodToCallPath(), "present");
74 }
75
76 String returnUrl = UrlFactory.parameterizeUrl( oleReqPOAskQuestionForm.getBackLocation(), parameters);
77
78 return new ActionForward(returnUrl, true);
79 }
80
81
82
83
84
85
86
87
88
89 private String getSelectedButton(HttpServletRequest request) {
90 String selectedButton = "-1";
91 String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
92 if (StringUtils.isNotBlank(parameterName)) {
93 selectedButton = StringUtils.substringBetween(parameterName, ".button", ".");
94 }
95
96 return selectedButton;
97 }
98
99
100 private void processErrorMessages(HttpServletRequest request) {
101 String errorKey = request.getParameter(KRADConstants.QUESTION_ERROR_KEY);
102 String errorPropertyName = request.getParameter(KRADConstants.QUESTION_ERROR_PROPERTY_NAME);
103 String errorParameter = request.getParameter(KRADConstants.QUESTION_ERROR_PARAMETER);
104
105 if (StringUtils.isNotBlank(errorKey)) {
106 if (StringUtils.isBlank(errorPropertyName)) {
107 throw new IllegalStateException("Both the errorKey and the errorPropertyName must be filled in, " + "in order for errors to be displayed by the question component. Currently, " + "only the errorKey has a value specified.");
108 }
109 else {
110 if (StringUtils.isBlank(errorParameter)) {
111 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPropertyName, errorKey);
112 }
113 else {
114 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPropertyName, errorKey, errorParameter);
115 }
116 }
117 }
118 }
119 }
120
121