Example #1
0
  @RequestMapping("role-def-save")
  public String save(@ModelAttribute RoleDef roleDef, RedirectAttributes redirectAttributes) {
    try {
      // before check
      roleDefChecker.check(roleDef);

      // after invoke
      RoleDef dest = null;
      Long id = roleDef.getId();

      if (id != null) {
        dest = roleDefManager.get(id);
        beanMapper.copy(roleDef, dest);
      } else {
        dest = roleDef;
      }

      if (id == null) {
        dest.setScopeId(ScopeHolder.getScopeId());
      }

      roleDefManager.save(dest);

      messageHelper.addFlashMessage(redirectAttributes, "core.success.save", "保存成功");
    } catch (CheckRoleException ex) {
      logger.warn(ex.getMessage(), ex);
      redirectAttributes.addFlashAttribute("message", ex.getMessage());

      return "auth/role-def-input";
    }

    return "redirect:/auth/role-def-list.do";
  }
Example #2
0
  public String input() {
    if (id > 0) {
      model = roleManager.get(id);
    }

    Long localId =
        scopeConnector.findLocalId(ScopeHolder.getGlobalCode(), ScopeHolder.getLocalCode());
    roleDefs = roleDefManager.find("from RoleDef where localId=?", localId);

    List<LocalScopeDTO> localScopeDtos = scopeConnector.findSharedLocalScopes();

    for (LocalScopeDTO localScopeDto : localScopeDtos) {
      roleDefs.addAll(roleDefManager.find("from RoleDef where localId=?", localScopeDto.getId()));
    }

    List<Role> roles = roleManager.findBy("localId", localId);
    List<RoleDef> removedRoleDefs = new ArrayList<RoleDef>();

    for (Role role : roles) {
      for (RoleDef roleDef : roleDefs) {
        if (roleDef.getId().equals(role.getRoleDef().getId())) {
          removedRoleDefs.add(roleDef);

          break;
        }
      }
    }

    roleDefs.removeAll(removedRoleDefs);

    return INPUT;
  }