Пример #1
0
  @PreAuthorize("hasRole('ROLE_ADMIN')")
  @RequestMapping(value = "/addsetting", method = RequestMethod.POST)
  public ModelAndView addSetting(
      @RequestHeader(value = "X-Requested-With", required = false) String requestedWith,
      HttpSession session,
      @ModelAttribute SettingsForm settingsForm,
      Model model,
      @RequestParam(value = "submitType") String actionPath) {

    ModelAndView mav = new ModelAndView();
    String strid = "";
    String key = "";
    String value = "";
    if (log.isDebugEnabled()) log.debug("Enter domain/addsetting");

    if (actionPath.equalsIgnoreCase("cancel")) {
      if (log.isDebugEnabled()) log.debug("trying to cancel from saveupdate");
      SearchDomainForm form2 = (SearchDomainForm) session.getAttribute("searchDomainForm");
      model.addAttribute(form2 != null ? form2 : new SearchDomainForm());
      model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));

      mav.setViewName("main");
      mav.addObject("statusList", EntityStatus.getEntityStatusList());
      return mav;
    }
    if (actionPath.equalsIgnoreCase("newsetting") || actionPath.equalsIgnoreCase("add setting")) {
      if (log.isDebugEnabled()) log.debug("trying to get/set settings");
      strid = "" + settingsForm.getId();
      key = "" + settingsForm.getKey();
      value = "" + settingsForm.getValue();
      try {
        if (log.isDebugEnabled()) log.debug("trying set settings services");
        configSvc.addSetting(key, value);
        if (log.isDebugEnabled()) log.debug("PAST trying set settings services");
      } catch (ConfigurationServiceException e) {
        e.printStackTrace();
      }

      model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
      SimpleForm simple = new SimpleForm();
      simple.setId(Long.parseLong(strid));
      model.addAttribute("simpleForm", simple);

      try {
        model.addAttribute("settingsResults", configSvc.getAllSettings());
      } catch (ConfigurationServiceException e) {
        e.printStackTrace();
      }
      mav.setViewName("settings");
      // the Form's default button action
      String action = "Update";
      model.addAttribute("settingsForm", settingsForm);
      model.addAttribute("action", action);
      model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
    }

    return mav;
  }
Пример #2
0
  @PreAuthorize("hasRole('ROLE_ADMIN')")
  @RequestMapping(value = "/removesettings", method = RequestMethod.POST)
  public ModelAndView removeAnchors(
      @RequestHeader(value = "X-Requested-With", required = false) String requestedWith,
      HttpSession session,
      @ModelAttribute SimpleForm simpleForm,
      Model model,
      @RequestParam(value = "submitType") String actionPath) {

    ModelAndView mav = new ModelAndView();

    if (log.isDebugEnabled()) log.debug("Enter domain/removesettings");
    if (simpleForm.getRemove() != null) {
      if (log.isDebugEnabled())
        log.debug("the list of checkboxes checked or not is: " + simpleForm.getRemove().toString());
    }

    String strid = "" + simpleForm.getId();
    if (configSvc != null
        && simpleForm != null
        && actionPath != null
        && (actionPath.equalsIgnoreCase("delete") || actionPath.equalsIgnoreCase("remove selected"))
        && simpleForm.getRemove() != null) {
      int cnt = simpleForm.getRemove().size();
      try {
        Collection<String> settingstoberemovedlist = simpleForm.getRemove();
        if (log.isDebugEnabled()) log.debug(" Trying to remove settings from database");
        configSvc.deleteSetting(settingstoberemovedlist);
        if (log.isDebugEnabled()) log.debug(" SUCCESS Trying to remove settings");
      } catch (ConfigurationServiceException e) {
        if (log.isDebugEnabled()) log.error(e);
      }
    }
    try {
      model.addAttribute("settingsResults", configSvc.getAllSettings());
    } catch (ConfigurationServiceException e) {
      e.printStackTrace();
    }
    mav.setViewName("settings");
    String action = "Update";
    model.addAttribute("settingsForm", new SettingsForm());
    model.addAttribute("action", action);
    model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
    model.addAttribute("simpleForm", simpleForm);
    strid = "" + simpleForm.getId();

    return mav;
  }