示例#1
0
  public void saveWhitelistApp(
      WhitelistApp whitelistApp,
      Long whitelistTypeId,
      String hostContent,
      String ipContent,
      String username,
      String tenantId) {
    Long id = whitelistApp.getId();
    WhitelistApp dest = null;

    if (id != null) {
      whitelistApp.setWhitelistHosts(null);
      whitelistApp.setWhitelistIps(null);
      dest = whitelistAppManager.get(id);
      beanMapper.copy(whitelistApp, dest);
    } else {
      dest = whitelistApp;
      dest.setUserId(username);
      dest.setTenantId(tenantId);
    }

    // type
    WhitelistType whitelistType = whitelistTypeManager.get(whitelistTypeId);
    dest.setWhitelistType(whitelistType);

    // host
    this.processHost(dest, Arrays.asList(hostContent.split("\n")));

    // ip
    this.processIp(dest, Arrays.asList(ipContent.split("\n")));

    whitelistAppManager.save(dest);
  }
  @RequestMapping("whitelist-type-input")
  public String input(@RequestParam(value = "id", required = false) Long id, Model model) {
    if (id != null) {
      WhitelistType whitelistType = whitelistTypeManager.get(id);
      model.addAttribute("model", whitelistType);
    }

    return "whitelist/whitelist-type-input";
  }
  @RequestMapping("whitelist-type-save")
  public String save(
      @ModelAttribute WhitelistType whitelistType, RedirectAttributes redirectAttributes) {
    String tenantId = tenantHolder.getTenantId();
    Long id = whitelistType.getId();
    WhitelistType dest = null;

    if (id != null) {
      dest = whitelistTypeManager.get(id);
      beanMapper.copy(whitelistType, dest);
    } else {
      dest = whitelistType;
      dest.setTenantId(tenantId);
    }

    whitelistTypeManager.save(dest);
    messageHelper.addFlashMessage(redirectAttributes, "core.success.save", "保存成功");

    return "redirect:/whitelist/whitelist-type-list.do";
  }