From: Sasha Sherstnev Date: Mon, 28 Oct 2013 20:20:47 +0000 (+0000) Subject: Simplify servlets X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=90f45024fc690682aea7a5f9d5ae49714b5b6130;p=proteocache.git Simplify servlets --- diff --git a/server/compbio/listeners/LengthServlet.java b/server/compbio/listeners/LengthServlet.java index c87a34d..533e6e1 100644 --- a/server/compbio/listeners/LengthServlet.java +++ b/server/compbio/listeners/LengthServlet.java @@ -2,7 +2,6 @@ package compbio.listeners; import java.io.IOException; import java.util.Calendar; -import java.util.List; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; @@ -11,7 +10,6 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import compbio.cassandra.DataBase; import compbio.statistic.StatisticsProt; /** @@ -25,29 +23,20 @@ public class LengthServlet extends HttpServlet { * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response) */ - protected void doGet(HttpServletRequest request, - HttpServletResponse response) throws ServletException, IOException { - List result; - String flag = request.getParameter("option"); + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String date1 = request.getParameter("data1"); String date2 = request.getParameter("data2"); StatisticsProt sp = new StatisticsProt(); - if (flag == null) - result = sp.readLength(date1, date2); - else { + if (null != request.getParameter("option")) { Calendar cal = Calendar.getInstance(); - String dateB = StatisticsProt.DateFormatYYMMDD(sp.earliestDate()); - String dateEnd = cal.get(Calendar.YEAR) + "/" - + (cal.get(Calendar.MONTH) + 1) + "/" - + cal.get(Calendar.DAY_OF_MONTH); - result = sp.readLength(dateB, dateEnd); + date1 = StatisticsProt.DateFormatYYMMDD(sp.earliestDate()); + date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH); } request.setAttribute("data1", date1); request.setAttribute("data2", date2); - request.setAttribute("result", result); - request.setAttribute("flag", flag); - RequestDispatcher rd = request - .getRequestDispatcher("/ReportLength.jsp"); + request.setAttribute("result", sp.readLength(date1, date2)); + request.setAttribute("flag", request.getParameter("option")); + RequestDispatcher rd = request.getRequestDispatcher("/ReportLength.jsp"); rd.forward(request, response); } @@ -55,8 +44,7 @@ public class LengthServlet extends HttpServlet { * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response) */ - protected void doPost(HttpServletRequest request, - HttpServletResponse response) throws ServletException, IOException { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } } diff --git a/server/compbio/listeners/ProtServlet.java b/server/compbio/listeners/ProtServlet.java index 8ed2d2f..cb74ecc 100644 --- a/server/compbio/listeners/ProtServlet.java +++ b/server/compbio/listeners/ProtServlet.java @@ -1,7 +1,6 @@ package compbio.listeners; import java.io.IOException; -import java.util.List; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; @@ -10,7 +9,6 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import compbio.cassandra.DataBase; import compbio.statistic.StatisticsProt; /** @@ -24,25 +22,22 @@ public class ProtServlet extends HttpServlet { * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response) */ - protected void doGet(HttpServletRequest request, - HttpServletResponse response) throws ServletException, IOException { - List result; + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String flag = request.getParameter("protein"); String prot = request.getParameter("prot"); String checkbox = request.getParameter("option"); StatisticsProt sp = new StatisticsProt(); if (checkbox != null) { - result = sp.readProtID(); + request.setAttribute("result", sp.readProtID()); } else { if (flag.equals("whole")) - result = sp.readProt(prot); + request.setAttribute("result", sp.readProteins(prot)); else - result = sp.readPart(prot); + request.setAttribute("result", sp.readPart(prot)); } request.setAttribute("prot", prot); request.setAttribute("flag", flag); request.setAttribute("checkbox", checkbox); - request.setAttribute("result", result); RequestDispatcher rd = request.getRequestDispatcher("/ReportProt.jsp"); rd.forward(request, response); } @@ -51,8 +46,7 @@ public class ProtServlet extends HttpServlet { * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response) */ - protected void doPost(HttpServletRequest request, - HttpServletResponse response) throws ServletException, IOException { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } diff --git a/server/compbio/listeners/QueryServlet.java b/server/compbio/listeners/QueryServlet.java index 1241b60..196decb 100644 --- a/server/compbio/listeners/QueryServlet.java +++ b/server/compbio/listeners/QueryServlet.java @@ -11,7 +11,7 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import compbio.cassandra.*; +import compbio.cassandra.DataBase; import compbio.statistic.StatisticsProt; @WebServlet("/QueryServlet") @@ -23,23 +23,20 @@ public class QueryServlet extends HttpServlet { * response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - List result; - String flag = request.getParameter("option"); String date1 = request.getParameter("data1"); String date2 = request.getParameter("data2"); StatisticsProt sp = new StatisticsProt(); - if (flag == null) - result = sp.readDetail(date1, date2); - else { + if (null != request.getParameter("option")) { Calendar cal = Calendar.getInstance(); - String dateB = StatisticsProt.DateFormatYYMMDD(sp.earliestDate()); - String dateEnd = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH); - result = sp.readDetail(dateB, dateEnd); + date1 = StatisticsProt.DateFormatYYMMDD(sp.earliestDate()); + date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH); } request.setAttribute("data1", date1); request.setAttribute("data2", date2); - request.setAttribute("result", result); - request.setAttribute("flag", flag); + List res = sp.readDetails(date1, date2); + request.setAttribute("result", res); + System.out.println ("QueryServlet.doGet: total number of dates = " + res.size()); + request.setAttribute("flag", request.getParameter("option")); RequestDispatcher rd = request.getRequestDispatcher("/ReportNew.jsp"); rd.forward(request, response); }