Convert servlets into Spring controllers
authorSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Fri, 29 Nov 2013 12:16:00 +0000 (12:16 +0000)
committerSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Fri, 29 Nov 2013 12:16:00 +0000 (12:16 +0000)
server/compbio/controllers/DBUpdateController.java [new file with mode: 0644]
server/compbio/controllers/DayStatisticsController.java
server/compbio/controllers/HelpController.java [new file with mode: 0644]
server/compbio/controllers/JobExecutionTimeController.java
server/compbio/controllers/JobLogController.java
server/compbio/controllers/SequenceSearchController.java

diff --git a/server/compbio/controllers/DBUpdateController.java b/server/compbio/controllers/DBUpdateController.java
new file mode 100644 (file)
index 0000000..1d84026
--- /dev/null
@@ -0,0 +1,65 @@
+package compbio.controllers;
+
+import java.util.Map;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import compbio.cassandra.CassandraRemover;
+
+/**
+ * @author Alexander Sherstnev
+ * @author Natasha Sherstneva
+ */
+@Controller
+public class DBUpdateController {
+
+       @RequestMapping(value = "/database/remove", method = RequestMethod.GET)
+       public String initRemoveForm(Map<String, Object> model) {
+               return "queryRemoveJobs";
+       }
+
+       @RequestMapping(value = "/database/state", method = RequestMethod.GET)
+       public String initDBStatRequest(Map<String, Object> model) {
+               // return "queryDBState";
+               return "support/Notimplemented";
+       }
+
+       @RequestMapping(value = "/database/remove/goreal", method = RequestMethod.GET)
+       public String findIPwithCounter(@RequestParam("byId") String flagId, @RequestParam("id") String jobId,
+                       @RequestParam("byDate") String flagDate, @RequestParam("date1") String date1, @RequestParam("date2") String date2,
+                       @RequestParam("byIp") String flagIp, @RequestParam("ip") String ip, @RequestParam("bySequence") String flagSeq,
+                       @RequestParam("seq") String seq, Map<String, Object> model) {
+
+               CassandraRemover cr = new CassandraRemover();
+               int numberRemover = 0;
+               if (flagId != null)
+                       numberRemover = cr.RemoveJobById(jobId);
+               if (flagDate != null)
+                       numberRemover = cr.RemoveJobByDate(date1, date2);
+               if (flagIp != null)
+                       numberRemover = cr.RemoveJobByIp(ip);
+               if (flagSeq != null)
+                       numberRemover = cr.RemoveJobBySequence(seq);
+               model.put("result", numberRemover);
+               return "reportRemoveData";
+       }
+
+       @RequestMapping(value = "/database/remove/go", method = RequestMethod.GET)
+       public String findIPwithCounter(@RequestParam("id") String jobId, @RequestParam("date1") String date1,
+                       @RequestParam("date2") String date2, @RequestParam("ip") String ip, @RequestParam("seq") String seq, Map<String, Object> model) {
+
+               /*
+                * CassandraRemover cr = new CassandraRemover(); int numberRemover = 0;
+                * if (flagId != null) numberRemover = cr.RemoveJobById(jobId); if
+                * (flagDate != null) numberRemover = cr.RemoveJobByDate(date1, date2);
+                * if (flagIp != null) numberRemover = cr.RemoveJobByIp(ip); if (flagSeq
+                * != null) numberRemover = cr.RemoveJobBySequence(seq);
+                * model.put("result", numberRemover); return "reportRemoveData";
+                */
+               return "support/Blocked";
+       }
+
+}
index da4538d..206a6df 100644 (file)
@@ -7,13 +7,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.WebDataBinder;
-import org.springframework.web.bind.annotation.InitBinder;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -32,16 +26,16 @@ public class DayStatisticsController {
 
        @RequestMapping(value = "/stat", method = RequestMethod.GET)
        public String initFindForm(Map<String, Object> model) {
-               return "QueryJobsByDate";
+               return "queryJobStatistics";
        }
 
        @RequestMapping(value = "/stat/query", method = RequestMethod.GET)
-       public String findJobsInPeriod(@RequestParam("data1") String date1, @RequestParam("data2") String date2,
+       public String findJobsInPeriod(@RequestParam("date1") String date1, @RequestParam("date2") String date2,
                        @RequestParam("option") String option, Map<String, Object> model) {
                final long startTime = System.currentTimeMillis();
 
                CassandraRequester cr = new CassandraRequester();
-               if (option.equals("AllDates")) {
+               if (option.equals("AllDates,off")) {
                        Calendar cal = Calendar.getInstance();
                        date1 = StatisticsProt.DateFormatYYMMDD(cr.earliestDate());
                        date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
@@ -53,7 +47,7 @@ public class DayStatisticsController {
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
                model.put("flag", option);
-               return "/ReportJobsByDate";
+               return "/reportJobStatistics";
        }
        
        @RequestMapping(value = "/stat/oneday", method = RequestMethod.GET)
@@ -65,7 +59,7 @@ public class DayStatisticsController {
                String date1 = formaterYYMMDD.format(new Date(formaterDDMMYY.parse(date).getTime()));
        
                CassandraRequester cr = new CassandraRequester();
-               List<DataBase> r1 = cr.countJobs(date1, date1);
+               //List<DataBase> r1 = cr.countJobs(date1, date1);
                List<DataBase> r = cr.readJobByDay(date);
                model.put("results", r);
                model.put("njobs", r.size());
@@ -73,6 +67,6 @@ public class DayStatisticsController {
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
                System.out.println("Request for date = " + date1 + ": " + r.size() + " jobs found");
-               return "/ReportJobsOfOneDay";
+               return "/reportJobStatisticsOneDay";
        }
 }
diff --git a/server/compbio/controllers/HelpController.java b/server/compbio/controllers/HelpController.java
new file mode 100644 (file)
index 0000000..cd16fff
--- /dev/null
@@ -0,0 +1,38 @@
+package compbio.controllers;
+
+import java.util.Map;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+//import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * @author Alexander Sherstnev
+ * @author Natasha Sherstneva
+ */
+@Controller
+public class HelpController {
+
+       @RequestMapping(value = "/help/overview", method = RequestMethod.GET)
+       public String formOverviewPage(Map<String, Object> model) {
+               return "help/Overview";
+       }
+
+       @RequestMapping(value = "/help/howto", method = RequestMethod.GET)
+       public String formHowtoPage(Map<String, Object> model) {
+               return "support/Notimplemented";
+       }
+
+
+       @RequestMapping(value = "/help/doc", method = RequestMethod.GET)
+       public String formDocPage(Map<String, Object> model) {
+               return "support/Notimplemented";
+       }
+       
+
+       @RequestMapping(value = "/help/javadoc", method = RequestMethod.GET)
+       public String formJavadoc(Map<String, Object> model) {
+               return "support/Notimplemented";
+       }
+}
index feee0dd..0917bde 100644 (file)
@@ -3,19 +3,11 @@ package compbio.controllers;
 import java.util.Calendar;
 import java.util.Map;
 
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.WebDataBinder;
-import org.springframework.web.bind.annotation.InitBinder;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
-
-import compbio.cassandra.DataBase;
 import compbio.statistic.CassandraRequester;
 import compbio.statistic.StatisticsProt;
 
@@ -28,7 +20,7 @@ public class JobExecutionTimeController {
 
        @RequestMapping(value = "/exectime", method = RequestMethod.GET)
        public String initFindForm(Map<String, Object> model) {
-               return "QueryTimeExecution";
+               return "queryTimeExecution";
        }
 
        @RequestMapping(value = "/exectime/query", method = RequestMethod.GET)
@@ -48,6 +40,6 @@ public class JobExecutionTimeController {
                model.put("flag", option);
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
-               return "/ReportTimeExecution";
+               return "/reportTimeExecution";
        }
 }
index 874e046..e207e4e 100644 (file)
@@ -18,7 +18,7 @@ public class JobLogController {
 
        @RequestMapping(value = "/joblog", method = RequestMethod.GET)
        public String initFindForm(Map<String, Object> model) {
-               return "QueryJobLog";
+               return "queryJobLog";
        }
 
        @RequestMapping(value = "/joblog/query", method = RequestMethod.GET)
@@ -29,6 +29,6 @@ public class JobLogController {
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
                model.put("IdJob", jobid);
-               return "ReportJobLog";
+               return "reportJobLog";
        }
 }
index a1642ee..53bfcfc 100644 (file)
@@ -1,17 +1,9 @@
-
 package compbio.controllers;
 
-
 import java.util.List;
 import java.util.Map;
 
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.WebDataBinder;
-import org.springframework.web.bind.annotation.InitBinder;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -27,34 +19,54 @@ import compbio.statistic.CassandraRequester;
 @Controller
 public class SequenceSearchController {
 
-       @RequestMapping(value = "/sequence", method = RequestMethod.GET)
-       public String initFindForm(Map<String, Object> model) {
-               return "QuerySequenceProtein";
+       @RequestMapping(value = "/sequence/query1", method = RequestMethod.GET)
+       public String formSequenceQuery(Map<String, Object> model) {
+               return "queryProteinSequence";
        }
 
-       @RequestMapping(value = "/sequence/query", method = RequestMethod.GET)
-       public String findSequence(@RequestParam("prot") String prot, @RequestParam("protein") String flag,
-                       @RequestParam("Search") String search, @RequestParam("counterJob") int counter, Map<String, Object> model) {
+       @RequestMapping(value = "/sequence/query2", method = RequestMethod.GET)
+       public String formCounterQuery(Map<String, Object> model) {
+               return "queryProteinSequenceCounter";
+       }
+       
+       @RequestMapping(value = "/sequence/querysequence", method = RequestMethod.GET)
+       public String findSequence(@RequestParam("sequence") String sequence, @RequestParam("protein") String flag, Map<String, Object> model) {
                final long startTime = System.currentTimeMillis();
-               CassandraRequester cr = new CassandraRequester();
-               if (search.equals("SearchCounter")) {
-                       List<DataBase> r = cr.readProteinByCounter(counter);
-                       model.put("results", r);
-                       model.put("njobs", r.size());
-                       System.out.println("Search counter = " + counter + ": " + r.size() + " proteins found");
-               } else {
-                       List<DataBase> r = cr.readProteins(prot, flag);
+
+               String trimmedsequence = sequence.replaceAll("\\s", "");
+               model.put("njobs", 0);
+               model.put("prot", trimmedsequence);
+               model.put("flag", flag);
+
+               if (0 < trimmedsequence.length()) {
+                       CassandraRequester cr = new CassandraRequester();
+                       List<DataBase> r = cr.readProteins(trimmedsequence, flag);
                        model.put("results", r);
+                       if (null != r) {
+                               System.out.println("result size = " + r.size());
+                               model.put("njobs", r.size());
+                       }
+               }
+               final long endTime = System.currentTimeMillis();
+               model.put("timeExecution", (endTime - startTime));
+               return "reportProteinSequences";
+       }
+
+       @RequestMapping(value = "/sequence/querycounter", method = RequestMethod.GET)
+       public String countSequences(@RequestParam("counterJob") int counter, Map<String, Object> model) {
+               final long startTime = System.currentTimeMillis();
+
+               CassandraRequester cr = new CassandraRequester();
+               List<DataBase> r = cr.readProteinByCounter(counter);
+               model.put("results", r);
+               model.put("njobs", 0);
+               if (null != r) {
                        model.put("njobs", r.size());
-                       //System.out.println("Search sequence: " + r.size() + " proteins found");
                }
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
-               model.put("prot", prot);
-               model.put("flag", flag);
-               model.put("search", search);
                model.put("counter", counter);
-               return "ReportSequenceProtein";
+               return "reportProteinSequencesCounter";
        }
 
 }