Merge branch 'master' into servlets
authorSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Thu, 19 Dec 2013 12:42:04 +0000 (12:42 +0000)
committerSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Thu, 19 Dec 2013 12:42:04 +0000 (12:42 +0000)
Conflicts:
server/compbio/controllers/DailyStatisticsController.java
server/compbio/controllers/JobExecutionTimeController.java
server/compbio/controllers/SequenceController.java
server/compbio/listeners/ServletJobsByDate.java
server/compbio/listeners/ServletTimeExecution.java
server/compbio/statistic/CassandraRequester.java

datadb/compbio/cassandra/DataBase.java [deleted file]
server/compbio/controllers/DailyStatisticsController.java
server/compbio/listeners/ServletIp.java
server/compbio/listeners/ServletJobsByDate.java
server/compbio/listeners/ServletJobsByIp.java
server/compbio/listeners/ServletSequenceProtein.java
server/compbio/listeners/ServletTimeExecution.java
server/compbio/statistic/CassandraRequester.java

diff --git a/datadb/compbio/cassandra/DataBase.java b/datadb/compbio/cassandra/DataBase.java
deleted file mode 100644 (file)
index 57063ec..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-package compbio.cassandra;
-
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Collections;
-
-public class DataBase {
-       private String date;
-       private int total;                                      // total number of jobs
-       private int totalOK;                            // number of jobs with execution status OK
-       private int totalStopped;                        // number of jobs with execution status STOPPED
-       private int totalError;                         // number of jobs with execution status Jpred ERROR
-       private int totalTimeOut;                       // number of jobs with execution status TIMEOUT
-       private int totalJobs;
-       private int totalId;                            // total jobs for current protein sequence
-       private String id;
-       private String ip;
-       private String prot;                            // protein sequence
-       private String jpred;
-       private List<Integer> timeRez;
-       private List<Integer> timeTotalExec;
-       private JobBean logInfo;
-       private ProteinBean predictions;
-
-       public DataBase() {
-       }
-
-       public DataBase(String dat, int total) {
-               this.date = dat;
-               this.total = total;
-       }
-
-       public void setDate(String dat) {
-               this.date = dat;
-       }
-
-       public String getDate() {
-               if (null == date)
-                       return "1/1/1970";
-               return date;
-       }
-
-       public void setTotal(int tot) {
-               this.total = tot;
-       }
-
-       public int getTotal() {
-               return total;
-       }
-
-       public void setTotalOK(int tot) {
-               this.totalOK = tot;
-       }
-
-       public int getTotalOK() {
-               return totalOK;
-       }
-
-       public void setTotalStopped(int tot) {
-               this.totalStopped = tot;
-       }
-
-       public int getTotalStopped() {
-               return totalStopped;
-       }
-
-       public void setTotalError(int tot) {
-               this.totalError = tot;
-       }
-
-       public int getTotalError() {
-               return totalError;
-       }
-
-       public void setTotalTimeOut(int tot) {
-               this.totalTimeOut = tot;
-       }
-
-       public int getTotalTimeOut() {
-               return totalTimeOut;
-       }
-       
-       public void setTotalJobs(int totalJobs) {
-               this.totalJobs = totalJobs;
-       }
-
-       public int getTotalJobs() {
-               return totalJobs;
-       }
-
-       public void setTotalId(int totId) {
-               this.totalId = totId;
-       }
-
-       public int getTotalId() {
-               return totalId;
-       }
-
-       public void setProt(String prot) {
-               this.prot = prot;
-       }
-
-       public String getProt() {
-               return prot;
-       }
-
-       public void setJpred(String jpred) {
-               this.jpred = jpred;
-       }
-
-       public String getJpred() {
-               return jpred;
-       }
-
-       public void setId(String id) {
-               this.id = id;
-       }
-
-       public String getId() {
-               return id;
-       }
-       
-       public void setIp(String ip) {
-               this.ip = ip;
-       }
-
-       public String getIp() {
-               return ip;
-       }
-
-       public void setTimeRez(List<Integer> timeRez) {
-               this.timeRez = timeRez;
-       }
-
-       public List<Integer> getTimeRez() {
-               return timeRez;
-       }
-       
-       public void setTimeTotalExec(List<Integer> timeTotalExec) {
-               this.timeTotalExec = timeTotalExec;
-       }
-
-       public List<Integer> getTimeTotalExec() {
-               return timeTotalExec;
-       }
-       
-       public void setLogInfo(JobBean logInfo){
-               this.logInfo = logInfo;
-       }
-       
-       public JobBean getLogInfo() {
-               return logInfo;
-       }
-       
-       public void setPredictions(ProteinBean predictions){
-               this.predictions = predictions;
-       }
-       
-       public ProteinBean getPredictions() {
-               return predictions;
-       }
-
-}
index ef399f5..d6a0c1e 100644 (file)
@@ -12,12 +12,10 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
 import compbio.engine.JobStatus;
-import compbio.cassandra.CassandraReader;
 import compbio.cassandra.DateBean;
-import compbio.cassandra.DateFormatter;
 import compbio.cassandra.TotalJobsStatisticBean;
 import compbio.statistic.CassandraRequester;
-
+import compbio.statistic.StatisticsProt;
 
 /**
  * @author Alexander Sherstnev
@@ -25,20 +23,18 @@ import compbio.statistic.CassandraRequester;
  */
 @Controller
 public class DailyStatisticsController extends BasicController {
-       Calendar cal = Calendar.getInstance();
-       final SimpleDateFormat formaterDDMMYY = DateFormatter.getFormatDDMMYY();
-       final SimpleDateFormat formaterYYMMDD = DateFormatter.getFormatYYMMDD();
-       String theEaerlistDate = DateFormatter.DateLongToString(CassandraReader.earliestDate(), formaterYYMMDD);
-       String theCurrentDate = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
-       
+
        @RequestMapping(value = "/stat/jobs/query", method = RequestMethod.GET)
        public String initFindForm(Map<String, Object> model) {
                model.put("username", getPrincipalName());
+               Calendar cal = Calendar.getInstance();
                String date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE);
                cal.add(Calendar.DATE, -3);
                String date1 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE);
+
                model.put("date1", date1);
                model.put("date2", date2);
+
                return "query/JobStatistics";
        }
 
@@ -46,34 +42,14 @@ public class DailyStatisticsController extends BasicController {
        public String findJobsInPeriod(@RequestParam("date1") String date1, @RequestParam("date2") String date2,
                        @RequestParam("option") String option, Map<String, Object> model) {
                model.put("username", getPrincipalName());
-               final long startTime = System.currentTimeMillis();              
+               final long startTime = System.currentTimeMillis();
+
                CassandraRequester cr = new CassandraRequester();
                if (option.equals("AllDates,off")) {
-                       date1 = theEaerlistDate;
-                       date2 = theCurrentDate;
-               }
-       
-               // dates in string format
-               String trimmeddate1 = date1.replaceAll("\\s", "");
-               String trimmeddate2 = date2.replaceAll("\\s", "");
-               // dates in long format
-               long longDate1 = DateFormatter.DateParsing(date1,formaterYYMMDD);
-               long longDate2 = DateFormatter.DateParsing(date2, formaterYYMMDD);
-               String error = DateChecking(trimmeddate1, trimmeddate2, longDate1, longDate2);
-               if (error != null) {
-                       model.put("error", error);
-                       model.put("date1", date1);
-                       model.put("date2", date2);
-                       return "query/JobStatistics";
+                       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);
                }
-
-               if (longDate1 < CassandraReader.earliestDate())
-                       longDate1 = CassandraReader.earliestDate();
-               if (longDate2 > cal.getTimeInMillis())
-                       longDate2 =  cal.getTimeInMillis();     
-               
-               date1 = DateFormatter.DateLongToString(longDate1, formaterYYMMDD);
-               date2 = DateFormatter.DateLongToString(longDate2, formaterYYMMDD);
                model.put("date1", date1);
                model.put("date2", date2);
                TotalJobsStatisticBean res = cr.countJobs(date1, date2);
@@ -92,6 +68,8 @@ public class DailyStatisticsController extends BasicController {
                final long startTime = System.currentTimeMillis();
 
                String realdate;
+               final SimpleDateFormat formaterDDMMYY = new SimpleDateFormat("dd/MM/yyyy");
+               final SimpleDateFormat formaterYYMMDD = new SimpleDateFormat("yyyy/MM/dd");
                try {
                        long thetime = formaterYYMMDD.parse(date).getTime();
                        if (thetime < 0) {
@@ -119,20 +97,4 @@ public class DailyStatisticsController extends BasicController {
                model.put("timeExecution", (endTime - startTime));
                return "/reportJobStatisticsOneDay";
        }
-       
-       private String DateChecking(String trimmeddate1, String trimmeddate2, long longDate1, long longDate2) {
-               
-               if (trimmeddate1.equalsIgnoreCase("") || trimmeddate2.equalsIgnoreCase("")) 
-                       return "The date cann't be empty";
-               else if (!DateFormatter.isThisDateValid(trimmeddate1, formaterYYMMDD) || !DateFormatter.isThisDateValid(trimmeddate2, formaterYYMMDD)) 
-                       return "The date format in invalid. Try format yyyy/mm/dd";
-               else if (longDate2 < CassandraReader.earliestDate()) 
-                       return "The date2 is after the earlestDate " + theEaerlistDate;
-               else if (longDate1 > cal.getTimeInMillis())
-                       return "The date1 is before the current date " + theCurrentDate;                        
-               else if (longDate1 > longDate2)         
-                       return "Wrong date's diaposon. The date1 is more than date2.";
-               else                    
-                       return null;
-       }
 }
index e229176..76c59ff 100644 (file)
@@ -9,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.CassandraRequester;
 
 /**
index fe24750..8ae389f 100644 (file)
@@ -1,9 +1,7 @@
 package compbio.listeners;
 
 import java.io.IOException;
-import java.text.SimpleDateFormat;
 import java.util.Calendar;
-import java.util.Date;
 import java.util.List;
 
 import javax.servlet.RequestDispatcher;
@@ -15,6 +13,7 @@ import javax.servlet.http.HttpServletResponse;
 
 import compbio.cassandra.DataBase;
 import compbio.statistic.CassandraRequester;
+import compbio.statistic.StatisticsProt;
 
 @WebServlet("/ServletJobsByDate")
 public class ServletJobsByDate extends HttpServlet {
@@ -31,7 +30,7 @@ public class ServletJobsByDate extends HttpServlet {
                CassandraRequester cr = new CassandraRequester();
                if (null != request.getParameter("option")) {
                        Calendar cal = Calendar.getInstance();
-                       date1 = DateFormatYYMMDD(cr.earliestDate());
+                       date1 = StatisticsProt.DateFormatYYMMDD(cr.earliestDate());
                        date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
                }
                request.setAttribute("data1", date1);
@@ -50,10 +49,4 @@ public class ServletJobsByDate extends HttpServlet {
                doGet(request, response);
        }
 
-       private String DateFormatYYMMDD(long indate) {
-               SimpleDateFormat datformat = new SimpleDateFormat("yyyy/MM/dd");
-               String dateString = datformat.format(new Date(indate));
-               return dateString;
-       }
-       
 }
index bff4a5c..d50ff71 100644 (file)
@@ -9,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.CassandraRequester;
 
 /**
index b631bff..8b75770 100644 (file)
@@ -10,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.CassandraRequester;
 
 /**
index 93b3faf..c380604 100644 (file)
@@ -1,9 +1,7 @@
 package compbio.listeners;
 
 import java.io.IOException;
-import java.text.SimpleDateFormat;
 import java.util.Calendar;
-import java.util.Date;
 
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletException;
@@ -12,6 +10,7 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import compbio.statistic.StatisticsProt;
 import compbio.statistic.CassandraRequester;
 
 /**
@@ -32,7 +31,7 @@ public class ServletTimeExecution extends HttpServlet {
                CassandraRequester sp = new CassandraRequester();
                if (null != request.getParameter("option")) {
                        Calendar cal = Calendar.getInstance();
-                       date1 = DateFormatYYMMDD(sp.earliestDate());
+                       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);
@@ -52,10 +51,4 @@ public class ServletTimeExecution extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                doGet(request, response);
        }
-
-       private String DateFormatYYMMDD(long indate) {
-               SimpleDateFormat datformat = new SimpleDateFormat("yyyy/MM/dd");
-               String dateString = datformat.format(new Date(indate));
-               return dateString;
-       }
 }
index 3e5db8a..f2336e7 100755 (executable)
@@ -12,7 +12,7 @@ import java.util.Map;
 import compbio.cassandra.DateBean;
 import compbio.cassandra.ProteinBean;
 import compbio.cassandra.CassandraNativeConnector;
-import compbio.cassandra.CassandraReaderOld;
+import compbio.cassandra.CassandraReader;
 import compbio.cassandra.DataBase;
 import compbio.cassandra.Pair;
 import compbio.cassandra.JobBean;
@@ -23,7 +23,7 @@ import compbio.cassandra.UserBean;
 import compbio.engine.JobStatus;
 
 public class CassandraRequester {
-       private CassandraReaderOld db = new CassandraReaderOld();
+       private CassandraReader db = new CassandraReader();
        private ArrayList<DataBase> query;
        private static long currentDate = 0;
        private static long earlestDate = 0;
@@ -122,7 +122,7 @@ public class CassandraRequester {
         * query: total number of jobs for the period from date1 till date2
         */
        public TotalJobsStatisticBean countJobs(String date1, String date2) {
-       /*      if (null == date1) {
+               if (null == date1) {
                        date1 = "1970/1/1";
                }
                if (null == date2) {
@@ -131,16 +131,17 @@ public class CassandraRequester {
                if (!isThisDateValid(date1, formatYYMMDD) || !isThisDateValid(date2, formatYYMMDD)) {
                        System.out.println("CassandraRequester.countJobs: wrong format for date1 " + date1 + "or date2 " + date2);
                        return null;
-               }*/
+               }
                SetDateRange();
                long dateStart = DateParsing(date1, formatYYMMDD);
                long dateEnd = DateParsing(date2, formatYYMMDD);
-/*             if (dateEnd < earlestDate || dateStart > currentDate || dateStart > dateEnd)
+               if (dateEnd < earlestDate || dateStart > currentDate || dateStart > dateEnd)
                        return null;
                if (dateStart < earlestDate)
                        dateStart = earlestDate;
                if (dateEnd > currentDate)
-                       dateStart = currentDate;*/
+                       dateStart = currentDate;
+
                Calendar start = Calendar.getInstance();
                start.setTime(new Date(dateStart));
                Calendar end = Calendar.getInstance();