Exemplo n.º 1
0
  @Override
  public void sendFriendshipRequest(String userId, String friendId) {
    Assert.notNull(userId, "userId must not be null");
    Assert.notNull(friendId, "friendId must not be null");

    User user = userRepository.findOne(userId);
    User friend = userRepository.findOne(friendId);

    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 (friend == null) {
      String msg = String.format("friend not find by id %s", friendId);
      logger.debug(msg);
      throw errorService.createException(AccountException.class, ErrorEnum.ERROR_USER_NOT_FOUND);
    } else if (!friend.getStatus().equals(AccountStatusEnum.ACTIVE)) {
      String msg = String.format("friend status must be: %s", AccountStatusEnum.ACTIVE);
      logger.debug(msg);
      throw errorService.createException(AccountException.class, ErrorEnum.ERROR_USER_NOT_ACTIVE);
    } else {
      Notification notification = new Notification();
      notification.setFromId(userId);
      notification.setToId(friendId);
      notification.setType(NotificationTypeEnum.FRIEND);
      notificationService.addNotification(notification);
    }
  }
Exemplo n.º 2
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);
    }
  }