001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kns.web.struts.form;
017
018import org.kuali.rice.kns.service.KNSServiceLocator;
019import org.kuali.rice.kns.util.WebUtils;
020import org.kuali.rice.kns.question.Question;
021import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
022import org.kuali.rice.krad.util.KRADConstants;
023import org.kuali.rice.krad.util.GlobalVariables;
024import javax.servlet.http.HttpServletRequest;
025import java.util.ArrayList;
026
027/**
028 * This class is the action form for all Question Prompts.
029 * 
030 * 
031 */
032public class QuestionPromptForm extends KualiForm {
033    private static final long serialVersionUID = 1L;
034    private ArrayList buttons;
035    private String caller;
036
037    private String formKey;
038    private String questionIndex;
039    private String questionText;
040    private String questionType;
041    private String title;
042    private String context;
043    private String reason;
044    private String showReasonField;
045    private String questionAnchor;
046    private String methodToCallPath;
047    private String docNum;
048
049    /**
050     * @return the docNum
051     */
052    public String getDocNum() {
053        return this.docNum;
054    }
055
056    /**
057     * @param docNum the docNum to set
058     */
059    public void setDocNum(String docNum) {
060        this.docNum = docNum;
061    }
062
063    /**
064     * @return boolean
065     */
066    public String getShowReasonField() {
067        return showReasonField;
068    }
069
070    /**
071     * @param showReasonField
072     */
073    public void setShowReasonField(String showReasonField) {
074        this.showReasonField = showReasonField;
075    }
076
077    /**
078     * @return Returns the buttons.
079     */
080    public ArrayList getButtons() {
081        return buttons;
082    }
083
084    /**
085     * @return Returns the caller.
086     */
087    public String getCaller() {
088        return caller;
089    }
090
091    /**
092     * @return Returns the formKey.
093     */
094    public String getFormKey() {
095        return formKey;
096    }
097
098    /**
099     * @return Returns the questionIndex.
100     */
101    public String getQuestionIndex() {
102        return questionIndex;
103    }
104
105    /**
106     * @return Returns the questionText.
107     */
108    public String getQuestionText() {
109        return questionText != null ? WebUtils.filterHtmlAndReplaceRiceMarkup(questionText) : questionText;
110    }
111
112    /**
113     * @return Returns the questionName.
114     */
115    public String getQuestionType() {
116        return questionType;
117    }
118
119    /**
120     * @return Returns the title.
121     */
122    public String getTitle() {
123        return title;
124    }
125
126    /**
127     * @see org.kuali.rice.krad.web.struts.pojo.PojoForm#populate(javax.servlet.http.HttpServletRequest)
128     */
129    public void populate(HttpServletRequest request) {
130        super.populate(request);
131
132        // set the title of the jsp, this should come from a resource bundle
133        title = KRADConstants.QUESTION_PAGE_TITLE;
134
135        if (request.getAttribute(KRADConstants.DOC_FORM_KEY) != null) {
136            this.setFormKey((String) request.getAttribute(KRADConstants.DOC_FORM_KEY));
137        }
138        else if (request.getParameter(KRADConstants.DOC_FORM_KEY) != null) {
139            this.setFormKey(request.getParameter(KRADConstants.DOC_FORM_KEY));
140        }
141        
142        if (request.getAttribute(KRADConstants.DOC_NUM) != null) {
143            this.setFormKey((String) request.getAttribute(KRADConstants.DOC_NUM));
144        }
145        
146
147        if (request.getParameter(KRADConstants.RETURN_LOCATION_PARAMETER) != null) {
148            this.setBackLocation(request.getParameter(KRADConstants.RETURN_LOCATION_PARAMETER));
149        }
150
151        if (getMethodToCall().equals(KRADConstants.START_METHOD)) { // don't do this for the processAnswer action otherwise it blows up
152            Question kualiQuestion = KNSServiceLocator.getQuestion(questionType);
153            if (kualiQuestion == null) {
154                throw new RuntimeException("question implementation not found: " + request.getParameter(KRADConstants.QUESTION_IMPL_ATTRIBUTE_NAME));
155            }
156           
157            // KULRICE-8077: PO Quote Limitation of Only 9 Vendors
158            String questionId = request.getParameter(KRADConstants.QUESTION_INST_ATTRIBUTE_NAME);
159            String questionTextAttributeName = KRADConstants.QUESTION_TEXT_ATTRIBUTE_NAME + questionId;
160            
161            if (GlobalVariables.getUserSession().retrieveObject(questionTextAttributeName)!=null) {
162                this.setQuestionText((String)GlobalVariables.getUserSession().retrieveObject(questionTextAttributeName));
163                GlobalVariables.getUserSession().removeObject(questionTextAttributeName);
164            }
165           
166            // some questions types default these so we should default if not
167            // present in request
168            if (questionText == null) {
169                questionText = kualiQuestion.getQuestion();
170            }
171
172            if (buttons == null) {
173                buttons = kualiQuestion.getButtons();
174            }
175        }
176    }
177
178    /**
179     * @param buttons The buttons to set.
180     */
181    public void setButtons(ArrayList buttons) {
182        this.buttons = buttons;
183    }
184
185    /**
186     * @param caller The caller to set.
187     */
188    public void setCaller(String caller) {
189        this.caller = caller;
190    }
191
192    /**
193     * @param formKey The formKey to set.
194     */
195    public void setFormKey(String formKey) {
196        this.formKey = formKey;
197    }
198
199    /**
200     * @param questionIndex The questionIndex to set.
201     */
202    public void setQuestionIndex(String questionIndex) {
203        this.questionIndex = questionIndex;
204    }
205
206    /**
207     * @param questionText The questionText to set.
208     */
209    public void setQuestionText(String questionText) {
210        this.questionText = questionText;
211    }
212
213    /**
214     * @param questionName The questionName to set.
215     */
216    public void setQuestionType(String questionName) {
217        this.questionType = questionName;
218    }
219
220    /**
221     * @param title The title to set.
222     */
223    public void setTitle(String title) {
224        this.title = title;
225    }
226
227    public String getContext() {
228        return context;
229    }
230
231    public void setContext(String context) {
232        this.context = context;
233    }
234
235    /**
236     * @return String
237     */
238    public String getReason() {
239        return reason;
240    }
241
242    /**
243     * @param reason
244     */
245    public void setReason(String reason) {
246        this.reason = reason;
247    }
248
249    public String getQuestionAnchor() {
250        return questionAnchor;
251    }
252
253    public void setQuestionAnchor(String questionAnchor) {
254        this.questionAnchor = questionAnchor;
255    }
256
257    public String getMethodToCallPath() {
258        return methodToCallPath;
259}
260    public void setMethodToCallPath(String methodToCallPath) {
261        this.methodToCallPath = methodToCallPath;
262    }
263    
264}