コード例 #1
0
  @RequestMapping(
      value = {"/save"},
      method = RequestMethod.POST)
  public ModelAndView save(
      @ModelAttribute("backup") @Valid Backup backup,
      BindingResult result,
      RedirectAttributes redirectAttributes) {

    if (result.hasErrors()) return editView(backup);

    if (!canWrite(backup.getOutputFolder())) {
      ObjectError error =
          new ObjectError("backup", "The provided output folder needs write permission");
      result.addError(error);
      return editView(backup);
    }

    if (backup.getDatabases() == null || backup.getDatabases().size() == 0) {
      ObjectError error =
          new ObjectError("databases", "At least one database needs to be selected");
      result.addError(error);
      return editView(backup);
    }

    if (backup.getId() == null) backupService.save(backup);
    else backupService.update(backup);

    redirectAttributes.addFlashAttribute("backup", backup);
    return new ModelAndView("redirect:/backups/list");
  }
コード例 #2
0
 @RequestMapping(
     value = {"/remove/{id}"},
     method = RequestMethod.GET)
 public ModelAndView remove(@PathVariable(value = "id") Integer backupId) {
   backupService.removeById(backupId);
   return new ModelAndView("redirect:/backups/list");
 }
コード例 #3
0
  @RequestMapping(
      value = {"/edit/{id}"},
      method = RequestMethod.GET)
  public ModelAndView edit(@PathVariable(value = "id") Integer backupId) {

    Backup alert = backupService.getById(backupId);
    if (alert == null) return getModelView("forward:/404");

    return editView(alert);
  }
コード例 #4
0
  @RequestMapping(
      value = {"/list"},
      method = RequestMethod.GET)
  public ModelAndView list() {

    ModelAndView mview =
        getModelView("list_backups", "MongoDB Backups", "List of Application Alerts");

    List<Breadcrumb> bds = new ArrayList<Breadcrumb>();
    bds.add(new Breadcrumb("Hosts"));
    bds.add(new Breadcrumb("Backups", "backups/list"));
    mview.addObject("breadcrumbs", bds);

    List<Backup> backups = backupService.list();
    mview.addObject("backups", backups);

    setupView(mview);
    return mview;
  }