001/**
002 * Copyright 2005-2018 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 * @deprecated KNS Struts deprecated, use KRAD and the Spring MVC framework.
031 */
032@Deprecated
033public class QuestionPromptForm extends KualiForm {
034    private static final long serialVersionUID = 1L;
035    private ArrayList buttons;
036    private String caller;
037
038    private String formKey;
039    private String questionIndex;
040    private String questionText;
041    private String questionType;
042    private String title;
043    private String context;
044    private String reason;
045    private String showReasonField;
046    private String questionAnchor;
047    private String methodToCallPath;
048    private String docNum;
049
050    /**
051     * @return the docNum
052     */
053    public String getDocNum() {
054        return this.docNum;
055    }
056
057    /**
058     * @param docNum the docNum to set
059     */
060    public void setDocNum(String docNum) {
061        this.docNum = docNum;
062    }
063
064    /**
065     * @return boolean
066     */
067    public String getShowReasonField() {
068        return showReasonField;
069    }
070
071    /**
072     * @param showReasonField
073     */
074    public void setShowReasonField(String showReasonField) {
075        this.showReasonField = showReasonField;
076    }
077
078    /**
079     * @return Returns the buttons.
080     */
081    public ArrayList getButtons() {
082        return buttons;
083    }
084
085    /**
086     * @return Returns the caller.
087     */
088    public String getCaller() {
089        return caller;
090    }
091
092    /**
093     * @return Returns the formKey.
094     */
095    public String getFormKey() {
096        return formKey;
097    }
098
099    /**
100     * @return Returns the questionIndex.
101     */
102    public String getQuestionIndex() {
103        return questionIndex;
104    }
105
106    /**
107     * @return Returns the questionText.
108     */
109    public String getQuestionText() {
110        return questionText != null ? WebUtils.filterHtmlAndReplaceRiceMarkup(questionText) : questionText;
111    }
112
113    /**
114     * @return Returns the questionName.
115     */
116    public String getQuestionType() {
117        return questionType;
118    }
119
120    /**
121     * @return Returns the title.
122     */
123    public String getTitle() {
124        return title;
125    }
126
127    /**
128     * @see org.kuali.rice.krad.web.struts.pojo.PojoForm#populate(javax.servlet.http.HttpServletRequest)
129     */
130    public void populate(HttpServletRequest request) {
131        super.populate(request);
132
133        // set the title of the jsp, this should come from a resource bundle
134        title = KRADConstants.QUESTION_PAGE_TITLE;
135
136        if (request.getAttribute(KRADConstants.DOC_FORM_KEY) != null) {
137            this.setFormKey((String) request.getAttribute(KRADConstants.DOC_FORM_KEY));
138        }
139        else if (request.getParameter(KRADConstants.DOC_FORM_KEY) != null) {
140            this.setFormKey(request.getParameter(KRADConstants.DOC_FORM_KEY));
141        }
142        
143        if (request.getAttribute(KRADConstants.DOC_NUM) != null) {
144            this.setFormKey((String) request.getAttribute(KRADConstants.DOC_NUM));
145        }
146        
147
148        if (request.getParameter(KRADConstants.RETURN_LOCATION_PARAMETER) != null) {
149            this.setBackLocation(request.getParameter(KRADConstants.RETURN_LOCATION_PARAMETER));
150        }
151
152        if (getMethodToCall().equals(KRADConstants.START_METHOD)) { // don't do this for the processAnswer action otherwise it blows up
153            Question kualiQuestion = KNSServiceLocator.getQuestion(questionType);
154            if (kualiQuestion == null) {
155                throw new RuntimeException("question implementation not found: " + request.getParameter(KRADConstants.QUESTION_IMPL_ATTRIBUTE_NAME));
156            }
157           
158            // KULRICE-8077: PO Quote Limitation of Only 9 Vendors
159            String questionId = request.getParameter(KRADConstants.QUESTION_INST_ATTRIBUTE_NAME);
160            String questionTextAttributeName = KRADConstants.QUESTION_TEXT_ATTRIBUTE_NAME + questionId;
161            
162            if (GlobalVariables.getUserSession().retrieveObject(questionTextAttributeName)!=null) {
163                this.setQuestionText((String)GlobalVariables.getUserSession().retrieveObject(questionTextAttributeName));
164                GlobalVariables.getUserSession().removeObject(questionTextAttributeName);
165            }
166           
167            // some questions types default these so we should default if not
168            // present in request
169            if (questionText == null) {
170                questionText = kualiQuestion.getQuestion();
171            }
172
173            if (buttons == null) {
174                buttons = kualiQuestion.getButtons();
175            }
176        }
177    }
178
179    /**
180     * @param buttons The buttons to set.
181     */
182    public void setButtons(ArrayList buttons) {
183        this.buttons = buttons;
184    }
185
186    /**
187     * @param caller The caller to set.
188     */
189    public void setCaller(String caller) {
190        this.caller = caller;
191    }
192
193    /**
194     * @param formKey The formKey to set.
195     */
196    public void setFormKey(String formKey) {
197        this.formKey = formKey;
198    }
199
200    /**
201     * @param questionIndex The questionIndex to set.
202     */
203    public void setQuestionIndex(String questionIndex) {
204        this.questionIndex = questionIndex;
205    }
206
207    /**
208     * @param questionText The questionText to set.
209     */
210    public void setQuestionText(String questionText) {
211        this.questionText = questionText;
212    }
213
214    /**
215     * @param questionName The questionName to set.
216     */
217    public void setQuestionType(String questionName) {
218        this.questionType = questionName;
219    }
220
221    /**
222     * @param title The title to set.
223     */
224    public void setTitle(String title) {
225        this.title = title;
226    }
227
228    public String getContext() {
229        return context;
230    }
231
232    public void setContext(String context) {
233        this.context = context;
234    }
235
236    /**
237     * @return String
238     */
239    public String getReason() {
240        return reason;
241    }
242
243    /**
244     * @param reason
245     */
246    public void setReason(String reason) {
247        this.reason = reason;
248    }
249
250    public String getQuestionAnchor() {
251        return questionAnchor;
252    }
253
254    public void setQuestionAnchor(String questionAnchor) {
255        this.questionAnchor = questionAnchor;
256    }
257
258    public String getMethodToCallPath() {
259        return methodToCallPath;
260}
261    public void setMethodToCallPath(String methodToCallPath) {
262        this.methodToCallPath = methodToCallPath;
263    }
264    
265}