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