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