+/* 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.io.PrintWriter;\r
import java.sql.SQLException;\r
import java.util.Date;\r
import java.util.Map;\r
+import java.util.Calendar;\r
+import java.text.SimpleDateFormat;\r
\r
import javax.servlet.RequestDispatcher;\r
import javax.servlet.ServletException;\r
throws ServletException, IOException {\r
\r
try {\r
+ long startTime = System.nanoTime();\r
StatDB db = new StatDB();\r
Date earliestRec = db.getEarliestRecord();\r
- Map<Date, Totals> monthlyTotals = StatCollection\r
- .getStats(earliestRec);\r
+ if (earliestRec == null) {\r
+ PrintWriter writer = resp.getWriter();\r
+ writer.println("No statistics found in the database. Please allow "\r
+ + "at least one hour after a server start for the statistics "\r
+ + "collector to collect the data. ");\r
+ writer.close();\r
+ return;\r
+ }\r
+ Map<Date, Totals> monthlyTotals = StatCollection.getStats(earliestRec);\r
+ long endTime = System.nanoTime();\r
req.setAttribute("stat", monthlyTotals);\r
req.setAttribute("total", Totals.sumOfTotals(monthlyTotals));\r
+// req.setAttribute("timeexec", (endTime - startTime) / 1000000);\r
+ req.setAttribute("timeexec", (endTime - startTime) / 100000000);\r
+ String timeStamp = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(\r
+ Calendar.getInstance().getTime());\r
+ req.setAttribute("timestamp", timeStamp);\r
\r
- RequestDispatcher dispatcher = req\r
- .getRequestDispatcher("statpages/MonthlySummary.jsp");\r
+ RequestDispatcher dispatcher = req.getRequestDispatcher("statpages/MonthlySummary.jsp");\r
+\r
+ req.setAttribute("isAdmin", isAdmin(req));\r
dispatcher.forward(req, resp);\r
\r
} catch (SQLException e) {\r
- // TODO Auto-generated catch block\r
e.printStackTrace();\r
+ throw new ServletException(e);\r
}\r
}\r
\r
+ static boolean isAdmin(final HttpServletRequest request) {\r
+ return request.isUserInRole("admin");\r
+ }\r
+\r
}\r