Coverage Report - org.kuali.rice.kns.web.struts.form.KualiExceptionIncidentForm
 
Classes in this File Line Coverage Branch Coverage Complexity
KualiExceptionIncidentForm
0%
0/98
0%
0/16
1.393
 
 1  
 /**
 2  
  * Copyright 2005-2011 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  
 package org.kuali.rice.kns.web.struts.form;
 17  
 
 18  
 import org.apache.log4j.Logger;
 19  
 import org.apache.struts.action.ActionMapping;
 20  
 import org.kuali.rice.krad.exception.ExceptionIncident;
 21  
 import org.kuali.rice.krad.util.KRADConstants;
 22  
 
 23  
 import javax.servlet.http.HttpServletRequest;
 24  
 import java.util.HashMap;
 25  
 import java.util.HashSet;
 26  
 import java.util.Map;
 27  
 import java.util.Set;
 28  
 
 29  
 /**
 30  
  * This class is the action form for all Question Prompts.
 31  
  * 
 32  
  * 
 33  
  */
 34  0
 public class KualiExceptionIncidentForm extends KualiForm {
 35  
     private static final long serialVersionUID = 831951332440283401L;
 36  0
     private static Logger LOG=Logger.getLogger(KualiExceptionIncidentForm.class); 
 37  
     
 38  
     /**
 39  
      * The form properties that should be populated in order for the toMap() method to function properly.
 40  
      */
 41  0
     private static final Set<String> PROPS_NEEDED_FOR_MAP = new HashSet<String>();
 42  
     static {
 43  0
             PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.DOCUMENT_ID);
 44  0
             PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.USER_EMAIL);
 45  0
             PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.USER_NAME);
 46  0
             PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.UUID);
 47  0
             PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.COMPONENT_NAME);
 48  0
             PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.DESCRIPTION);
 49  0
             PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.EXCEPTION_REPORT_SUBJECT);
 50  0
             PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.EXCEPTION_MESSAGE);
 51  0
             PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.DISPLAY_MESSAGE);
 52  0
             PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.STACK_TRACE);
 53  0
     }
 54  
     
 55  
     /**
 56  
      * Flag to determine whether it's cancel action
 57  
      */
 58  0
     private boolean cancel=false;
 59  
     /**
 60  
      * Object containing exception information
 61  
      */
 62  
 //    private KualiExceptionIncident exceptionIncident;
 63  
     /**
 64  
      * The error subject created from current settings and thrown exception
 65  
      */
 66  
      private String exceptionReportSubject;
 67  
     /**
 68  
      * The error message
 69  
      */
 70  
      private String exceptionMessage;
 71  
      /**
 72  
       * The error message to be displayed
 73  
       */
 74  
       private String displayMessage;
 75  
      /**
 76  
      * Additional message from user
 77  
      */
 78  
      private String description;
 79  
      /**
 80  
       * Document id. it's blank if not a document process
 81  
       */
 82  0
      private String documentId=""; 
 83  
      /**
 84  
       * Session user email address
 85  
       */
 86  0
      private String userEmail="";
 87  
      /**
 88  
       * Session user name
 89  
       */
 90  0
      private String principalName="";
 91  
      /**
 92  
       * Session user name
 93  
       */
 94  0
      private String userName="";
 95  
      /**
 96  
       * Detail message not for displaying
 97  
       */
 98  
      private String stackTrace;
 99  
      /**
 100  
      * Form that threw the exception
 101  
      */
 102  
     private String componentName;
 103  
 
 104  
     /**
 105  
      * @see org.kuali.rice.krad.web.struts.pojo.PojoForm#populate(javax.servlet.http.HttpServletRequest)
 106  
      */
 107  
     public void populate(HttpServletRequest request) {
 108  
         
 109  0
         super.populate(request);
 110  
         
 111  
         // KULRICE-4402: ie explorer needs this.
 112  0
         if(notNull(request.getParameter(KRADConstants.CANCEL_METHOD + ".x")) && notNull(request.getParameter(
 113  
                 KRADConstants.CANCEL_METHOD + ".y"))){
 114  0
                 this.setCancel(true);
 115  
         }                
 116  0
     }
 117  
     
 118  
     private boolean notNull(String s){
 119  0
             if(s != null && !"".equals(s)){
 120  0
                     return true;
 121  
             }else 
 122  0
                     return false;
 123  
     }
 124  
 
 125  
     /*
 126  
      * Reset method - reset attributes of form retrieved from session otherwise
 127  
      * we will always call docHandler action
 128  
      * @param mapping
 129  
      * @param request
 130  
      */
 131  
     public void reset(ActionMapping mapping, HttpServletRequest request) {
 132  
         
 133  0
         this.setMethodToCall(null);
 134  0
         this.setRefreshCaller(null);
 135  0
         this.setAnchor(null);
 136  0
         this.setCurrentTabIndex(0);
 137  
         
 138  0
         this.cancel=false;
 139  0
         this.documentId=null;
 140  0
         this.componentName=null;
 141  0
         this.description=null;
 142  0
         this.displayMessage=null;
 143  0
         this.exceptionMessage=null;
 144  0
         this.stackTrace=null;
 145  0
         this.userEmail=null;
 146  0
         this.userName=null;
 147  0
         this.principalName=null;
 148  
 
 149  0
     }
 150  
     
 151  
     /**
 152  
      * This method return list of required information contained by the jsp in both
 153  
      * display and hidden properties.
 154  
      * 
 155  
      * @return
 156  
      * <p>Example:
 157  
      * <code>
 158  
      * documentId, 2942084
 159  
      * userEmail, someone@somewhere
 160  
      * userName, some name
 161  
      * componentFormName, Form that threw exception name
 162  
      * exceptionMessage, Error message from exception
 163  
      * displayMessage, Either exception error message or generic exception error message
 164  
      * stackTrace, Exception stack trace here
 165  
      * </code>
 166  
      * 
 167  
      */
 168  
     public Map<String, String> toMap() {
 169  0
         if (LOG.isTraceEnabled()) {
 170  0
             String message=String.format("ENTRY");
 171  0
             LOG.trace(message);
 172  
         }
 173  
         
 174  0
         Map<String, String> map=new HashMap<String, String>();
 175  0
         map.put(ExceptionIncident.DOCUMENT_ID, this.documentId);
 176  0
         map.put(ExceptionIncident.USER_EMAIL, this.userEmail);
 177  0
         map.put(ExceptionIncident.USER_NAME, this.userName);
 178  0
         map.put(ExceptionIncident.UUID, this.principalName);
 179  0
         map.put(ExceptionIncident.COMPONENT_NAME, this.componentName);
 180  0
         map.put(ExceptionIncident.DESCRIPTION, this.description);
 181  0
         map.put(ExceptionIncident.EXCEPTION_REPORT_SUBJECT, this.exceptionReportSubject);
 182  0
         map.put(ExceptionIncident.EXCEPTION_MESSAGE, this.exceptionMessage);
 183  0
         map.put(ExceptionIncident.DISPLAY_MESSAGE, this.displayMessage);
 184  0
         map.put(ExceptionIncident.STACK_TRACE, this.stackTrace);
 185  
         
 186  0
         if (LOG.isTraceEnabled()) {
 187  0
             String message=String.format("ENTRY %s", map.toString());
 188  0
             LOG.trace(message);
 189  
         }
 190  
         
 191  0
         return map;
 192  
     }
 193  
 
 194  
     /**
 195  
      * @return the cancel
 196  
      */
 197  
     public final boolean isCancel() {
 198  0
         return this.cancel;
 199  
     }
 200  
 
 201  
     /**
 202  
      * @param cancel the cancel to set
 203  
      */
 204  
     public final void setCancel(boolean cancel) {
 205  0
         this.cancel = cancel;
 206  0
     }
 207  
 
 208  
     /**
 209  
      * @return the exceptionIncident
 210  
      */
 211  
 //    public final KualiExceptionIncident getExceptionIncident() {
 212  
 //        return this.exceptionIncident;
 213  
 //    }
 214  
 
 215  
     /**
 216  
      * @return the description
 217  
      */
 218  
     public final String getDescription() {
 219  0
         return this.description;
 220  
     }
 221  
 
 222  
     /**
 223  
      * @param description the description to set
 224  
      */
 225  
     public final void setDescription(String description) {
 226  0
         this.description = description;
 227  0
     }
 228  
 
 229  
     /**
 230  
      * @return the exceptionMessage
 231  
      */
 232  
     public final String getExceptionMessage() {
 233  0
         return this.exceptionMessage;
 234  
     }
 235  
 
 236  
     /**
 237  
      * @param exceptionMessage the exceptionMessage to set
 238  
      */
 239  
     public final void setExceptionMessage(String exceptionMessage) {
 240  0
         this.exceptionMessage = exceptionMessage;
 241  0
     }
 242  
 
 243  
     /**
 244  
      * @return the displayMessage
 245  
      */
 246  
     public final String getDisplayMessage() {
 247  0
         return this.displayMessage;
 248  
     }
 249  
 
 250  
     /**
 251  
      * @param displayMessage the displayMessage to set
 252  
      */
 253  
     public final void setDisplayMessage(String displayMessage) {
 254  0
         this.displayMessage = displayMessage;
 255  0
     }
 256  
 
 257  
     /**
 258  
      * @return the documentId
 259  
      */
 260  
     public final String getDocumentId() {
 261  0
         return this.documentId;
 262  
     }
 263  
 
 264  
     /**
 265  
      * @param documentId the documentId to set
 266  
      */
 267  
     public final void setDocumentId(String documentId) {
 268  0
         this.documentId = documentId;
 269  0
     }
 270  
     
 271  
     /**
 272  
      * @return the userEmail
 273  
      */
 274  
     public final String getUserEmail() {
 275  0
         return this.userEmail;
 276  
     }
 277  
 
 278  
     /**
 279  
      * @param userEmail the userEmail to set
 280  
      */
 281  
     public final void setUserEmail(String userEmail) {
 282  0
         this.userEmail = userEmail;
 283  0
     }
 284  
 
 285  
     /**
 286  
          * @return the principalName
 287  
          */
 288  
         public String getPrincipalName() {
 289  0
                 return this.principalName;
 290  
         }
 291  
 
 292  
         /**
 293  
          * @param principalName the principalName to set
 294  
          */
 295  
         public void setPrincipalName(String principalName) {
 296  0
                 this.principalName = principalName;
 297  0
         }
 298  
 
 299  
         /**
 300  
      * @return the userName
 301  
      */
 302  
     public final String getUserName() {
 303  0
         return this.userName;
 304  
     }
 305  
 
 306  
     /**
 307  
      * @param userName the userName to set
 308  
      */
 309  
     public final void setUserName(String userName) {
 310  0
         this.userName = userName;
 311  0
     }
 312  
 
 313  
     /**
 314  
      * @param stackTrace the stackTrace to set
 315  
      */
 316  
     public final void setStackTrace(String stackTrace) {
 317  0
         this.stackTrace = stackTrace;
 318  0
     }
 319  
 
 320  
     /**
 321  
      * @return the stackTrace
 322  
      */
 323  
     public final String getStackTrace() {
 324  0
         return this.stackTrace;
 325  
     }
 326  
 
 327  
     /**
 328  
      * @return the exceptionReportSubject
 329  
      */
 330  
     public final String getExceptionReportSubject() {
 331  0
         return this.exceptionReportSubject;
 332  
     }
 333  
 
 334  
     /**
 335  
      * @param exceptionReportSubject the exceptionReportSubject to set
 336  
      */
 337  
     public final void setExceptionReportSubject(String exceptionReportSubject) {
 338  0
         this.exceptionReportSubject = exceptionReportSubject;
 339  0
     }
 340  
 
 341  
     /**
 342  
      * @return the componentName
 343  
      */
 344  
     public final String getComponentName() {
 345  0
         return this.componentName;
 346  
     }
 347  
 
 348  
     /**
 349  
      * @param componentName the componentName to set
 350  
      */
 351  
     public final void setComponentName(String componentName) {
 352  0
         this.componentName = componentName;
 353  0
     }
 354  
 
 355  
         /**
 356  
          * This overridden method ...
 357  
          * 
 358  
          * @see org.kuali.rice.krad.web.struts.form.KualiForm#shouldMethodToCallParameterBeUsed(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest)
 359  
          */
 360  
         @Override
 361  
         public boolean shouldMethodToCallParameterBeUsed(
 362  
                         String methodToCallParameterName,
 363  
                         String methodToCallParameterValue, HttpServletRequest request) {
 364  
                 // we will allow all method to calls since the KualiExceptionHandlerAction will ignore the methodToCall
 365  0
                 return true;
 366  
         }
 367  
 
 368  
         /**
 369  
          * @see org.kuali.rice.krad.web.struts.form.KualiForm#shouldPropertyBePopulatedInForm(java.lang.String, javax.servlet.http.HttpServletRequest)
 370  
          */
 371  
         @Override
 372  
         public boolean shouldPropertyBePopulatedInForm(
 373  
                         String requestParameterName, HttpServletRequest request) {
 374  0
                 if (PROPS_NEEDED_FOR_MAP.contains(requestParameterName)) {
 375  0
                         return true;
 376  
                 }
 377  0
                 else if (KRADConstants.CANCEL_METHOD.equals(requestParameterName)) {
 378  0
                         return true;
 379  
                 }
 380  0
                 return super.shouldPropertyBePopulatedInForm(requestParameterName, request);
 381  
         }
 382  
 }
 383