예제 #1
0
 @Override
 public void saveRole(ServiceContext context, Role role) throws JServiceException {
   validateRoleCode(role);
   if (exists(context, role)) {
     throw new JServiceException("role code [" + role.getRoleCode() + "] already has exist.");
   }
   saveOnly(context, role);
 }
예제 #2
0
  @Override
  public void deleteRole(ServiceContext context, Role role) throws JServiceException {
    if (JStringUtils.isNullOrEmpty(role.getId())) {
      throw new IllegalArgumentException("the primary property id of role is null.");
    }

    if (JStringUtils.isNullOrEmpty(role.getRoleCode())) {
      role.setRoleCode(getById(context, role.getId()).getRoleCode());
    }
    validateRoleCode(role);
    delete(context, role.getId());
  }
예제 #3
0
  @Override
  public void updateRole(ServiceContext context, Role role) throws JServiceException {

    validateRoleCode(role);

    if (JStringUtils.isNullOrEmpty(role.getId())) {
      throw new IllegalArgumentException("the primary property id of role is null.");
    }

    if (exists(context, role)) {
      throw new JServiceException("role code [" + role.getRoleCode() + "] already has exist.");
    }
    updateOnly(context, role);
  }
예제 #4
0
  private void validateRoleCode(Role role) throws JServiceException {

    String code = role.getRoleCode();

    if (JStringUtils.isNullOrEmpty(code)) {
      throw new IllegalArgumentException("role code  is null");
    }

    code = code.trim();

    if (ADMIN_CODE.equalsIgnoreCase(code)) {
      throw new JServiceException(
          "role code [" + ADMIN_CODE + "] is initialized by system.please change...");
    }

    if (DEFAULT_CODE.equalsIgnoreCase(code)) {
      throw new JServiceException(
          "role code [" + DEFAULT_CODE + "] is initialized by system.please change...");
    }
  }
예제 #5
0
 @Override
 public boolean exists(ServiceContext context, Role role) throws JServiceException {
   if (role == null) {
     throw new IllegalArgumentException("role argument is null");
   }
   boolean exists = false;
   Role dbRole = getRoleByRoleCode(context, role.getRoleCode());
   // new created.
   if (JStringUtils.isNullOrEmpty(role.getId())) {
     exists = dbRole != null;
   } else {
     // updated status.
     if (dbRole != null) {
       // if it's self
       exists = !role.getId().equals(dbRole.getId());
     } else {
       exists = false;
     }
   }
   return exists;
 }