use of io.atlasmap.v2.Validations in project atlasmap by atlasmap.
the class XmlValidationServiceTest method testValidateMappingSourceToTargetRangeConcerns.
@Test
public void testValidateMappingSourceToTargetRangeConcerns() throws Exception {
AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.xml");
assertNotNull(mapping);
Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
XmlField in = (XmlField) fieldMapping.getInputField().get(0);
in.setFieldType(FieldType.DOUBLE);
XmlField out = (XmlField) fieldMapping.getOutputField().get(0);
out.setFieldType(FieldType.LONG);
validations.addAll(sourceValidationService.validateMapping(mapping));
validations.addAll(targetValidationService.validateMapping(mapping));
if (LOG.isDebugEnabled()) {
debugErrors(validations);
}
assertFalse(validationHelper.hasErrors());
assertTrue(validationHelper.hasWarnings());
assertFalse(validationHelper.hasInfos());
assertThat(1, is(validationHelper.getCount()));
assertTrue(validations.stream().anyMatch(atlasMappingError -> atlasMappingError.getMessage().contains("range")));
}
use of io.atlasmap.v2.Validations 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.Validations 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.Validations 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);
}
}
}
}
use of io.atlasmap.v2.Validations 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);
}
}
}
}
Aggregations