Example #1
0
  public void validateForCreate() {

    List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();

    DataValidatorBuilder baseDataValidator = getDataValidator(dataValidationErrors);

    baseDataValidator
        .reset()
        .parameter(GUARANTOR_JSON_INPUT_PARAMS.CLIENT_RELATIONSHIP_TYPE_ID.getValue())
        .value(this.clientRelationshipTypeId)
        .ignoreIfNull()
        .integerGreaterThanZero();

    baseDataValidator
        .reset()
        .parameter(GUARANTOR_JSON_INPUT_PARAMS.GUARANTOR_TYPE_ID.getValue())
        .value(this.guarantorTypeId)
        .notNull()
        .inMinMaxRange(GuarantorType.getMinValue(), GuarantorType.getMaxValue());

    // validate for existing Client or Staff serving as gurantor
    if (!this.isExternalGuarantor()) {
      baseDataValidator
          .reset()
          .parameter(GUARANTOR_JSON_INPUT_PARAMS.ENTITY_ID.getValue())
          .value(this.entityId)
          .notNull()
          .integerGreaterThanZero();
    } else {
      // validate for an external guarantor
      baseDataValidator
          .reset()
          .parameter(GUARANTOR_JSON_INPUT_PARAMS.FIRSTNAME.getValue())
          .value(this.firstname)
          .notBlank()
          .notExceedingLengthOf(50);
      baseDataValidator
          .reset()
          .parameter(GUARANTOR_JSON_INPUT_PARAMS.LASTNAME.getValue())
          .value(this.lastname)
          .notBlank()
          .notExceedingLengthOf(50);
      validateNonMandatoryFieldsForMaxLength(baseDataValidator);
    }

    if (!dataValidationErrors.isEmpty()) {
      throw new PlatformApiDataValidationException(
          "validation.msg.validation.errors.exist",
          "Validation errors exist.",
          dataValidationErrors);
    }
  }
Example #2
0
  public void validateForUpdate() {
    List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();

    DataValidatorBuilder baseDataValidator = getDataValidator(dataValidationErrors);

    baseDataValidator
        .reset()
        .parameter(GUARANTOR_JSON_INPUT_PARAMS.CLIENT_RELATIONSHIP_TYPE_ID.getValue())
        .value(this.clientRelationshipTypeId)
        .ignoreIfNull()
        .integerGreaterThanZero();

    baseDataValidator
        .reset()
        .parameter(GUARANTOR_JSON_INPUT_PARAMS.GUARANTOR_TYPE_ID.getValue())
        .value(this.guarantorTypeId)
        .ignoreIfNull()
        .inMinMaxRange(GuarantorType.getMinValue(), GuarantorType.getMaxValue());

    // validate for existing Client or Staff serving as gurantor
    if (!this.isExternalGuarantor()) {
      baseDataValidator
          .reset()
          .parameter(GUARANTOR_JSON_INPUT_PARAMS.ENTITY_ID.getValue())
          .value(this.entityId)
          .ignoreIfNull()
          .integerGreaterThanZero();
    } else {
      // TODO: Vishwas this validation is buggy (it is compulsory to
      // update
      // firstname and last name when a guarantor type is changed), to be
      // corrected while
      // refactoring for maker checker
      baseDataValidator
          .reset()
          .parameter(GUARANTOR_JSON_INPUT_PARAMS.FIRSTNAME.getValue())
          .value(this.firstname)
          .ignoreIfNull()
          .notExceedingLengthOf(50);
      baseDataValidator
          .reset()
          .parameter(GUARANTOR_JSON_INPUT_PARAMS.LASTNAME.getValue())
          .value(this.lastname)
          .ignoreIfNull()
          .notExceedingLengthOf(50);

      validateNonMandatoryFieldsForMaxLength(baseDataValidator);
    }
    baseDataValidator
        .reset()
        .anyOfNotNull(
            this.entityId,
            this.addressLine1,
            this.addressLine2,
            this.city,
            this.comment,
            this.country,
            this.firstname,
            this.housePhoneNumber,
            this.lastname,
            this.mobileNumber,
            this.state,
            this.zip);

    if (!dataValidationErrors.isEmpty()) {
      throw new PlatformApiDataValidationException(
          "validation.msg.validation.errors.exist",
          "Validation errors exist.",
          dataValidationErrors);
    }
  }