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.core.api.CoreApiServiceLocator;
19 import org.kuali.rice.krad.uif.UifConstants.ViewType;
20
21 import java.io.PrintWriter;
22 import java.io.StringWriter;
23
24
25
26
27
28
29 public class IncidentReportForm extends UifFormBase {
30 private static final long serialVersionUID = -6677581167041430694L;
31
32 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 super();
50
51 setViewTypeName(ViewType.INCIDENT);
52 }
53
54
55
56
57
58
59 public String createEmailMessage() {
60 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 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 return message;
69
70 }
71
72
73
74
75
76
77 public String createEmailSubject() {
78 String app = CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsString("application.id");
79 String env = CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsString("environment");
80 String format = "%s:%s:%s:%s";
81 String subject = String.format(format, app, env, (incidentViewId == null) ? "" : incidentViewId,
82 truncateString(exceptionMessage, 180));
83 return subject;
84 }
85
86
87
88
89
90
91
92
93
94
95 protected String truncateString(String str, int maxLength) {
96 if (str != null && str.length() > maxLength)
97 str = str.substring(0, maxLength);
98 return str;
99 }
100
101
102
103
104
105
106
107
108 protected String getStackTrace(Throwable t) {
109 StringWriter sw = new StringWriter();
110 PrintWriter pw = new PrintWriter(sw, true);
111 t.printStackTrace(pw);
112 pw.flush();
113 sw.flush();
114 return sw.toString();
115 }
116
117
118
119
120 public String getErrorMessage() {
121 return this.errorMessage;
122 }
123
124
125
126
127
128 public void setErrorMessage(String errorMessage) {
129 this.errorMessage = errorMessage;
130 }
131
132
133
134
135 public String getExceptionMessage() {
136 return this.exceptionMessage;
137 }
138
139
140
141
142
143 public void setExceptionMessage(String exceptionMessage) {
144 this.exceptionMessage = exceptionMessage;
145 }
146
147
148
149
150 public String getExceptionStackTrace() {
151 return this.exceptionStackTrace;
152 }
153
154
155
156
157
158 public void setExceptionStackTrace(String exceptionStackTrace) {
159 this.exceptionStackTrace = exceptionStackTrace;
160 }
161
162
163
164
165 public String getUserInput() {
166 return this.userInput;
167 }
168
169
170
171
172
173 public void setUserInput(String userInput) {
174 this.userInput = userInput;
175 }
176
177
178
179
180 public boolean isDevMode() {
181 return this.devMode;
182 }
183
184
185
186
187
188 public void setDevMode(boolean devMode) {
189 this.devMode = devMode;
190 }
191
192
193
194
195
196 public void setIncidentDocId(String incidentDocId) {
197 this.incidentDocId = incidentDocId;
198 }
199
200
201
202
203 public String getIncidentDocId() {
204 return incidentDocId;
205 }
206
207
208
209
210
211 public void setIncidentViewId(String incidentViewId) {
212 this.incidentViewId = incidentViewId;
213 }
214
215
216
217
218 public String getIncidentViewId() {
219 return incidentViewId;
220 }
221
222
223
224
225
226 public void setException(Exception exception) {
227 this.exception = exception;
228 setExceptionStackTrace(getStackTrace(exception));
229 setExceptionMessage(exception.getMessage());
230 }
231
232
233
234
235 public Exception getException() {
236 return exception;
237 }
238
239
240
241
242
243 public void setUserName(String userName) {
244 this.userName = userName;
245 }
246
247
248
249
250 public String getUserName() {
251 return userName;
252 }
253
254
255
256
257
258 public void setUserId(String userId) {
259 this.userId = userId;
260 }
261
262
263
264
265 public String getUserId() {
266 return userId;
267 }
268
269
270
271
272
273 public void setUserEmail(String userEmail) {
274 this.userEmail = userEmail;
275 }
276
277
278
279
280 public String getUserEmail() {
281 return userEmail;
282 }
283
284
285
286
287
288 public void setController(String controller) {
289 this.controller = controller;
290 }
291
292
293
294
295 public String getController() {
296 return controller;
297 }
298
299
300
301
302
303
304 public void setSessionId(String copiedSessionId) {
305 sessionId = copiedSessionId;
306 }
307
308 }