Add basic security jars to the project
[proteocache.git] / server / compbio / controllers / DailyStatisticsController.java
index fd7a0db..c9df6be 100644 (file)
@@ -26,6 +26,14 @@ public class DailyStatisticsController {
 
        @RequestMapping(value = "/stat", method = RequestMethod.GET)
        public String initFindForm(Map<String, Object> model) {
+               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 "queryJobStatistics";
        }
 
@@ -40,13 +48,14 @@ public class DailyStatisticsController {
                        date1 = StatisticsProt.DateFormatYYMMDD(cr.earliestDate());
                        date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
                }
-               model.put("data1", date1);
-               model.put("data2", date2);
+               model.put("date1", date1);
+               model.put("date2", date2);
                List<DataBase> res = cr.countJobs(date1, date2);
                model.put("result", res);
+               model.put("ndays", res.size());
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
-               model.put("flag", option);
+               model.put("option", option);
                return "/reportJobStatistics";
        }
        
@@ -54,19 +63,28 @@ public class DailyStatisticsController {
        public String findJobsInOneDay(@RequestParam("date") String date, Map<String, Object> model) throws ParseException {
                final long startTime = System.currentTimeMillis();
 
+               String realdate;
                final SimpleDateFormat formaterDDMMYY = new SimpleDateFormat("dd/MM/yyyy");
                final SimpleDateFormat formaterYYMMDD = new SimpleDateFormat("yyyy/MM/dd");
-               String date1 = formaterYYMMDD.format(new Date(formaterDDMMYY.parse(date).getTime()));
-       
+               try {
+                       long thetime = formaterYYMMDD.parse(date).getTime();
+                       if (thetime < 0) {
+                               realdate = date;
+                       } else {
+                               realdate = formaterDDMMYY.format(new Date(thetime));
+                       }
+               } catch (ParseException e) {
+                       realdate = date;
+               }
+
                CassandraRequester cr = new CassandraRequester();
-               //List<DataBase> r1 = cr.countJobs(date1, date1);
-               List<DataBase> r = cr.readJobByDay(date);
+               // IMPORTANT: input should be suppied in the format: DD/MM/YYYY
+               List<DataBase> r = cr.readJobByDay(realdate);
                model.put("results", r);
                model.put("njobs", r.size());
-               model.put("date", date1);
+               model.put("date", realdate);
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
-               System.out.println("Request for date = " + date1 + ": " + r.size() + " jobs found");
                return "/reportJobStatisticsOneDay";
        }
 }