Search in sources :

Example 31 with Validation

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);
}
Also used : Validation(io.atlasmap.v2.Validation) Validations(io.atlasmap.v2.Validations) Test(org.junit.Test)

Example 32 with Validation

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());
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasMapping(io.atlasmap.v2.AtlasMapping) XmlField(io.atlasmap.xml.v2.XmlField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 33 with Validation

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());
    }
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasModule(io.atlasmap.spi.AtlasModule) AtlasException(io.atlasmap.api.AtlasException)

Example 34 with Validation

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);
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Arrays(java.util.Arrays) FieldDirection(io.atlasmap.spi.FieldDirection) ValidationScope(io.atlasmap.v2.ValidationScope) DataSource(io.atlasmap.v2.DataSource) MappingType(io.atlasmap.v2.MappingType) AtlasConversionInfo(io.atlasmap.spi.AtlasConversionInfo) ValidationStatus(io.atlasmap.v2.ValidationStatus) AtlasConversionConcern(io.atlasmap.spi.AtlasConversionConcern) FieldType(io.atlasmap.v2.FieldType) Validation(io.atlasmap.v2.Validation) ArrayList(java.util.ArrayList) Mapping(io.atlasmap.v2.Mapping) List(java.util.List) Field(io.atlasmap.v2.Field) AtlasModuleDetail(io.atlasmap.spi.AtlasModuleDetail) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasModuleMode(io.atlasmap.spi.AtlasModuleMode) Optional(java.util.Optional) AtlasConversionService(io.atlasmap.api.AtlasConversionService) Method(java.lang.reflect.Method) BaseMapping(io.atlasmap.v2.BaseMapping) AtlasConverter(io.atlasmap.api.AtlasConverter) AtlasValidationService(io.atlasmap.api.AtlasValidationService) AtlasConversionInfo(io.atlasmap.spi.AtlasConversionInfo) AtlasConverter(io.atlasmap.api.AtlasConverter) Method(java.lang.reflect.Method) FieldType(io.atlasmap.v2.FieldType)

Example 35 with Validation

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);
            }
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Field(io.atlasmap.v2.Field)

Aggregations

Validation (io.atlasmap.v2.Validation)39 AtlasMapping (io.atlasmap.v2.AtlasMapping)17 Test (org.junit.Test)17 Mapping (io.atlasmap.v2.Mapping)14 Field (io.atlasmap.v2.Field)7 BaseMapping (io.atlasmap.v2.BaseMapping)6 JavaField (io.atlasmap.java.v2.JavaField)5 Validations (io.atlasmap.v2.Validations)5 DataSource (io.atlasmap.v2.DataSource)3 ArrayList (java.util.ArrayList)3 AtlasConversionService (io.atlasmap.api.AtlasConversionService)2 AtlasConverter (io.atlasmap.api.AtlasConverter)2 AtlasException (io.atlasmap.api.AtlasException)2 JsonField (io.atlasmap.json.v2.JsonField)2 AtlasConversionConcern (io.atlasmap.spi.AtlasConversionConcern)2 AtlasConversionInfo (io.atlasmap.spi.AtlasConversionInfo)2 AtlasModule (io.atlasmap.spi.AtlasModule)2 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)2 FieldDirection (io.atlasmap.spi.FieldDirection)2 FieldType (io.atlasmap.v2.FieldType)2