+/* Copyright (c) 2011 Peter Troshin\r
+ * \r
+ * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0 \r
+ * \r
+ * This library is free software; you can redistribute it and/or modify it under the terms of the\r
+ * Apache License version 2 as published by the Apache Software Foundation\r
+ * \r
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
+ * License for more details.\r
+ * \r
+ * A copy of the license is in apache_license.txt. It is also available here:\r
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
+ * \r
+ * Any republication or derived work distributed in source code form\r
+ * must include this copyright and license notice.\r
+ */\r
package compbio.stat.servlet;\r
\r
import java.io.IOException;\r
import java.sql.SQLException;\r
-import java.sql.Timestamp;\r
import java.util.Calendar;\r
import java.util.Date;\r
-import java.util.Map;\r
-import java.util.TreeMap;\r
+import java.util.GregorianCalendar;\r
\r
import javax.servlet.RequestDispatcher;\r
import javax.servlet.ServletException;\r
import javax.servlet.http.HttpServletRequest;\r
import javax.servlet.http.HttpServletResponse;\r
\r
-import compbio.stat.collector.StatDB;\r
-import compbio.stat.collector.StatProcessor;\r
-import compbio.ws.client.Services;\r
+import org.apache.log4j.Logger;\r
+\r
+import compbio.stat.servlet.util.StatCollection;\r
+import compbio.stat.servlet.util.Totals;\r
\r
public class DisplayStat extends HttpServlet {\r
\r
+ private final static Logger log = Logger.getLogger(DisplayStat.class);\r
+\r
@Override\r
protected void doGet(HttpServletRequest req, HttpServletResponse resp)\r
throws ServletException, IOException {\r
- // TODO\r
- Calendar startTime = Calendar.getInstance();\r
- startTime.roll(Calendar.YEAR, false);\r
- Timestamp startDate = new Timestamp(startTime.getTimeInMillis());\r
- Timestamp stopDate = new Timestamp(new Date().getTime());\r
- StatDB statdb = null;\r
- try {\r
- statdb = new StatDB();\r
+ String datetime = req.getParameter("datetime");\r
\r
- Map<Services, StatProcessor> stats = new TreeMap<Services, StatProcessor>();\r
- for (Services service : Services.values()) {\r
- stats.put(\r
- service,\r
- new StatProcessor(statdb.readData(startDate, stopDate,\r
- service, null)));\r
- }\r
+ Date fromDate = new Date(Long.parseLong(datetime));\r
+ Calendar toCal = GregorianCalendar.getInstance();\r
+ toCal.setTime(fromDate);\r
+ toCal.add(Calendar.MONTH, 1);\r
\r
- Map<Services, StatProcessor> statsCluster = new TreeMap<Services, StatProcessor>();\r
- for (Services service : Services.values()) {\r
- statsCluster.put(\r
- service,\r
- new StatProcessor(statdb.readData(startDate, stopDate,\r
- service, true)));\r
- }\r
+ try {\r
+ StatCollection stats = StatCollection.newStatCollecton(fromDate,\r
+ toCal.getTime());\r
\r
- Map<Services, StatProcessor> statsLocal = new TreeMap<Services, StatProcessor>();\r
- for (Services service : Services.values()) {\r
- statsLocal.put(\r
- service,\r
- new StatProcessor(statdb.readData(startDate, stopDate,\r
- service, false)));\r
- }\r
+ log.trace("Stats: " + stats);\r
req.setAttribute("stat", stats);\r
- req.setAttribute("statTotal", Totals.sumStats(stats));\r
-\r
- req.setAttribute("statCluster", statsCluster);\r
- req.setAttribute("statLocal", statsLocal);\r
- req.setAttribute("startDate", startDate.getTime());\r
- req.setAttribute("stopDate", stopDate.getTime());\r
+ req.setAttribute("statTotal", Totals.sumStats(stats.getAllStat()));\r
+ req.setAttribute("statTotalCluster",\r
+ Totals.sumStats(stats.getClusterStat()));\r
+ req.setAttribute("statTotalLocal",\r
+ Totals.sumStats(stats.getLocalStat()));\r
\r
+ req.setAttribute("startDate", fromDate);\r
+ req.setAttribute("stopDate", toCal.getTime());\r
+ log.trace("from " + fromDate + " to " + toCal.getTime());\r
RequestDispatcher dispatcher = req\r
.getRequestDispatcher("statpages/Statistics.jsp");\r
dispatcher.forward(req, resp);\r
\r
} catch (SQLException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ log.error(e.getMessage(), e);\r
+ throw new ServletException(e);\r
}\r
\r
}\r
-\r
}\r