コード例 #1
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());
  }
コード例 #2
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;
 }
コード例 #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);
  }