1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.web.struts;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.struts.action.ActionForm;
20 import org.apache.struts.action.ActionForward;
21 import org.apache.struts.action.ActionMapping;
22 import org.kuali.ole.module.purap.PurapKeyConstants;
23 import org.kuali.ole.module.purap.document.ReceivingDocument;
24 import org.kuali.ole.module.purap.util.ReceivingQuestionCallback;
25 import org.kuali.ole.sys.OLEConstants;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.ole.sys.document.web.struts.FinancialSystemTransactionalDocumentActionBase;
28 import org.kuali.rice.core.api.config.property.ConfigurationService;
29 import org.kuali.rice.kns.question.ConfirmationQuestion;
30 import org.kuali.rice.kns.service.DataDictionaryService;
31 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
32 import org.kuali.rice.krad.bo.Note;
33 import org.kuali.rice.krad.util.ObjectUtils;
34
35 import javax.servlet.http.HttpServletRequest;
36 import javax.servlet.http.HttpServletResponse;
37 import java.util.Iterator;
38 import java.util.TreeMap;
39
40 public class ReceivingBaseAction extends FinancialSystemTransactionalDocumentActionBase {
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 protected ActionForward askQuestionWithInput(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String questionType, String notePrefix, String operation, String messageKey, ReceivingQuestionCallback callback) throws Exception {
60 TreeMap<String, ReceivingQuestionCallback> questionsAndCallbacks = new TreeMap<String, ReceivingQuestionCallback>();
61 questionsAndCallbacks.put(questionType, callback);
62
63 return askQuestionWithInput(mapping, form, request, response, questionType, notePrefix, operation, messageKey, questionsAndCallbacks, "", mapping.findForward(OLEConstants.MAPPING_BASIC));
64 }
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87 protected ActionForward askQuestionWithInput(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String questionType, String notePrefix, String operation, String messageKey, TreeMap<String, ReceivingQuestionCallback> questionsAndCallbacks, String messagePrefix, ActionForward redirect) throws Exception {
88 KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
89 ReceivingDocument receivingDocument = (ReceivingDocument) kualiDocumentFormBase.getDocument();
90
91 String question = (String) request.getParameter(OLEConstants.QUESTION_INST_ATTRIBUTE_NAME);
92 String reason = request.getParameter(OLEConstants.QUESTION_REASON_ATTRIBUTE_NAME);
93 String noteText = "";
94
95 ConfigurationService kualiConfiguration = SpringContext.getBean(ConfigurationService.class);
96 String firstQuestion = questionsAndCallbacks.firstKey();
97 ReceivingQuestionCallback callback = null;
98 Iterator questions = questionsAndCallbacks.keySet().iterator();
99 String mapQuestion = null;
100 String key = null;
101
102
103 if (question == null) {
104 key = getQuestionProperty(messageKey, messagePrefix, kualiConfiguration, firstQuestion);
105 String message = StringUtils.replace(key, "{0}", operation);
106
107
108 return this.performQuestionWithInput(mapping, form, request, response, firstQuestion, message, OLEConstants.CONFIRMATION_QUESTION, questionType, "");
109 } else {
110
111 while (questions.hasNext()) {
112 mapQuestion = (String) questions.next();
113
114 if (StringUtils.equals(mapQuestion, question)) {
115 callback = questionsAndCallbacks.get(mapQuestion);
116 break;
117 }
118 }
119 key = getQuestionProperty(messageKey, messagePrefix, kualiConfiguration, mapQuestion);
120
121 Object buttonClicked = request.getParameter(OLEConstants.QUESTION_CLICKED_BUTTON);
122 if (question.equals(mapQuestion) && buttonClicked.equals(ConfirmationQuestion.NO)) {
123
124
125 String nextQuestion = null;
126
127 if (questions.hasNext()) {
128 nextQuestion = (String) questions.next();
129 key = getQuestionProperty(messageKey, messagePrefix, kualiConfiguration, nextQuestion);
130
131 return this.performQuestionWithInput(mapping, form, request, response, nextQuestion, key, OLEConstants.CONFIRMATION_QUESTION, questionType, "");
132 } else {
133
134 return mapping.findForward(OLEConstants.MAPPING_BASIC);
135 }
136 }
137
138 String introNoteMessage = notePrefix + OLEConstants.BLANK_SPACE;
139
140
141 noteText = introNoteMessage + reason;
142 int noteTextLength = noteText.length();
143
144
145 int noteTextMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(Note.class, OLEConstants.NOTE_TEXT_PROPERTY_NAME).intValue();
146 if (StringUtils.isBlank(reason) || (noteTextLength > noteTextMaxLength)) {
147
148 int reasonLimit = noteTextMaxLength - noteTextLength;
149 if (reason == null) {
150
151 reason = "";
152 }
153
154 return this.performQuestionWithInputAgainBecauseOfErrors(mapping, form, request, response, mapQuestion, key, OLEConstants.CONFIRMATION_QUESTION, questionType, "", reason, PurapKeyConstants.ERROR_PAYMENT_REQUEST_REASON_REQUIRED, OLEConstants.QUESTION_REASON_ATTRIBUTE_NAME, new Integer(reasonLimit).toString());
155 }
156 }
157
158
159 if (ObjectUtils.isNotNull(callback)) {
160 ReceivingDocument refreshedReceivingDocument = callback.doPostQuestion(receivingDocument, noteText);
161 kualiDocumentFormBase.setDocument(refreshedReceivingDocument);
162 }
163 String nextQuestion = null;
164
165 if (questions.hasNext()) {
166 nextQuestion = (String) questions.next();
167 key = getQuestionProperty(messageKey, messagePrefix, kualiConfiguration, nextQuestion);
168
169 return this.performQuestionWithInput(mapping, form, request, response, nextQuestion, key, OLEConstants.CONFIRMATION_QUESTION, questionType, "");
170 }
171
172 return redirect;
173 }
174
175
176
177
178
179
180
181
182
183
184
185
186 protected String getQuestionProperty(String messageKey, String messagePrefix, ConfigurationService kualiConfiguration, String question) {
187
188 return kualiConfiguration.getPropertyValueAsString((StringUtils.isEmpty(messagePrefix)) ? messageKey : messagePrefix + question);
189 }
190
191 }