use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class BaseModuleValidationService method populateConversionConcerns.
protected void populateConversionConcerns(String mappingId, AtlasConversionInfo converterAnno, String inputFieldName, String outFieldName, List<Validation> validations) {
if (converterAnno == null || converterAnno.concerns() == null) {
return;
}
for (AtlasConversionConcern atlasConversionConcern : converterAnno.concerns()) {
String message = atlasConversionConcern.getMessage(converterAnno);
if (AtlasConversionConcern.NONE.equals(atlasConversionConcern)) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
validation.setMessage(message);
validation.setStatus(ValidationStatus.INFO);
validations.add(validation);
} else if (atlasConversionConcern.equals(AtlasConversionConcern.RANGE) || atlasConversionConcern.equals(AtlasConversionConcern.FORMAT) || atlasConversionConcern.equals(AtlasConversionConcern.FRACTIONAL_PART) || atlasConversionConcern.equals(AtlasConversionConcern.TIMEZONE)) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
validation.setMessage(message);
validation.setStatus(ValidationStatus.WARN);
validations.add(validation);
} else if (atlasConversionConcern.equals(AtlasConversionConcern.UNSUPPORTED)) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
validation.setMessage(message);
validation.setStatus(ValidationStatus.ERROR);
validations.add(validation);
}
}
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class BaseModuleValidationService method validateField.
@SuppressWarnings("unchecked")
protected void validateField(String mappingId, Field field, FieldDirection direction, List<Validation> validations) {
if (field == null) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
validation.setMessage(String.format("%s field %s is null", direction.value(), getFieldName(field)));
validation.setStatus(ValidationStatus.ERROR);
validations.add(validation);
} else if (getFieldType().isAssignableFrom(field.getClass())) {
validateModuleField(mappingId, (T) field, direction, validations);
}
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class JavaValidationServiceTest method testValidateAtlasMappingFileConversionRequired.
@Test
public void testValidateAtlasMappingFileConversionRequired() throws Exception {
AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.xml");
assertNotNull(mapping);
Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
JavaField in = (JavaField) fieldMapping.getInputField().get(0);
in.setFieldType(FieldType.COMPLEX);
in.setClassName("io.atlasmap.java.module.MockJavaClass");
JavaField out = (JavaField) fieldMapping.getOutputField().get(0);
out.setFieldType(FieldType.STRING);
validations.addAll(sourceValidationService.validateMapping(mapping));
validations.addAll(targetValidationService.validateMapping(mapping));
assertFalse(validationHelper.hasErrors());
assertTrue(validationHelper.hasWarnings());
assertFalse(validationHelper.hasInfos());
assertThat(1, is(validationHelper.getCount()));
Validation v = validations.get(0);
assertEquals(ValidationScope.MAPPING, v.getScope());
assertEquals("map.firstName.firstName", v.getId());
assertEquals(ValidationStatus.WARN, v.getStatus());
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class JavaValidationService method validateClassConversion.
private void validateClassConversion(String mappingId, JavaField inputField, JavaField outField, List<Validation> validations) {
Optional<AtlasConverter<?>> atlasConverter = getConversionService().findMatchingConverter(inputField.getClassName(), outField.getClassName());
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.getClassName(), outField.getClassName()));
validation.setStatus(ValidationStatus.WARN);
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(inputField.getFieldType()) == 0 && atlasConversionInfo.targetType().compareTo(outField.getFieldType()) == 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 JavaJavaFlatMappingTest method testProcessJavaJavaFlatFieldMappingPrimitivesBoxedValues.
@Test
public void testProcessJavaJavaFlatFieldMappingPrimitivesBoxedValues() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-flatprimitive.xml").toURI());
AtlasSession session = context.createSession();
BaseFlatPrimitiveClass sourceClass = generateFlatPrimitiveClassPrimitiveFieldsBoxedValues(SourceFlatPrimitiveClass.class);
session.setDefaultSourceDocument(sourceClass);
context.process(session);
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof TargetFlatPrimitiveClass);
validateFlatPrimitiveClassPrimitiveFields((TargetFlatPrimitiveClass) object);
Validations validations = session.getValidations();
for (Validation v : validations.getValidation()) {
printValidation(v);
}
}
Aggregations