Source:
public boolean isValid(DataSample record, ConstraintValidatorContext context) { uk.gov.ea.datareturns.domain.model.fields.impl.ReturnType returnType = record.getReturnType(); uk.gov.ea.datareturns.domain.model.fields.impl.Parameter parameter = record.getParameter(); uk.gov.ea.datareturns.domain.model.fields.impl.Unit unit = record.getUnit(); ReturnType returnTypeEntity = (returnType != null) ? returnType.getEntity() : null; ReleasesAndTransfers releasesAndTransfersEntity = null; Parameter parameterEntity = (parameter != null) ? parameter.getEntity() : null; Unit unitEntity = (unit != null) ? unit.getEntity() : null; DependencyValidation dependencyValidation = SpringApplicationContextProvider.getApplicationContext().getBean(DependencyValidation.class); Pair<ControlledListsList, DependencyValidation.Result> validation = dependencyValidation.validate(returnTypeEntity, releasesAndTransfersEntity, parameterEntity, unitEntity); String message = null; DependencyValidation.Result result = validation.getRight(); ControlledListsList level = validation.getLeft(); if (result == DependencyValidation.Result.OK) { return true; } else { if (result == DependencyValidation.Result.EXPECTED && level != ControlledListsList.RELEASES_AND_TRANSFERS) { return true; } else { switch (level) { case UNITS: message = MessageCodes.DependencyConflict.Unit; break; case PARAMETERS: message = MessageCodes.DependencyConflict.Parameter; break; case RELEASES_AND_TRANSFERS: message = null; break; case RETURN_TYPE: message = MessageCodes.DependencyConflict.Rtn_Type; break; } } } if (message != null) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); } return false; }

Target:
public boolean isValid(DataSample record, ConstraintValidatorContext context) { ReturnType returnTypeEntity = AbstractEntityValue.getEntity(record.getReturnType()); ReleasesAndTransfers releasesAndTransfersEntity = null; Parameter parameterEntity = AbstractEntityValue.getEntity(record.getParameter()); Unit unitEntity = AbstractEntityValue.getEntity(record.getUnit()); DependencyValidation dependencyValidation = SpringApplicationContextProvider.getApplicationContext().getBean(DependencyValidation.class); Pair<ControlledListsList, DependencyValidation.Result> validation = dependencyValidation.validate(returnTypeEntity, releasesAndTransfersEntity, parameterEntity, unitEntity); String message = null; DependencyValidation.Result result = validation.getRight(); ControlledListsList level = validation.getLeft(); if (result == DependencyValidation.Result.OK) { return true; } else { if (result == DependencyValidation.Result.EXPECTED && level != ControlledListsList.RELEASES_AND_TRANSFERS) { return true; } else { switch (level) { case UNITS: message = MessageCodes.DependencyConflict.Unit; break; case PARAMETERS: message = MessageCodes.DependencyConflict.Parameter; break; case RELEASES_AND_TRANSFERS: message = null; break; case RETURN_TYPE: message = MessageCodes.DependencyConflict.Rtn_Type; break; } } } if (message != null) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); } return false; }