Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions mock-identity-system/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ public class IdentitySchemaValidator implements ConstraintValidator<IdentitySche
@Value("${mosip.mock.ida.identity.schema.url}")
private String identitySchemaUrl;

@Value("#{${mosip.mock.ida.update-identity.non-mandatory.fields}}")
private Set<String> nonMandatoryFieldsOnUpdate;

private String action;

private JsonSchema schema;
Expand Down Expand Up @@ -68,23 +65,27 @@ private Set<ValidationMessage> validateIdentityData(JsonNode identityJsonNode) {
Set<ValidationMessage> 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());
Comment thread
This conversation was marked as resolved.
Resolved
}
return errors;
}

private void addValidationErrorCode(Set<ValidationMessage> 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";
}
Comment thread
This conversation was marked as resolved.
Resolved

private InputStream getResource(String url) {
try{
Resource resource = resourceLoader.getResource(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Loading