use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class DefaultAtlasSessionTest method testGetSetValidations.
@Test
public void testGetSetValidations() {
assertNotNull(session.getValidations());
assertNotNull(session.getValidations().getValidation());
assertTrue(session.getValidations().getValidation().size() == 0);
Validations validations = new Validations();
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId("bar");
validations.getValidation().add(validation);
session.setValidations(validations);
assertNotNull(session.getValidations());
assertNotNull(session.getValidations().getValidation());
assertTrue(session.getValidations().getValidation().size() == 1);
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class XmlValidationServiceTest method testValidateMappingInvalidCombineInputFieldType.
@Test
public void testValidateMappingInvalidCombineInputFieldType() {
AtlasMapping atlasMapping = getAtlasMappingFullValid();
Mapping combineFieldMapping = AtlasModelFactory.createMapping(MappingType.COMBINE);
combineFieldMapping.setId("combine.firstName.lastName");
XmlField bIJavaField = xmlModelFactory.createXmlField();
bIJavaField.setFieldType(FieldType.STRING);
bIJavaField.setValue(Boolean.TRUE);
bIJavaField.setPath("firstName");
combineFieldMapping.getInputField().add(bIJavaField);
XmlField sOJavaField = xmlModelFactory.createXmlField();
sOJavaField.setFieldType(FieldType.BOOLEAN);
sOJavaField.setPath("lastName");
sOJavaField.setIndex(0);
combineFieldMapping.getOutputField().add(sOJavaField);
atlasMapping.getMappings().getMapping().add(combineFieldMapping);
validations.addAll(sourceValidationService.validateMapping(atlasMapping));
validations.addAll(targetValidationService.validateMapping(atlasMapping));
assertTrue(validationHelper.hasErrors());
assertFalse(validationHelper.hasWarnings());
assertFalse(validationHelper.hasInfos());
assertEquals(new Integer(1), new Integer(validationHelper.getCount()));
Validation validation = validations.get(0);
assertNotNull(validation);
assertEquals(ValidationScope.MAPPING, validation.getScope());
assertEquals("combine.firstName.lastName", validation.getId());
assertEquals("Output field 'lastName' must be of type 'STRING' for a Combine Mapping", validation.getMessage());
assertEquals(ValidationStatus.ERROR, validation.getStatus());
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class DefaultAtlasContext method processValidation.
@Override
public void processValidation(AtlasSession userSession) throws AtlasException {
if (!(userSession instanceof DefaultAtlasSession)) {
throw new AtlasException(String.format("Unsupported session class '%s'", userSession.getClass().getName()));
}
if (!this.equals(userSession.getAtlasContext())) {
throw new AtlasException("Cannot execute AtlasSession created by the other AtlasContext");
}
DefaultAtlasSession session = (DefaultAtlasSession) userSession;
if (LOG.isDebugEnabled()) {
LOG.debug("Begin processValidation {}", session == null ? null : session.toString());
}
List<Validation> validations = getContextFactory().getValidationService().validateMapping(session.getMapping());
if (validations != null && !validations.isEmpty()) {
session.getValidations().getValidation().addAll(validations);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Detected {} core validation notices", validations.size());
}
for (AtlasModule module : getSourceModules().values()) {
module.processPreValidation(session);
}
for (AtlasModule module : getTargetModules().values()) {
module.processPreValidation(session);
}
if (LOG.isDebugEnabled()) {
LOG.debug("End processValidation {}", session == null ? null : session.toString());
}
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class BaseModuleValidationService method validateFieldTypeConversion.
protected void validateFieldTypeConversion(String mappingId, Field inputField, Field outField, List<Validation> validations) {
FieldType inFieldType = inputField.getFieldType();
FieldType outFieldType = outField.getFieldType();
Optional<AtlasConverter<?>> atlasConverter = conversionService.findMatchingConverter(inFieldType, outFieldType);
if (!atlasConverter.isPresent()) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
validation.setMessage(String.format("Conversion from '%s' to '%s' is required but no converter is available", inputField.getFieldType(), outField.getFieldType()));
validation.setStatus(ValidationStatus.ERROR);
validations.add(validation);
} else {
AtlasConversionInfo conversionInfo;
// find the method that does the conversion
Method[] methods = atlasConverter.get().getClass().getMethods();
conversionInfo = Arrays.stream(methods).map(method -> method.getAnnotation(AtlasConversionInfo.class)).filter(atlasConversionInfo -> atlasConversionInfo != null).filter(atlasConversionInfo -> (atlasConversionInfo.sourceType().compareTo(inFieldType) == 0 && atlasConversionInfo.targetType().compareTo(outFieldType) == 0)).findFirst().orElse(null);
if (conversionInfo != null) {
populateConversionConcerns(mappingId, conversionInfo, getFieldName(inputField), getFieldName(outField), validations);
}
}
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class BaseModuleValidationService method validateCombineMapping.
protected void validateCombineMapping(Mapping mapping, List<Validation> validations) {
if (mapping == null) {
return;
}
List<Field> sourceFields = mapping.getInputField();
Field targetField = mapping.getOutputField() != null ? mapping.getOutputField().get(0) : null;
String mappingId = mapping.getId();
if (getMode() == AtlasModuleMode.TARGET && matchDocIdOrNull(targetField.getDocId())) {
if (sourceFields != null) {
// we should convert per module validations to plugin style
for (Field sourceField : sourceFields) {
validateSourceAndTargetTypes(mappingId, sourceField, targetField, validations);
}
}
// check that the output field is of type String else error
if (targetField.getFieldType() != FieldType.STRING) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
validation.setMessage(String.format("Output field '%s' must be of type '%s' for a Combine Mapping", getFieldName(targetField), FieldType.STRING));
validation.setStatus(ValidationStatus.ERROR);
validations.add(validation);
}
validateField(mappingId, targetField, FieldDirection.TARGET, validations);
} else if (sourceFields != null) {
// SOURCE
for (Field sourceField : sourceFields) {
if (matchDocIdOrNull(sourceField.getDocId())) {
validateField(mappingId, sourceField, FieldDirection.SOURCE, validations);
}
}
}
}
Aggregations