Coverage Report - org.kuali.rice.krad.web.form.IncidentReportForm
 
Classes in this File Line Coverage Branch Coverage Complexity
IncidentReportForm
0%
0/58
0%
0/22
1.379
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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/ecl1.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.krad.web.form;
 17  
 
 18  
 import org.kuali.rice.krad.service.KRADServiceLocator;
 19  
 
 20  
 import java.io.PrintWriter;
 21  
 import java.io.StringWriter;
 22  
 
 23  
 /**
 24  
  * Form class for incident reports
 25  
  * 
 26  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 27  
  */
 28  
 public class IncidentReportForm extends UifFormBase {
 29  
 
 30  
     private static final long serialVersionUID = -6677581167041430694L;
 31  
 
 32  0
     protected String errorMessage = "The system has encountered an error and is unable to complete your request at this time. Please provide more information regarding this error by completing this Incident Report.";
 33  
 
 34  
     protected Exception exception;
 35  
     protected String exceptionMessage;
 36  
     protected String exceptionStackTrace;
 37  
 
 38  
     protected String userInput;
 39  
     protected String incidentDocId;
 40  
     protected String incidentViewId;
 41  
     protected String controller;
 42  
     protected String userName;
 43  
     protected String userId;
 44  
     protected String userEmail;
 45  
 
 46  
     protected boolean devMode;
 47  
 
 48  
     public IncidentReportForm() {
 49  0
         super();
 50  0
         setViewTypeName("INCIDENT");
 51  0
     }
 52  
 
 53  
     /**
 54  
      * Creates the email message from the exception, form and user data.
 55  
      * 
 56  
      * @return the email message
 57  
      */
 58  
     public String createEmailMessage() {
 59  0
         String format = "Document Id: %s%n" + "View Id: %s%n" + "Handler: %s%n%n" + "User Email: %s%n"
 60  
                 + "Person User Identifier: %s%n" + "Person Name: %s%n" + "User Input: %s%n%n" + "errorMessage: %n"
 61  
                 + "%s";
 62  0
         String message = String.format(format, (incidentDocId == null) ? "" : incidentDocId, (incidentViewId == null) ? "" : incidentViewId,
 63  
                 (controller == null) ? "" : controller, (userEmail == null) ? "" : userEmail, (userId == null) ? ""
 64  
                         : userId, (userName == null) ? "" : userName, (userInput == null) ? "" : userInput,
 65  
                 (exceptionStackTrace == null) ? "" : exceptionStackTrace);
 66  
 
 67  0
         return message;
 68  
 
 69  
     }
 70  
 
 71  
     /**
 72  
      * Creates the email subject containing the mode, view id and the exception message.
 73  
      * 
 74  
      * @return the email subject
 75  
      */
 76  
     public String createEmailSubject() {
 77  0
         String env = KRADServiceLocator.getKualiConfigurationService().getPropertyString("environment");
 78  0
         String format = "%s:%s:%s";
 79  0
         String subject = String.format(format, env, (incidentViewId == null) ? "" : incidentViewId,
 80  
                 truncateString(exceptionMessage, 180));
 81  0
         return subject;
 82  
     }
 83  
 
 84  
     /**
 85  
      * Truncate the string to specified length.
 86  
      * 
 87  
      * @param str
 88  
      *            the string to truncate
 89  
      * @param maxLength
 90  
      *            the max length
 91  
      * @return the truncated string
 92  
      */
 93  
     protected String truncateString(String str, int maxLength) {
 94  0
         if (str != null && str.length() > maxLength)
 95  0
             str = str.substring(0, maxLength);
 96  0
         return str;
 97  
     }
 98  
 
 99  
     /**
 100  
      * Gets the stack trace from an exception.
 101  
      * 
 102  
      * @param t
 103  
      *            the throwable to get the stack trace from
 104  
      * @return the stack trace
 105  
      */
 106  
     protected String getStackTrace(Throwable t) {
 107  0
         StringWriter sw = new StringWriter();
 108  0
         PrintWriter pw = new PrintWriter(sw, true);
 109  0
         t.printStackTrace(pw);
 110  0
         pw.flush();
 111  0
         sw.flush();
 112  0
         return sw.toString();
 113  
     }
 114  
 
 115  
     /**
 116  
      * @return the errorMessage
 117  
      */
 118  
     public String getErrorMessage() {
 119  0
         return this.errorMessage;
 120  
     }
 121  
 
 122  
     /**
 123  
      * @param errorMessage
 124  
      *            the errorMessage to set
 125  
      */
 126  
     public void setErrorMessage(String errorMessage) {
 127  0
         this.errorMessage = errorMessage;
 128  0
     }
 129  
 
 130  
     /**
 131  
      * @return the exceptionMessage
 132  
      */
 133  
     public String getExceptionMessage() {
 134  0
         return this.exceptionMessage;
 135  
     }
 136  
 
 137  
     /**
 138  
      * @param exceptionMessage
 139  
      *            the exceptionMessage to set
 140  
      */
 141  
     public void setExceptionMessage(String exceptionMessage) {
 142  0
         this.exceptionMessage = exceptionMessage;
 143  0
     }
 144  
 
 145  
     /**
 146  
      * @return the exceptionStackTrace
 147  
      */
 148  
     public String getExceptionStackTrace() {
 149  0
         return this.exceptionStackTrace;
 150  
     }
 151  
 
 152  
     /**
 153  
      * @param exceptionStackTrace
 154  
      *            the exceptionStackTrace to set
 155  
      */
 156  
     public void setExceptionStackTrace(String exceptionStackTrace) {
 157  0
         this.exceptionStackTrace = exceptionStackTrace;
 158  0
     }
 159  
 
 160  
     /**
 161  
      * @return the userInput
 162  
      */
 163  
     public String getUserInput() {
 164  0
         return this.userInput;
 165  
     }
 166  
 
 167  
     /**
 168  
      * @param userInput
 169  
      *            the userInput to set
 170  
      */
 171  
     public void setUserInput(String userInput) {
 172  0
         this.userInput = userInput;
 173  0
     }
 174  
 
 175  
     /**
 176  
      * @return the devMode
 177  
      */
 178  
     public boolean isDevMode() {
 179  0
         return this.devMode;
 180  
     }
 181  
 
 182  
     /**
 183  
      * @param devMode
 184  
      *            the devMode to set
 185  
      */
 186  
     public void setDevMode(boolean devMode) {
 187  0
         this.devMode = devMode;
 188  0
     }
 189  
 
 190  
     /**
 191  
      * @param incidentDocId
 192  
      *            the incidentDocId to set
 193  
      */
 194  
     public void setIncidentDocId(String incidentDocId) {
 195  0
         this.incidentDocId = incidentDocId;
 196  0
     }
 197  
 
 198  
     /**
 199  
      * @return the incidentDocId
 200  
      */
 201  
     public String getIncidentDocId() {
 202  0
         return incidentDocId;
 203  
     }
 204  
 
 205  
     /**
 206  
      * @param incidentViewId
 207  
      *            the incidentViewId to set
 208  
      */
 209  
     public void setIncidentViewId(String incidentViewId) {
 210  0
         this.incidentViewId = incidentViewId;
 211  0
     }
 212  
 
 213  
     /**
 214  
      * @return the incidentViewId
 215  
      */
 216  
     public String getIncidentViewId() {
 217  0
         return incidentViewId;
 218  
     }
 219  
 
 220  
     /**
 221  
      * @param exception
 222  
      *            the exception to set
 223  
      */
 224  
     public void setException(Exception exception) {
 225  0
         this.exception = exception;
 226  0
         setExceptionStackTrace(getStackTrace(exception));
 227  0
         setExceptionMessage(exception.getMessage());
 228  0
     }
 229  
 
 230  
     /**
 231  
      * @return the exception
 232  
      */
 233  
     public Exception getException() {
 234  0
         return exception;
 235  
     }
 236  
 
 237  
     /**
 238  
      * @param userName
 239  
      *            the userName to set
 240  
      */
 241  
     public void setUserName(String userName) {
 242  0
         this.userName = userName;
 243  0
     }
 244  
 
 245  
     /**
 246  
      * @return the userName
 247  
      */
 248  
     public String getUserName() {
 249  0
         return userName;
 250  
     }
 251  
 
 252  
     /**
 253  
      * @param userId
 254  
      *            the userId to set
 255  
      */
 256  
     public void setUserId(String userId) {
 257  0
         this.userId = userId;
 258  0
     }
 259  
 
 260  
     /**
 261  
      * @return the userId
 262  
      */
 263  
     public String getUserId() {
 264  0
         return userId;
 265  
     }
 266  
 
 267  
     /**
 268  
      * @param userEmail
 269  
      *            the userEmail to set
 270  
      */
 271  
     public void setUserEmail(String userEmail) {
 272  0
         this.userEmail = userEmail;
 273  0
     }
 274  
 
 275  
     /**
 276  
      * @return the userEmail
 277  
      */
 278  
     public String getUserEmail() {
 279  0
         return userEmail;
 280  
     }
 281  
 
 282  
     /**
 283  
      * @param controller
 284  
      *            the controller to set
 285  
      */
 286  
     public void setController(String controller) {
 287  0
         this.controller = controller;
 288  0
     }
 289  
 
 290  
     /**
 291  
      * @return the controller
 292  
      */
 293  
     public String getController() {
 294  0
         return controller;
 295  
     }
 296  
 
 297  
 }