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); } }
@GET @Path("template") @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) public String newGuarantorTemplate(@Context final UriInfo uriInfo) { this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission); final List<EnumOptionData> guarantorTypeOptions = GuarantorEnumerations.guarantorType(GuarantorType.values()); final Collection<CodeValueData> allowedClientRelationshipTypes = this.codeValueReadPlatformService.retrieveCodeValuesByCode( GuarantorConstants.GUARANTOR_RELATIONSHIP_CODE_NAME); final Collection<CodeValueData> allowedGncbTypes = this.codeValueReadPlatformService.retrieveCodeValuesByCode( GuarantorConstants.GNCB_RELATIONSHIP_CODE_NAME); final Collection<PortfolioAccountData> accountLinkingOptions = null; final GuarantorData guarantorData = GuarantorData.template( guarantorTypeOptions, allowedClientRelationshipTypes, allowedGncbTypes, accountLinkingOptions); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.apiJsonSerializerService.serialize( settings, guarantorData, RESPONSE_DATA_PARAMETERS); }
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); } }