View Javadoc
1   /**
2    * This Source Code Form is subject to the terms of the Mozilla Public
3    * License, v. 2.0. If a copy of the MPL was not distributed with this
4    * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5    *
6    * If it is not possible or desirable to put the notice in a particular
7    * file, then You may include the notice in a location (such as a LICENSE
8    * file in a relevant directory) where a recipient would be likely to look
9    * for such a notice.
10  
11   * 
12   */
13   
14  /*  ---------------------------------------------------------------------------
15   *  U.S. Government, Department of the Army
16   *  Army Materiel Command
17   *  Research Development Engineering Command
18   *  Communications Electronics Research Development and Engineering Center
19   *  ---------------------------------------------------------------------------
20   */
21  
22  package org.miloss.fgsms.presentation;
23  
24  import de.laures.cewolf.DatasetProduceException;
25  import de.laures.cewolf.DatasetProducer;
26  import java.io.Serializable;
27  import java.util.Date;
28  import java.util.Map;
29  import org.miloss.fgsms.services.interfaces.dataaccessservice.GetMessageLogsResponseMsg;
30  import org.apache.log4j.Level;
31  import org.miloss.fgsms.common.Logger;;
32  import org.jfree.data.category.DefaultCategoryDataset;
33  
34  /**
35   *
36   * @author AO
37   */
38  public class TransactionLogActionBreakDown implements DatasetProducer, Serializable {
39  
40      public Object produceDataset(Map params) throws DatasetProduceException {
41          DefaultCategoryDataset data = new DefaultCategoryDataset();
42          try {
43              //Logger.getAnonymousLogger().log(Level.INFO, "fgsmsWEB debug, size" +  params.size());
44              GetMessageLogsResponseMsg res = (GetMessageLogsResponseMsg) params.get("fgsms.data");
45              TransactionLogActionSet set = new TransactionLogActionSet();
46  
47              if (res!=null && res.getLogs() != null && res.getLogs() != null && res.getLogs().getTransactionLog() != null && res.getLogs().getTransactionLog().size() > 0) {
48                  for (int i = 0; i < res.getLogs().getTransactionLog().size(); i++) {
49                      String action = res.getLogs().getTransactionLog().get(i).getAction();
50                      int clip = 0;
51                      if (res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("/") > clip) {
52                          clip = res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("/");
53                      }
54                      if (res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("}") > clip) {
55                          clip = res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("}");
56                      }
57                      if (res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf(":") > clip) {
58                          clip = res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf(":");
59                      }
60                      if (res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("#") > clip) {
61                          clip = res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("#");
62                      }
63  
64                      if (clip > 0) {
65                          action = (res.getLogs().getTransactionLog().get(i).getAction().substring(clip + 1));
66                      }
67                      if (set.Contains(action)) {
68                          if (res.getLogs().getTransactionLog().get(i).isIsFault()) {
69                              set.get(action).success++;
70                          } else {
71                              set.get(action).failures++;
72                          }
73                      } else {
74                          TransactionLogActionData t = new TransactionLogActionData();
75                          t.action = action;
76                          t.success = 0;
77                          t.failures = 0;
78                          if (res.getLogs().getTransactionLog().get(i).isIsFault()) {
79                              t.success++;
80                          } else {
81                              t.failures++;
82                          }
83                          set.add(t);
84                      }
85  
86                  }
87                  for (int i = 0; i < set.stuff.size(); i++) {
88                     // LogHelper.getLog().log(Level.WARNING,
89                     //         set.stuff.get(i).action + set.stuff.get(i).success + set.stuff.get(i).failures );
90                      if (set.stuff.get(i).success > 0) {
91                          data.addValue(set.stuff.get(i).success, set.stuff.get(i).action + " Success", set.stuff.get(i).action);
92                      }
93                      if (set.stuff.get(i).failures > 0) {
94                          data.addValue(set.stuff.get(i).failures, set.stuff.get(i).action + " Failures", set.stuff.get(i).action);
95                      }
96                  }
97              }
98              
99          } catch (Exception ex) {
100             LogHelper.getLog().log(Level.ERROR, "TransactionLogActionBreakDown produce chart data " + ex.getLocalizedMessage());
101         }
102         return data;
103     }
104 
105     public boolean hasExpired(Map params, Date since) {
106         return (System.currentTimeMillis() - since.getTime()) > 5000;
107     }
108 
109     public String getProducerId() {
110         return "fgsms.TransactionLogActionBreakDown";
111     }
112 }