X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=server%2Fcompbio%2Fcontrollers%2FMainController.java;h=d9e0cf03d5e4ce5da94d5ec747c9205917e152f7;hb=39e7d79de1fd4062182d18019826cb805dea2625;hp=a945e2551083c47529553a9938fad194460ebfca;hpb=c1ae48e93c766434005e5d5201af8ad23bc0a59b;p=proteocache.git diff --git a/server/compbio/controllers/MainController.java b/server/compbio/controllers/MainController.java index a945e25..d9e0cf0 100644 --- a/server/compbio/controllers/MainController.java +++ b/server/compbio/controllers/MainController.java @@ -1,45 +1,146 @@ package compbio.controllers; +import java.util.Calendar; + import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import compbio.beans.Total; +import compbio.beans.TotalJobsStatisticBean; +import compbio.cassandra.DateFormatter; +import compbio.cassandra.readers.DailyStatisticsReader; + +/** + * The main system controller with most general functionality (home page, login + * and logout pages) + * + * @author Alexander Sherstnev + * @author Natasha Sherstneva + * + * @version 1.0 + * @since Dec 2013 + */ @Controller public class MainController extends BasicController { + /** + * Form the project home page + * + * @param model + * MVC model object + * + * @return JSP template for the page + */ @RequestMapping(value = "/index", method = RequestMethod.GET) public String printPublicHome(ModelMap model) { - model.addAttribute("message", "Spring Security Custom Form example"); + model.addAttribute("username", getPrincipalName()); + model = getStatistics(model); + if (isUserRole()) + return "home"; return "public"; } + /** + * Form login page + * + * @param model + * MVC model object + * + * @return JSP template for the page + */ @RequestMapping(value = "/login", method = RequestMethod.GET) public String login(ModelMap model) { return "login"; } + /** + * Form a page with failed login + * + * @param model + * MVC model object + * + * @return JSP template for the page + */ @RequestMapping(value = "/loginfailed", method = RequestMethod.GET) public String loginerror(ModelMap model) { model.addAttribute("error", "Wrong user name or password"); return "login"; } + /** + * Form a page after log out + * + * @param model + * MVC model object + * + * @return JSP template for the page + */ @RequestMapping(value = "/logout", method = RequestMethod.GET) public String logout(ModelMap model) { + model = getStatistics(model); return "public"; } + /** + * Form a page with denial of service + * + * @param model + * MVC model object + * + * @return JSP template for the page + */ @RequestMapping(value = "/denied", method = RequestMethod.GET) public String denied(ModelMap model) { model.put("username", getPrincipalName()); return "support/Denied"; } + /** + * Form the project home page + * + * @param model + * MVC model object + * + * @return JSP template for the page + */ @RequestMapping(value = "/home", method = RequestMethod.GET) - public String printHome(ModelMap model ) { + public String printHome(ModelMap model) { model.addAttribute("username", getPrincipalName()); + model = getStatistics(model); return "home"; } + /** + * collect job execution statiustics for the last 7 days. + * + * @param model + * MVC model object + * + * @return the the same model, but with additional parameters with the job + * statistics + */ + private ModelMap getStatistics(ModelMap model) { + int ndays = 7; + model.addAttribute("ndays", ndays); + + Calendar cal = Calendar.getInstance(); + String date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH); + long longDate2 = DateFormatter.DateParsing(date2, formaterYYMMDD); + cal.add(Calendar.DATE, -ndays); + String date1 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH); + long longDate1 = DateFormatter.DateParsing(date1, formaterYYMMDD); + + DailyStatisticsReader reader = new DailyStatisticsReader(); + TotalJobsStatisticBean res = reader.query(longDate1, longDate2); + Total total = res.getWholeTotal(); + model.addAttribute("total", total.getTotal()); + model.addAttribute("totalOK", total.getTotalOK()); + model.addAttribute("totalTimeout", total.getTotalOK()); + model.addAttribute("totalError", total.getTotalError()); + model.addAttribute("totalStopped", total.getTotalStopped()); + return model; + } + }