Coverage Report - org.kuali.rice.kns.web.struts.action.QuestionPromptAction
 
Classes in this File Line Coverage Branch Coverage Complexity
QuestionPromptAction
0%
0/40
0%
0/18
3
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.kuali.rice.kns.web.struts.action;
 18  
 
 19  
 import java.util.Map;
 20  
 import java.util.Properties;
 21  
 
 22  
 import javax.servlet.http.HttpServletRequest;
 23  
 import javax.servlet.http.HttpServletResponse;
 24  
 
 25  
 import org.apache.commons.lang.StringUtils;
 26  
 import org.apache.struts.action.ActionForm;
 27  
 import org.apache.struts.action.ActionForward;
 28  
 import org.apache.struts.action.ActionMapping;
 29  
 import org.kuali.rice.core.util.RiceConstants;
 30  
 import org.kuali.rice.kns.exception.AuthorizationException;
 31  
 import org.kuali.rice.kns.util.GlobalVariables;
 32  
 import org.kuali.rice.kns.util.KNSConstants;
 33  
 import org.kuali.rice.kns.util.UrlFactory;
 34  
 import org.kuali.rice.kns.web.struts.form.QuestionPromptForm;
 35  
 
 36  
 /**
 37  
  * This class handles Actions for QuestionPromp.
 38  
  *
 39  
  *
 40  
  */
 41  0
 public class QuestionPromptAction extends KualiAction {
 42  
         
 43  
     /**
 44  
          * This overridden method ...
 45  
          * 
 46  
          * @see org.kuali.rice.kns.web.struts.action.KualiAction#checkAuthorization(org.apache.struts.action.ActionForm, java.lang.String)
 47  
          */
 48  
         @Override
 49  
         protected void checkAuthorization(ActionForm form, String methodToCall)
 50  
                         throws AuthorizationException {
 51  
                 // no authorization required
 52  0
         }
 53  
 
 54  
         /**
 55  
      * This method is the entry point action for the question prompt component.
 56  
      *
 57  
      * @param mapping
 58  
      * @param form
 59  
      * @param request
 60  
      * @param response
 61  
      * @return ActionForward
 62  
      * @throws Exception
 63  
      */
 64  
     public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 65  
         // deal with the fact that some requests might be reposts from errors on the reason field
 66  0
         processErrorMessages(request);
 67  
 
 68  0
         return mapping.findForward(RiceConstants.MAPPING_BASIC);
 69  
     }
 70  
 
 71  
     /**
 72  
      * This method handles gathering all input and passing control back to the caller action.
 73  
      *
 74  
      * @param mapping
 75  
      * @param form
 76  
      * @param request
 77  
      * @param response
 78  
      * @return ActionForward
 79  
      * @throws Exception
 80  
      */
 81  
     public ActionForward processAnswer(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 82  0
         QuestionPromptForm questionPromptForm = (QuestionPromptForm) form;
 83  
 
 84  0
         Properties parameters = new Properties();
 85  
 
 86  0
         parameters.put(KNSConstants.DOC_FORM_KEY, questionPromptForm.getFormKey());
 87  0
         parameters.put(KNSConstants.QUESTION_CLICKED_BUTTON, getSelectedButton(request));
 88  0
         parameters.put(KNSConstants.METHOD_TO_CALL_ATTRIBUTE, questionPromptForm.getCaller());
 89  0
         parameters.put(KNSConstants.REFRESH_CALLER, KNSConstants.QUESTION_REFRESH);
 90  0
         parameters.put(KNSConstants.QUESTION_INST_ATTRIBUTE_NAME, questionPromptForm.getQuestionIndex());
 91  0
         if(questionPromptForm.getDocNum() != null){
 92  0
                 parameters.put(KNSConstants.DOC_NUM, questionPromptForm.getDocNum());
 93  
         }
 94  
         
 95  0
         if (StringUtils.isNotBlank(questionPromptForm.getQuestionAnchor())) {
 96  0
             parameters.put(KNSConstants.ANCHOR, questionPromptForm.getQuestionAnchor());
 97  
         }
 98  
 
 99  0
         String context = questionPromptForm.getContext();
 100  0
         if (StringUtils.isNotBlank(context)) {
 101  0
             parameters.put(KNSConstants.QUESTION_CONTEXT, context);
 102  
         }
 103  0
         String reason = questionPromptForm.getReason();
 104  0
         if (StringUtils.isNotBlank(reason)) {
 105  0
             parameters.put(KNSConstants.QUESTION_REASON_ATTRIBUTE_NAME, reason);
 106  
         }
 107  0
         if (StringUtils.isNotBlank(questionPromptForm.getMethodToCallPath())) {
 108  
             // For header tab navigation. Leaving it blank will just kick user back to page.
 109  0
             parameters.put(questionPromptForm.getMethodToCallPath(), "present");
 110  
         }
 111  
 
 112  0
         String returnUrl = UrlFactory.parameterizeUrl(questionPromptForm.getBackLocation(), parameters);
 113  
 
 114  0
         return new ActionForward(returnUrl, true);
 115  
     }
 116  
 
 117  
     /**
 118  
      * Parses the method to call attribute to pick off the button number that was pressed.
 119  
      *
 120  
      * @param request
 121  
      * @return int
 122  
      */
 123  
     private String getSelectedButton(HttpServletRequest request) {
 124  0
         String selectedButton = "-1";
 125  0
         String parameterName = (String) request.getAttribute(KNSConstants.METHOD_TO_CALL_ATTRIBUTE);
 126  0
         if (StringUtils.isNotBlank(parameterName)) {
 127  0
             selectedButton = StringUtils.substringBetween(parameterName, ".button", ".");
 128  
         }
 129  
 
 130  0
         return selectedButton;
 131  
     }
 132  
 
 133  
     /**
 134  
      * This method handles processing any error messages coming in the door.
 135  
      *
 136  
      * @param request
 137  
      */
 138  
     private void processErrorMessages(HttpServletRequest request) {
 139  0
         String errorKey = request.getParameter(KNSConstants.QUESTION_ERROR_KEY);
 140  0
         String errorPropertyName = request.getParameter(KNSConstants.QUESTION_ERROR_PROPERTY_NAME);
 141  0
         String errorParameter = request.getParameter(KNSConstants.QUESTION_ERROR_PARAMETER);
 142  
 
 143  0
         if (StringUtils.isNotBlank(errorKey)) {
 144  0
             if (StringUtils.isBlank(errorPropertyName)) {
 145  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.");
 146  
             }
 147  
             else {
 148  0
                 if (StringUtils.isBlank(errorParameter)) {
 149  0
                     GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPropertyName, errorKey);
 150  
                 }
 151  
                 else {
 152  0
                     GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPropertyName, errorKey, errorParameter);
 153  
                 }
 154  
             }
 155  
         }
 156  0
     }
 157  
 }