1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kns.web.struts.action; |
18 | |
|
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.kuali.rice.core.api.util.RiceConstants; |
24 | |
import org.kuali.rice.kns.web.struts.form.QuestionPromptForm; |
25 | |
import org.kuali.rice.krad.exception.AuthorizationException; |
26 | |
import org.kuali.rice.krad.util.GlobalVariables; |
27 | |
import org.kuali.rice.krad.util.KRADConstants; |
28 | |
import org.kuali.rice.krad.util.UrlFactory; |
29 | |
|
30 | |
import javax.servlet.http.HttpServletRequest; |
31 | |
import javax.servlet.http.HttpServletResponse; |
32 | |
import java.util.Properties; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class QuestionPromptAction extends KualiAction { |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
@Override |
47 | |
protected void checkAuthorization(ActionForm form, String methodToCall) |
48 | |
throws AuthorizationException { |
49 | |
|
50 | 0 | } |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
63 | |
|
64 | 0 | processErrorMessages(request); |
65 | |
|
66 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
67 | |
} |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
public ActionForward processAnswer(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
80 | 0 | QuestionPromptForm questionPromptForm = (QuestionPromptForm) form; |
81 | |
|
82 | 0 | Properties parameters = new Properties(); |
83 | |
|
84 | 0 | parameters.put(KRADConstants.DOC_FORM_KEY, questionPromptForm.getFormKey()); |
85 | 0 | parameters.put(KRADConstants.QUESTION_CLICKED_BUTTON, getSelectedButton(request)); |
86 | 0 | parameters.put(KRADConstants.METHOD_TO_CALL_ATTRIBUTE, questionPromptForm.getCaller()); |
87 | 0 | parameters.put(KRADConstants.REFRESH_CALLER, KRADConstants.QUESTION_REFRESH); |
88 | 0 | parameters.put(KRADConstants.QUESTION_INST_ATTRIBUTE_NAME, questionPromptForm.getQuestionIndex()); |
89 | 0 | if(questionPromptForm.getDocNum() != null){ |
90 | 0 | parameters.put(KRADConstants.DOC_NUM, questionPromptForm.getDocNum()); |
91 | |
} |
92 | |
|
93 | 0 | if (StringUtils.isNotBlank(questionPromptForm.getQuestionAnchor())) { |
94 | 0 | parameters.put(KRADConstants.ANCHOR, questionPromptForm.getQuestionAnchor()); |
95 | |
} |
96 | |
|
97 | 0 | String context = questionPromptForm.getContext(); |
98 | 0 | if (StringUtils.isNotBlank(context)) { |
99 | 0 | parameters.put(KRADConstants.QUESTION_CONTEXT, context); |
100 | |
} |
101 | 0 | String reason = questionPromptForm.getReason(); |
102 | 0 | if (StringUtils.isNotBlank(reason)) { |
103 | 0 | parameters.put(KRADConstants.QUESTION_REASON_ATTRIBUTE_NAME, reason); |
104 | |
} |
105 | 0 | if (StringUtils.isNotBlank(questionPromptForm.getMethodToCallPath())) { |
106 | |
|
107 | 0 | parameters.put(questionPromptForm.getMethodToCallPath(), "present"); |
108 | |
} |
109 | |
|
110 | 0 | String returnUrl = UrlFactory.parameterizeUrl(questionPromptForm.getBackLocation(), parameters); |
111 | |
|
112 | 0 | return new ActionForward(returnUrl, true); |
113 | |
} |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
private String getSelectedButton(HttpServletRequest request) { |
122 | 0 | String selectedButton = "-1"; |
123 | 0 | String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE); |
124 | 0 | if (StringUtils.isNotBlank(parameterName)) { |
125 | 0 | selectedButton = StringUtils.substringBetween(parameterName, ".button", "."); |
126 | |
} |
127 | |
|
128 | 0 | return selectedButton; |
129 | |
} |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
private void processErrorMessages(HttpServletRequest request) { |
137 | 0 | String errorKey = request.getParameter(KRADConstants.QUESTION_ERROR_KEY); |
138 | 0 | String errorPropertyName = request.getParameter(KRADConstants.QUESTION_ERROR_PROPERTY_NAME); |
139 | 0 | String errorParameter = request.getParameter(KRADConstants.QUESTION_ERROR_PARAMETER); |
140 | |
|
141 | 0 | if (StringUtils.isNotBlank(errorKey)) { |
142 | 0 | if (StringUtils.isBlank(errorPropertyName)) { |
143 | 0 | 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."); |
144 | |
} |
145 | |
else { |
146 | 0 | if (StringUtils.isBlank(errorParameter)) { |
147 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPropertyName, errorKey); |
148 | |
} |
149 | |
else { |
150 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPropertyName, errorKey, errorParameter); |
151 | |
} |
152 | |
} |
153 | |
} |
154 | 0 | } |
155 | |
} |