Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
Signed-off-by: kaifk468 <[email protected]>
  • Loading branch information
kaifk468 committed Dec 15, 2024
1 parent 8c4f04f commit 433338d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,49 +46,45 @@ public void initialize(IdentitySchema constraintAnnotation) {

@Override
public boolean isValid(Object object, ConstraintValidatorContext context) {
context.disableDefaultConstraintViolation();
if (!(object instanceof RequestWrapper)) {
context.buildConstraintViolationWithTemplate("Invalid request type")
.addConstraintViolation();
return false;
}
RequestWrapper wrapper= (RequestWrapper) object;
Object requestObject = wrapper.getRequest();
if (!(requestObject instanceof IdentityData)) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate("Invalid request object type").addConstraintViolation();
return false;
}
IdentityData identityData=(IdentityData) requestObject;
JsonNode identityJsonNode = objectMapper.valueToTree(identityData);
Set<ValidationMessage> errors = getSchema().validate(identityJsonNode);
boolean isValid=true;
String errorName="";
String errorCode="";
if(!isCreate){
for(ValidationMessage validationMessage: errors){
String field=validationMessage.
getInstanceLocation().getName(0);
// Ignore validation errors with code 1029 (null value) for exempted fields when validating updateIdentity
if(!validationMessage.getCode().equals("1029") || !nonMandatoryFieldsOnUpdate.contains(field)){
errorName="invalid_"+field.toLowerCase();
errorCode="invalid_"+field.toLowerCase();
isValid=false;
break;
}
}
}else if(!errors.isEmpty()){
isValid=false;
}else{
isValid=errors.isEmpty();
}
if (!isValid) {
if(StringUtils.isEmpty(errorCode))
errorCode="invalid_"+errors.iterator().next().getInstanceLocation().getName(0).toLowerCase();
context.disableDefaultConstraintViolation();
if(StringUtils.isEmpty(errorName))
errorName="invalid_"+errors.iterator().next().getInstanceLocation().getName(0).toLowerCase();
context.buildConstraintViolationWithTemplate(errorName)
context.buildConstraintViolationWithTemplate(errorCode)
.addConstraintViolation();
log.error("Validation failed for IdentityData: {}", errors);
return false;
}
return true;
}

private JsonSchema getSchema() {
if(schema !=null ) return schema;
synchronized (this) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
##-----------------------------------------Mock-identity-system properties----------------------------------------------

mosip.mock.ida.identity.schema.url=classpath:/mock-identity-schema.json
mosip.mock.ida.update-identity.non-mandatory.fields={"fullName","name","givenName","familyName","middleName","nickName","preferredUsername","gender","streetAddress","locality","region","country","pin","preferredLang","dateOfBirth","postalCode","encodedPhoto","email","phone","zoneInfo","locale","password"}


##----------------------------------------- Database properties --------------------------------------------------------

spring.datasource.url=jdbc:postgresql://localhost:5432/mosip_mockidentitysystem?currentSchema=mockidentitysystem
Expand Down

0 comments on commit 433338d

Please sign in to comment.