I need some help in identifying the logic to implement the following conditions below:
I have a search criteria request which can can have around 10 possible combinations. Im writing the request validation for it with proper error messages.
These are my conditions :
if (request.getFullName() == null && request.getFullNameEs() == null && request.getBirthDate() == null && request.getNat() == null &&
request.getGender() == null) {
validationErrors.add("Name criteria search is not proper");
}
if (request.getPassportNo() != null) {
if (request.getPassportNationality() == null && request.getBirthYear() == null) {
errors.reject(NULL_OR_EMPTY_FIELD_ERROR, "Please pass passportNationality or birthYear ");
}
if (request.getPassportTypeId() == null || request.getPassportNationality() == null) {
errors.reject(NULL_OR_EMPTY_FIELD_ERROR, "Please pass passportTypeId and/or passportNationality");
}
} else {
errors.reject(NULL_OR_EMPTY_FIELD_ERROR, "Please pass passportNo");
}
if (request.getIdNo() == null) {
if (request.getIdType() == null || request.getIdNationalityId() == null) {
errors.reject(NULL_OR_EMPTY_FIELD_ERROR, "Please pass IdType and/or IdNationalityId");
return;
}
} else {
errors.reject(NULL_OR_EMPTY_FIELD_ERROR, "Please pass idNo");
}
if (request.getPersonNo() == null && request.getPersonTypeId() == null) {
errors.reject(NULL_OR_EMPTY_FIELD_ERROR, ERROR_MESSAGE);
}
if (request.getSponsorNo() == null && request.getSponsorTypeId() == null && request.getPpsId() == null) {
errors.reject(NULL_OR_EMPTY_FIELD_ERROR, ERROR_MESSAGE);
}
if (request.getSponsorNo() == null && request.getSponsorTypeId() == null && request.getPpsId() == null) {
errors.reject(NULL_OR_EMPTY_FIELD_ERROR, ERROR_MESSAGE);
}
if (request.getSponsorNo() == null) {
errors.reject(NULL_OR_EMPTY_FIELD_ERROR, ERROR_MESSAGE);
}
if (request.getPersonNo() == null && request.getPersonTypeId() == null) {
errors.reject(NULL_OR_EMPTY_FIELD_ERROR, ERROR_MESSAGE);
}
in one request, only of the criteria should be passed and it that particular criteria failed then I want the validation to break and display only that particular error message and not the list of messages.
How can I achieve this behavior?
Aucun commentaire:
Enregistrer un commentaire