1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.miloss.fgsms.presentation;
22
23 import de.laures.cewolf.DatasetProduceException;
24 import de.laures.cewolf.DatasetProducer;
25 import java.io.Serializable;
26 import java.net.URL;
27 import java.util.ArrayList;
28 import java.util.Date;
29 import java.util.List;
30 import java.util.Map;
31 import org.miloss.fgsms.common.Utility;
32 import org.miloss.fgsms.services.interfaces.dataaccessservice.GetMessageLogsResponseMsg;
33 import org.miloss.fgsms.services.interfaces.dataaccessservice.TransactionLog;
34 import org.apache.log4j.Level;
35 import org.miloss.fgsms.common.Logger;;
36 import org.jfree.data.time.Millisecond;
37 import org.jfree.data.time.TimeSeries;
38 import org.jfree.data.time.TimeSeriesCollection;
39
40
41
42
43
44 public class TransactionLogViewerData implements DatasetProducer, Serializable {
45
46 public TransactionLogViewerData() {
47 }
48
49 public TransactionLogViewerData(URL url) {
50 dasu = url;
51 }
52 private URL dasu=null;
53 private List<TransactionLog> data=null;
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162 public String GetRenderedData(GetMessageLogsResponseMsg res)
163 {
164 String out = "";
165 if (res == null)
166 return out;
167 try
168 {
169 out += ("Total Records available: " + res.getTotalRecords());
170
171 if (res.getLogs() != null
172 && res.getLogs() != null
173 && res.getLogs().getTransactionLog() != null
174 && res.getLogs().getTransactionLog().size() > 0) {
175 out += ("<table border=1><tr>"
176 + "<th>Action</th>"
177 + "<th>Success/Fault</th>"
178 + "<th>Requestor Identity</th>"
179 + "<th>Response Time</th>"
180
181 + "<th>Timestamp</th>"
182 + "<th>SLA Violation</th>"
183 + "<th>Details</th></tr>");
184 data = res.getLogs().getTransactionLog();
185
186
187
188 boolean colorflag = false;
189 for (int i = 0; i < res.getLogs().getTransactionLog().size(); i++) {
190 out += ("<tr ");
191 colorflag = !colorflag;
192 if (colorflag) {
193 out += " bgcolor=#EEFFEE><td>";
194 } else {
195 out += " bgcolor=#DDFFDD><td>";
196 }
197 int clip = 0;
198
199 if (Utility.stringIsNullOrEmpty(res.getLogs().getTransactionLog().get(i).getAction())) {
200 out += "NA</td><td>";
201 } else {
202 out += (res.getLogs().getTransactionLog().get(i).getAction() + "</td><td>");
203 }
204 if (!res.getLogs().getTransactionLog().get(i).isIsFault()) {
205 out += ("<font color=#FF0000><b>Fault</b></font>");
206 } else {
207 out += ("Success");
208 }
209 out += ("</td><td>" + Utility.encodeHTML(ParseIdentities(res.getLogs().getTransactionLog().get(i).getIdentity()))
210 + "</td><td>" + res.getLogs().getTransactionLog().get(i).getResponseTime()
211 + "ms</td>");
212
213 out += ("<td>" + res.getLogs().getTransactionLog().get(i).getTimestamp().toString()
214 + "</td><td>");
215 if (res.getLogs().getTransactionLog().get(i).isIsSLAFault()) {
216 out += ("<font color=#FF0000><b>Fault</b></font>");
217 }
218 out += "</td><td>"
219 + Utility.encodeHTML(res.getLogs().getTransactionLog().get(i).getSlaFaultMsg())
220 + "<a href=\"SpecificTransactionLogViewer.jsp?ID=" + res.getLogs().getTransactionLog().get(i).getTransactionId() + "\">Details</a>"
221 + "</td></tr></tr>";
222
223 }
224
225
226 } else {
227 out += "<br><Br>No records were returned.";
228 }
229
230 } catch (SecurityException ex) {
231 out += ("Access was denied to the requested resource.");
232 LogHelper.getLog().log(Level.ERROR, "TransactionLogViewer, access denied when error rendering data for user ");
233 } catch (Exception ex) {
234 Logger.getLogger("fgsms.Web").log(Level.WARN, "Error caught", ex);
235 out += ("There was an error processing your request. Message: " + ex.getLocalizedMessage());
236 LogHelper.getLog().log(Level.ERROR, "TransactionLogViewer, error rendering data for user ", ex);
237 }
238 return out;
239 }
240 public Object produceDataset(Map params) throws DatasetProduceException {
241
242
243 TimeSeriesCollection col = new TimeSeriesCollection();
244
245
246 try {
247 GetMessageLogsResponseMsg res = (GetMessageLogsResponseMsg) params.get("fgsms.data");
248 TransactionLogData recordset = new TransactionLogData();
249 if (res != null && res.getLogs() != null && res.getLogs() != null && res.getLogs().getTransactionLog() != null && res.getLogs().getTransactionLog().size() > 0) {
250
251
252 for (int i = 0; i < res.getLogs().getTransactionLog().size(); i++) {
253 String action = res.getLogs().getTransactionLog().get(i).getAction();
254 int clip = 0;
255 if (res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("/") > clip) {
256 clip = res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("/");
257 }
258 if (res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("}") > clip) {
259 clip = res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("}");
260 }
261 if (res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf(":") > clip) {
262 clip = res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf(":");
263 }
264 if (res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("#") > clip) {
265 clip = res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("#");
266 }
267
268 if (clip > 0) {
269 action = (res.getLogs().getTransactionLog().get(i).getAction().substring(clip + 1));
270 }
271 TransactionLogTimeStampStruct t2 = new TransactionLogTimeStampStruct();
272 t2.ResponseTime = res.getLogs().getTransactionLog().get(i).getResponseTime();
273 t2.cal = res.getLogs().getTransactionLog().get(i).getTimestamp();
274 if (recordset.Contains(action)) {
275 recordset.get(action).add(t2);
276 } else {
277 TransactionLogStruct t3 = new TransactionLogStruct();
278 t3.action = action;
279 t3.data = new ArrayList<TransactionLogTimeStampStruct>();
280 t3.data.add(t2);
281 recordset.add(t3);
282 }
283
284
285 }
286
287 for (int i = 0; i < recordset.stuff.size(); i++) {
288 TimeSeries s = new TimeSeries(recordset.stuff.get(i).action, org.jfree.data.time.Millisecond.class);
289
290 for (int k = 0; k < recordset.stuff.get(i).data.size(); k++) {
291 Millisecond m = new Millisecond(recordset.stuff.get(i).data.get(k).cal.getTime());
292
293
294
295
296 s.addOrUpdate(m, recordset.stuff.get(i).data.get(k).ResponseTime);
297
298 }
299
300 col.addSeries(s);
301
302 }
303 }
304 } catch (Exception ex) {
305 LogHelper.getLog().log(Level.ERROR, "TransactionLogViewerData produce chart data " + ex.getLocalizedMessage());
306 }
307
308 return col;
309 }
310
311 public boolean hasExpired(Map params, Date since) {
312 return (System.currentTimeMillis() - since.getTime()) > 5000;
313 }
314
315 public String getProducerId() {
316 return "fgsms.TransactionLogViewerData";
317 }
318
319 public static String ParseIdentities(List<String> identity) {
320 if (identity == null || identity.isEmpty()) {
321
322 return "";
323 }
324 StringBuilder ret = new StringBuilder();
325 for (int i = 0; i < identity.size(); i++) {
326 ret= ret.append(identity.get(i)).append(", ");
327 }
328 String r = ret.toString().trim();
329
330 return r.substring(0, ret.length() - 1);
331
332 }
333 }