Commit cb309ccf authored by Michael Ritter's avatar Michael Ritter
Browse files

Differentiate on GET/POST methods for the stats servlet

parent 34f9c264
package edu.umiacs.ace.stats;
import edu.umiacs.ace.util.EntityManagerServlet;
import org.apache.log4j.Logger;
import javax.persistence.EntityManager;
import javax.servlet.RequestDispatcher;
......@@ -17,22 +18,42 @@ import java.util.List;
* Created by shake on 8/30/16.
*/
public class StatisticsServlet extends EntityManagerServlet {
private static final Object[] HEADER = {"date", "collection", "group", "total_count", "size"};
private static final Logger LOG = Logger.getLogger(StatisticsServlet.class);
// General infos
private static final String GET = "GET";
private static final String SERVLET = "statistics.jsp";
// Query params
private static final String AFTER = "after";
private static final String BEFORE = "before";
private static final String GROUP = "group";
private static final String COLLECTION = "collection";
private static final String CSV = "csv";
@Override
protected void processRequest(HttpServletRequest request, HttpServletResponse response, EntityManager em) throws ServletException, IOException {
// Differentiate on the request method
// GET - no query, just forward
// POST - query/csv handling
if (GET.equals(request.getMethod())) {
processGet(request, response);
} else {
processPost(request, response, em);
}
}
private void processGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher dispatcher = request.getRequestDispatcher(SERVLET);
dispatcher.forward(request, response);
}
private void processPost(HttpServletRequest request, HttpServletResponse response, EntityManager em) throws ServletException, IOException {
String csv = getParameter(request, CSV, null);
String group = getParameter(request, GROUP, null);
String after = getParameter(request, AFTER, null);
String before = getParameter(request, BEFORE, null);
String group = getParameter(request, GROUP, null);
String collection = getParameter(request, COLLECTION, null);
String csv = getParameter(request, CSV, null);
SummaryQuery q = new SummaryQuery(group, after, before, collection);
......@@ -42,7 +63,7 @@ public class StatisticsServlet extends EntityManagerServlet {
List<IngestSummary> summary = q.getSummary();
request.setAttribute("summary", summary);
RequestDispatcher dispatcher = request.getRequestDispatcher("statistics.jsp");
RequestDispatcher dispatcher = request.getRequestDispatcher(SERVLET);
dispatcher.forward(request, response);
} else {
try {
......@@ -51,8 +72,9 @@ public class StatisticsServlet extends EntityManagerServlet {
response.setHeader("Content-Disposition", "attachment; filename=ingest-summary.csv");
q.writeToCsv(response.getOutputStream());
} catch (SQLException e) {
e.printStackTrace();
LOG.error("Error with statistics query", e);
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment