diff --git a/mock-identity-system/README.md b/mock-identity-system/README.md index 5f293b77..5c4e5d03 100644 --- a/mock-identity-system/README.md +++ b/mock-identity-system/README.md @@ -72,8 +72,7 @@ This validation ensures that the provided Identity data adhere to the defined sc ```` mosip.mock.ida.identity.schema.url=classpath:/mock-identity-schema.json - mosip.mock.ida.update-identity.non-mandatory.fields={"givenName","familyName","middleName","nickName","preferredUsername","gender","streetAddress","locality","region","country","pin","preferredLang","dateOfBirth","postalCode","encodedPhoto","email","phone","zoneInfo","locale","password"} -```` + ```` How It Works * For create operations: diff --git a/mock-identity-system/src/main/java/io/mosip/esignet/mock/identitysystem/validator/IdentitySchemaValidator.java b/mock-identity-system/src/main/java/io/mosip/esignet/mock/identitysystem/validator/IdentitySchemaValidator.java index 7bf3d776..5e4ac7fd 100644 --- a/mock-identity-system/src/main/java/io/mosip/esignet/mock/identitysystem/validator/IdentitySchemaValidator.java +++ b/mock-identity-system/src/main/java/io/mosip/esignet/mock/identitysystem/validator/IdentitySchemaValidator.java @@ -25,9 +25,6 @@ public class IdentitySchemaValidator implements ConstraintValidator nonMandatoryFieldsOnUpdate; - private String action; private JsonSchema schema; @@ -68,11 +65,9 @@ private Set validateIdentityData(JsonNode identityJsonNode) { Set errors = schema.validate(identityJsonNode); // If not a create operation, filter out specific errors if (action.equals("UPDATE")) { - // Ignore validation errors with code 1029 (null value) and for exempted fields when validating updateIdentity + // Ignore validation errors with code 1028 (null value) and for exempted fields when validating updateIdentity errors = errors.stream() - .filter(error -> !error.getCode().equals("1029") || - !nonMandatoryFieldsOnUpdate.contains(error. - getInstanceLocation().getName(0))) + .filter(error -> !error.getCode().equals("1028")) .collect(Collectors.toSet()); } return errors; @@ -80,11 +75,17 @@ private Set validateIdentityData(JsonNode identityJsonNode) { private void addValidationErrorCode(Set errors, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); - errors.forEach(error->context. - buildConstraintViolationWithTemplate("invalid_"+error.getInstanceLocation().getName(0).toLowerCase()) + errors.forEach(error-> + context.buildConstraintViolationWithTemplate(getErrorCodeFromValidationMessage(error)) .addConstraintViolation()); } + private String getErrorCodeFromValidationMessage(ValidationMessage error) { + String fieldName = error.getInstanceLocation().getNameCount() > 0 ? error.getInstanceLocation().getName(0) : + error.getProperty(); + return fieldName != null ? "invalid_"+fieldName.toLowerCase() : "unknown_field"; + } + private InputStream getResource(String url) { try{ Resource resource = resourceLoader.getResource(url); diff --git a/mock-identity-system/src/main/resources/application-default.properties b/mock-identity-system/src/main/resources/application-default.properties index ab53aaf4..d4ef7bd8 100644 --- a/mock-identity-system/src/main/resources/application-default.properties +++ b/mock-identity-system/src/main/resources/application-default.properties @@ -30,7 +30,6 @@ mosip.mock.ida.identity.schema.url=classpath:/mock-identity-schema.json mosip.mock.ui-spec.schema.url=classpath:/mock-identity-ui-spec.json -mosip.mock.ida.update-identity.non-mandatory.fields={"fullName","givenName","familyName","middleName","nickName","preferredUsername","gender","streetAddress","locality","region","country","pin","preferredLang","dateOfBirth","postalCode","encodedPhoto","email","phone","zoneInfo","locale","password"} ##----------------------------------------- Database properties -------------------------------------------------------- mosip.mockidentitysystem.database.hostname=${database.host}