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