1 package compbio.controllers;
3 import java.util.Calendar;
5 import org.springframework.stereotype.Controller;
6 import org.springframework.ui.ModelMap;
7 import org.springframework.web.bind.annotation.RequestMapping;
8 import org.springframework.web.bind.annotation.RequestMethod;
10 import compbio.beans.Total;
11 import compbio.beans.TotalJobsStatisticBean;
12 import compbio.cassandra.DateFormatter;
13 import compbio.cassandra.readers.DailyStatisticsReader;
16 * The main system controller with most general functionality (home page, login
19 * @author Alexander Sherstnev
20 * @author Natasha Sherstneva
26 public class MainController extends BasicController {
29 * Form the project home page
34 * @return JSP template for the page
36 @RequestMapping(value = "/index", method = RequestMethod.GET)
37 public String printPublicHome(ModelMap model) {
38 model.addAttribute("username", getPrincipalName());
39 model = getStatistics(model);
51 * @return JSP template for the page
53 @RequestMapping(value = "/login", method = RequestMethod.GET)
54 public String login(ModelMap model) {
59 * Form a page with failed login
64 * @return JSP template for the page
66 @RequestMapping(value = "/loginfailed", method = RequestMethod.GET)
67 public String loginerror(ModelMap model) {
68 model.addAttribute("error", "Wrong user name or password");
73 * Form a page after log out
78 * @return JSP template for the page
80 @RequestMapping(value = "/logout", method = RequestMethod.GET)
81 public String logout(ModelMap model) {
82 model = getStatistics(model);
87 * Form a page with denial of service
92 * @return JSP template for the page
94 @RequestMapping(value = "/denied", method = RequestMethod.GET)
95 public String denied(ModelMap model) {
96 model.put("username", getPrincipalName());
97 return "support/Denied";
101 * Form the project home page
106 * @return JSP template for the page
108 @RequestMapping(value = "/home", method = RequestMethod.GET)
109 public String printHome(ModelMap model) {
110 model.addAttribute("username", getPrincipalName());
111 model = getStatistics(model);
116 * collect job execution statiustics for the last 7 days.
121 * @return the the same model, but with additional parameters with the job
124 private ModelMap getStatistics(ModelMap model) {
126 model.addAttribute("ndays", ndays);
128 Calendar cal = Calendar.getInstance();
129 String date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
130 long longDate2 = DateFormatter.DateParsing(date2, formaterYYMMDD);
131 cal.add(Calendar.DATE, -ndays);
132 String date1 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
133 long longDate1 = DateFormatter.DateParsing(date1, formaterYYMMDD);
135 DailyStatisticsReader reader = new DailyStatisticsReader();
136 TotalJobsStatisticBean res = reader.query(longDate1, longDate2);
137 Total total = res.getWholeTotal();
138 model.addAttribute("total", total.getTotal());
139 model.addAttribute("totalOK", total.getTotalOK());
140 model.addAttribute("totalTimeout", total.getTotalOK());
141 model.addAttribute("totalError", total.getTotalError());
142 model.addAttribute("totalStopped", total.getTotalStopped());