Merge branch 'DAO'
[proteocache.git] / server / compbio / controllers / DailyStatisticsController.java
index a9b51f1..5d183f9 100644 (file)
@@ -11,12 +11,13 @@ 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.beans.DateBean;
+import compbio.beans.TotalJobsStatisticBean;
 import compbio.cassandra.DateFormatter;
-import compbio.cassandra.Total;
-import compbio.cassandra.TotalJobsStatisticBean;
-import compbio.statistic.CassandraRequester;
+
+import compbio.beans.Total;
+import compbio.cassandra.readers.CassandraReader;
+import compbio.cassandra.readers.DailyStatisticsReader;
 
 /**
  * @author Alexander Sherstnev
@@ -27,11 +28,13 @@ import compbio.statistic.CassandraRequester;
 public class DailyStatisticsController extends BasicController {
 
        /**
-        * form a query page for daily job statistics. The servlet should be
-        * available for users and admins only. By defaults the report time range is
-        * from the earliest day with jobs to today ("Query for all dates" is
-        * ticked). If the user removes the tick the time range is from today - 3
-        * days to today. Currently, the input model is empty.
+        * form a query page for daily job statistics.
+        * 
+        * The servlet should be available for users and admins only. By defaults
+        * the report time range is from the earliest day with jobs to current date
+        * ("Query for all dates" is ticked). If the user removes the tick the time
+        * range is from today - 3 days to today. Currently, the input model is
+        * empty.
         * 
         * @param model
         *            MVC model
@@ -71,7 +74,7 @@ public class DailyStatisticsController extends BasicController {
                model.put("username", getPrincipalName());
                Calendar loccal = Calendar.getInstance();
                final long startTime = System.currentTimeMillis();
-               CassandraRequester cr = new CassandraRequester();
+               DailyStatisticsReader reader = new DailyStatisticsReader();
                if (option.equals("AllDates,off")) {
                        date1 = theEaerlistDate;
                        date2 = theCurrentDate;
@@ -100,7 +103,7 @@ public class DailyStatisticsController extends BasicController {
                date2 = DateFormatter.DateLongToString(longDate2, formaterYYMMDD);
                model.put("date1", date1);
                model.put("date2", date2);
-               TotalJobsStatisticBean res = cr.countJobs(date1, date2);
+               TotalJobsStatisticBean res = reader.query(longDate1, longDate2);
                model.put("result", res);
                Map<String, Total> results = res.getDateTotal();
                String csvline = "\'Date\',\'Total\',\'OK\',\'Stopped\',\'Error\',\'Timeout\'%0A";
@@ -114,7 +117,7 @@ public class DailyStatisticsController extends BasicController {
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
                model.put("option", option);
-               return "/reportJobStatistics";
+               return "reports/JobStatistics";
        }
 
        /**
@@ -135,8 +138,9 @@ public class DailyStatisticsController extends BasicController {
                final long startTime = System.currentTimeMillis();
 
                String realdate;
+               long thetime = 0;
                try {
-                       long thetime = formaterYYMMDD.parse(date).getTime();
+                       thetime = formaterYYMMDD.parse(date).getTime();
                        if (thetime < 0) {
                                realdate = date;
                        } else {
@@ -144,15 +148,16 @@ public class DailyStatisticsController extends BasicController {
                        }
                } catch (ParseException e) {
                        realdate = date;
+                       thetime = formaterDDMMYY.parse(realdate).getTime();
                }
 
-               if (null == JobStatus.getJobStatus(status)) {
+               if (null == JobStatus.getJobStatus(status)) 
                        return "support/Notimplemented";
-               }
 
-               CassandraRequester cr = new CassandraRequester();
+
+               DailyStatisticsReader reader = new DailyStatisticsReader();
                // IMPORTANT: input should be suppied in the format: DD/MM/YYYY
-               DateBean r = cr.readJobByDay(realdate, JobStatus.getJobStatus(status));
+               DateBean r = reader.readJobByDay(thetime, realdate, JobStatus.getJobStatus(status));
                model.put("results", r);
                if (r != null)
                        model.put("njobs", r.getJobidAndSeq().size());
@@ -160,6 +165,6 @@ public class DailyStatisticsController extends BasicController {
                model.put("status", status);
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
-               return "/reportJobStatisticsOneDay";
+               return "reports/JobStatisticsOneDay";
        }
 }