View Javadoc

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