+/* 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.text.DateFormat;\r
-import java.text.ParseException;\r
-import java.text.SimpleDateFormat;\r
import java.util.Calendar;\r
import java.util.Date;\r
import java.util.GregorianCalendar;\r
-import java.util.Map;\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 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
- String month = req.getParameter("month");\r
- System.out.println("? " + month);\r
- DateFormat df = SimpleDateFormat.getInstance();\r
+ String datetime = req.getParameter("datetime");\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
try {\r
- Date fromDate = df.parse(month);\r
- Map<Date, StatCollection> statsMap = StatCollection\r
- .getStats(fromDate);\r
- assert statsMap.size() == 1;\r
- StatCollection stats = statsMap.values().iterator().next();\r
- req.setAttribute("stat", stats.getAllStat());\r
+ StatCollection stats = StatCollection.newStatCollecton(fromDate,\r
+ toCal.getTime());\r
+\r
+ log.trace("Stats: " + stats);\r
+ req.setAttribute("stat", stats);\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.getTime());\r
- Calendar c = GregorianCalendar.getInstance();\r
- c.setTime(fromDate);\r
- c.add(Calendar.MONTH, 1);\r
- req.setAttribute("stopDate", c.getTime());\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
- } catch (ParseException 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