1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
27
28
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
58
59
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
76
77
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
89
90
91
92
93
94
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
104
105
106
107
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
120
121 public String getErrorMessage() {
122 return this.errorMessage;
123 }
124
125
126
127
128
129 public void setErrorMessage(String errorMessage) {
130 this.errorMessage = errorMessage;
131 }
132
133
134
135
136 public String getExceptionMessage() {
137 return this.exceptionMessage;
138 }
139
140
141
142
143
144 public void setExceptionMessage(String exceptionMessage) {
145 this.exceptionMessage = exceptionMessage;
146 }
147
148
149
150
151 public String getExceptionStackTrace() {
152 return this.exceptionStackTrace;
153 }
154
155
156
157
158
159 public void setExceptionStackTrace(String exceptionStackTrace) {
160 this.exceptionStackTrace = exceptionStackTrace;
161 }
162
163
164
165
166 public String getUserInput() {
167 return this.userInput;
168 }
169
170
171
172
173
174 public void setUserInput(String userInput) {
175 this.userInput = userInput;
176 }
177
178
179
180
181 public boolean isDevMode() {
182 return this.devMode;
183 }
184
185
186
187
188
189 public void setDevMode(boolean devMode) {
190 this.devMode = devMode;
191 }
192
193
194
195
196
197 public void setIncidentDocId(String incidentDocId) {
198 this.incidentDocId = incidentDocId;
199 }
200
201
202
203
204 public String getIncidentDocId() {
205 return incidentDocId;
206 }
207
208
209
210
211
212 public void setIncidentViewId(String incidentViewId) {
213 this.incidentViewId = incidentViewId;
214 }
215
216
217
218
219 public String getIncidentViewId() {
220 return incidentViewId;
221 }
222
223
224
225
226
227 public void setException(Exception exception) {
228 this.exception = exception;
229 setExceptionStackTrace(getStackTrace(exception));
230 setExceptionMessage(exception.getMessage());
231 }
232
233
234
235
236 public Exception getException() {
237 return exception;
238 }
239
240
241
242
243
244 public void setUserName(String userName) {
245 this.userName = userName;
246 }
247
248
249
250
251 public String getUserName() {
252 return userName;
253 }
254
255
256
257
258
259 public void setUserId(String userId) {
260 this.userId = userId;
261 }
262
263
264
265
266 public String getUserId() {
267 return userId;
268 }
269
270
271
272
273
274 public void setUserEmail(String userEmail) {
275 this.userEmail = userEmail;
276 }
277
278
279
280
281 public String getUserEmail() {
282 return userEmail;
283 }
284
285
286
287
288
289 public void setController(String controller) {
290 this.controller = controller;
291 }
292
293
294
295
296 public String getController() {
297 return controller;
298 }
299
300 }