Example #1
0
  private void validateDeliveryInfo(DeliveryInfo deliveryInfo, UserDAO userDAO)
      throws EmailDuplicateException, InvalidInputException {
    String firstName = deliveryInfo.getFirstName();
    if (ValidatorUtil.isEmpty(firstName) || ValidatorUtil.isInvalidLength(firstName, 1, 20)) {
      throw new InvalidInputException("deliveryInfo.firstName");
    }
    String lastName = deliveryInfo.getLastName();
    if (ValidatorUtil.isEmpty(lastName) || ValidatorUtil.isInvalidLength(lastName, 1, 20)) {
      throw new InvalidInputException("deliveryInfo.lastName");
    }
    String email = deliveryInfo.getEmail();
    if (ValidatorUtil.isEmpty(email)
        || ValidatorUtil.isInvalidLength(email, 1, 50)
        || ValidatorUtil.isInvalidEmail(email.trim())) {
      throw new InvalidInputException("deliveryInfo.email");
    }
    String address = deliveryInfo.getAddress();
    if (ValidatorUtil.isEmpty(address) || ValidatorUtil.isInvalidLength(address, 1, 100)) {
      throw new InvalidInputException("deliveryInfo.address");
    }
    String tel = deliveryInfo.getTel();
    if (ValidatorUtil.isEmpty(tel) || ValidatorUtil.isInvalidLength(tel, 1, 50)) {
      throw new InvalidInputException("deliveryInfo.tel");
    }

    Long dbUserId = userDAO.getUserIdByEmail(email.trim());
    if (dbUserId != null) {
      if (userId == null || (dbUserId.longValue() != userId.longValue())) {
        throw new EmailDuplicateException("deliveryInfo.email");
      }
    }
  }
Example #2
0
  private void validateCredentials(String un, String pwd, UserDAO userDAO)
      throws UserNameDuplicateException, InvalidInputException {
    if (ValidatorUtil.isEmpty(un) || ValidatorUtil.isInvalidLength(un, 1, 20)) {
      throw new InvalidInputException("userName");
    }
    if (ValidatorUtil.isEmpty(pwd, false) || ValidatorUtil.isInvalidLength(pwd, 5, 20, false)) {
      throw new InvalidInputException("password");
    }

    Long dbUserId = userDAO.getUserIdByUserName(un.trim());
    if (dbUserId != null) {
      if (userId == null || (dbUserId.longValue() != userId.longValue()))
        throw new UserNameDuplicateException("userName");
    }
  }