예제 #1
0
  @Override
  public void sendMemberRequest(String userId, String communityId) {
    Assert.notNull(userId, "userId must not be null");
    Assert.notNull(communityId, "communityId must not be null");

    User user = userRepository.findOne(userId);
    Community community = communityRepository.findOne(communityId);

    if (user == null) {
      String msg = String.format("user not find by id %s", userId);
      logger.debug(msg);
      throw errorService.createException(AccountException.class, ErrorEnum.ERROR_USER_NOT_FOUND);
    } else if (!user.getStatus().equals(AccountStatusEnum.ACTIVE)) {
      String msg = String.format("user status must be: %s", AccountStatusEnum.ACTIVE);
      logger.debug(msg);
      throw errorService.createException(AccountException.class, ErrorEnum.ERROR_USER_NOT_ACTIVE);
    } else if (community == null) {
      String msg = String.format("community not find by id %s", communityId);
      logger.debug(msg);
      throw errorService.createException(
          AccountException.class, ErrorEnum.ERROR_COMMUNITY_NOT_FOUND);
    } else if (!community.getStatus().equals(AccountStatusEnum.ACTIVE)) {
      String msg = String.format("community status must be: %s", AccountStatusEnum.ACTIVE);
      logger.debug(msg);
      throw errorService.createException(
          AccountException.class, ErrorEnum.ERROR_COMMUNITY_NOT_ACTIVE);
    } else {
      Notification notification = new Notification();
      notification.setFromId(userId);
      notification.setToId(communityId);
      notification.setType(NotificationTypeEnum.MEMBER);
      notificationService.addNotification(notification);
    }
  }
예제 #2
0
  @Override
  public void deleteMember(String userId, String communityId) {
    Assert.notNull(userId, "userId must not be null");
    Assert.notNull(communityId, "communityId must not be null");

    User user = userRepository.findOne(userId);
    Community community = communityRepository.findOne(communityId);

    if (user == null) {
      String msg = String.format("user not find by id %s", userId);
      logger.debug(msg);
      throw errorService.createException(AccountException.class, ErrorEnum.ERROR_USER_NOT_FOUND);
    } else if (!user.getStatus().equals(AccountStatusEnum.ACTIVE)) {
      String msg = String.format("user status must be: %s", AccountStatusEnum.ACTIVE);
      logger.debug(msg);
      throw errorService.createException(AccountException.class, ErrorEnum.ERROR_USER_NOT_ACTIVE);
    } else if (community == null) {
      String msg = String.format("community not find by id %s", communityId);
      logger.debug(msg);
      throw errorService.createException(
          AccountException.class, ErrorEnum.ERROR_COMMUNITY_NOT_FOUND);
    } else if (!community.getStatus().equals(AccountStatusEnum.ACTIVE)) {
      String msg = String.format("community status must be: %s", AccountStatusEnum.ACTIVE);
      logger.debug(msg);
      throw errorService.createException(
          AccountException.class, ErrorEnum.ERROR_COMMUNITY_NOT_ACTIVE);
    } else {
      relationRepository.remove(communityId, userId, RelationTypeEnum.MEMBER);
      accountStoreService.update(userId);
    }
  }
예제 #3
0
  @Override
  public void deleteOwner(String userId, String communityId) {
    Assert.notNull(userId, "userId must not be null");
    Assert.notNull(communityId, "communityId must not be null");

    User user = userRepository.findOne(userId);
    Community community = communityRepository.findOne(communityId);

    if (user == null) {
      String msg = String.format("user not find by id %s", userId);
      logger.debug(msg);
      throw errorService.createException(AccountException.class, ErrorEnum.ERROR_USER_NOT_FOUND);
    } else if (!user.getStatus().equals(AccountStatusEnum.ACTIVE)) {
      String msg = String.format("user status must be: %s", AccountStatusEnum.ACTIVE);
      logger.debug(msg);
      throw errorService.createException(AccountException.class, ErrorEnum.ERROR_USER_NOT_ACTIVE);
    } else if (community == null) {
      String msg = String.format("community not find by id %s", communityId);
      logger.debug(msg);
      throw errorService.createException(
          AccountException.class, ErrorEnum.ERROR_COMMUNITY_NOT_FOUND);
    } else if (!community.getStatus().equals(AccountStatusEnum.ACTIVE)) {
      String msg = String.format("community status must be: %s", AccountStatusEnum.ACTIVE);
      logger.debug(msg);
      throw errorService.createException(
          AccountException.class, ErrorEnum.ERROR_COMMUNITY_NOT_ACTIVE);
    } else {
      String[] typeRelations = new String[1];
      typeRelations[0] = RelationTypeEnum.OWNER.toString();

      List<Relation> relations =
          relationRepository.findByAccountRelationCriteria(
              new AccountRelationCriteria(communityId, typeRelations));

      if (relations != null
          && relations.size() == 1
          && relations.get(0).getUserIds() != null
          && relations.get(0).getUserIds().length > 1) {
        relationRepository.remove(communityId, userId, RelationTypeEnum.OWNER);
        accountStoreService.update(userId);
      } else {
        String msg =
            String.format("the sole owner %s of the user community active %s", userId, communityId);
        logger.debug(msg);
        throw errorService.createException(
            AccountException.class, ErrorEnum.ERROR_SOLE_OWNER_OF_THE_USER_COMMUNITY_ACTIVE);
      }
    }
  }