Search in sources :

Example 36 with Validation

use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.

the class BaseModuleValidationService method validateSeparateMapping.

protected void validateSeparateMapping(Mapping mapping, List<Validation> validations) {
    if (mapping == null) {
        return;
    }
    final Field sourceField = mapping.getInputField() != null ? mapping.getInputField().get(0) : null;
    List<Field> targetFields = mapping.getOutputField();
    String mappingId = mapping.getId();
    if (getMode() == AtlasModuleMode.SOURCE && matchDocIdOrNull(sourceField.getDocId())) {
        // check that the input field is of type String else error
        if (sourceField.getFieldType() != FieldType.STRING) {
            Validation validation = new Validation();
            validation.setScope(ValidationScope.MAPPING);
            validation.setId(mapping.getId());
            validation.setMessage(String.format("Input field '%s' must be of type '%s' for a Separate Mapping", getFieldName(sourceField), FieldType.STRING));
            validation.setStatus(ValidationStatus.ERROR);
            validations.add(validation);
        }
        validateField(mappingId, sourceField, FieldDirection.SOURCE, validations);
        if (targetFields != null) {
            // we should convert per module validations to plugin style
            for (Field targetField : targetFields) {
                validateSourceAndTargetTypes(mappingId, sourceField, targetField, validations);
            }
        }
    } else if (targetFields != null) {
        // TARGET
        for (Field targetField : targetFields) {
            if (matchDocIdOrNull(targetField.getDocId())) {
                validateField(mappingId, targetField, FieldDirection.TARGET, validations);
            }
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Field(io.atlasmap.v2.Field)

Example 37 with Validation

use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.

the class BaseModuleValidationService method validateMapping.

@Override
public List<Validation> validateMapping(AtlasMapping mapping) {
    List<Validation> validations = new ArrayList<>();
    if (getMode() == AtlasModuleMode.UNSET) {
        Validation validation = new Validation();
        validation.setMessage(String.format("No mode specified for %s/%s, skipping module validations", this.getModuleDetail().name(), this.getClass().getSimpleName()));
    }
    if (mapping != null && mapping.getMappings() != null && mapping.getMappings().getMapping() != null && !mapping.getMappings().getMapping().isEmpty()) {
        validateMappingEntries(mapping.getMappings().getMapping(), validations);
    }
    boolean found = false;
    for (DataSource ds : mapping.getDataSource()) {
        if (ds.getUri() != null && ds.getUri().startsWith(getModuleDetail().uri())) {
            found = true;
            break;
        }
    }
    if (!found) {
        Validation validation = new Validation();
        validation.setScope(ValidationScope.DATA_SOURCE);
        validation.setMessage(String.format("No DataSource with '%s' uri specified", getModuleDetail().uri()));
        validation.setStatus(ValidationStatus.ERROR);
        validations.add(validation);
    }
    return validations;
}
Also used : Validation(io.atlasmap.v2.Validation) ArrayList(java.util.ArrayList) DataSource(io.atlasmap.v2.DataSource)

Example 38 with Validation

use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.

the class BaseModuleValidationService method validateMapMapping.

protected void validateMapMapping(Mapping mapping, List<Validation> validations) {
    Field sourceField = null;
    Field targetField = null;
    String mappingId = mapping.getId();
    if (mapping != null && mapping.getInputField() != null && mapping.getInputField().size() > 0) {
        sourceField = mapping.getInputField().get(0);
        if (getMode() == AtlasModuleMode.SOURCE && matchDocIdOrNull(sourceField.getDocId())) {
            validateField(mappingId, sourceField, FieldDirection.SOURCE, validations);
        }
    }
    if (mapping != null && mapping.getOutputField() != null && mapping.getOutputField().size() > 0) {
        targetField = mapping.getOutputField().get(0);
        if (getMode() == AtlasModuleMode.TARGET && matchDocIdOrNull(targetField.getDocId())) {
            validateField(mappingId, targetField, FieldDirection.TARGET, validations);
        }
    }
    if (sourceField != null && targetField != null && getMode() == AtlasModuleMode.SOURCE && matchDocIdOrNull(sourceField.getDocId())) {
        // FIXME Run only for SOURCE to avoid duplicate validation...
        // we should convert per module validations to plugin style
        validateSourceAndTargetTypes(mappingId, sourceField, targetField, validations);
    }
}
Also used : Field(io.atlasmap.v2.Field)

Example 39 with Validation

use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.

the class JsonValidationServiceTest method testValidateMappingInvalidCombineInputFieldType.

@Test
public void testValidateMappingInvalidCombineInputFieldType() {
    AtlasMapping atlasMapping = getAtlasMappingFullValid();
    Mapping combineFieldMapping = AtlasModelFactory.createMapping(MappingType.COMBINE);
    combineFieldMapping.setId("combine.firstName.lastName");
    JsonField bIJavaField = jsonModelFactory.createJsonField();
    bIJavaField.setFieldType(FieldType.STRING);
    bIJavaField.setValue(Boolean.TRUE);
    bIJavaField.setPath("firstName");
    combineFieldMapping.getInputField().add(bIJavaField);
    JsonField sOJavaField = jsonModelFactory.createJsonField();
    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) JsonField(io.atlasmap.json.v2.JsonField) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 40 with Validation

use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.

the class JsonValidationServiceTest method testValidateMappingInvalidSeparateInputFieldType.

@Test
public void testValidateMappingInvalidSeparateInputFieldType() {
    AtlasMapping atlasMapping = getAtlasMappingFullValid();
    Mapping separateFieldMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
    separateFieldMapping.setId("separate.firstName.lastName");
    JsonField bIJavaField = jsonModelFactory.createJsonField();
    bIJavaField.setFieldType(FieldType.BOOLEAN);
    bIJavaField.setValue(Boolean.TRUE);
    bIJavaField.setPath("firstName");
    separateFieldMapping.getInputField().add(bIJavaField);
    JsonField sOJavaField = jsonModelFactory.createJsonField();
    sOJavaField.setFieldType(FieldType.STRING);
    sOJavaField.setPath("lastName");
    sOJavaField.setIndex(0);
    separateFieldMapping.getOutputField().add(sOJavaField);
    atlasMapping.getMappings().getMapping().add(separateFieldMapping);
    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("separate.firstName.lastName", validation.getId());
    assertEquals("Input field 'firstName' must be of type 'STRING' for a Separate Mapping", validation.getMessage());
    assertEquals(ValidationStatus.ERROR, validation.getStatus());
}
Also used : Validation(io.atlasmap.v2.Validation) JsonField(io.atlasmap.json.v2.JsonField) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

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