use of io.atlasmap.spi.AtlasConversionInfo in project atlasmap by atlasmap.
the class DoubleConverterTest method checkAnnotations.
@Test
public void checkAnnotations() throws Exception {
Class<?> aClass = DoubleConverter.class;
Method[] methods = aClass.getMethods();
for (Method method : methods) {
if (method.isSynthetic()) {
// We are running in Eclipse or jacoco
continue;
}
if (method.getName().startsWith("convert")) {
Annotation[] annotations = method.getDeclaredAnnotations();
assertNotNull(annotations);
assertTrue(annotations.length > 0);
for (Annotation annotation : annotations) {
assertTrue(AtlasConversionInfo.class.isAssignableFrom(annotation.annotationType()));
AtlasConversionInfo atlasConversionInfo = (AtlasConversionInfo) annotation;
assertNotNull(atlasConversionInfo.sourceType());
assertTrue(atlasConversionInfo.sourceType().compareTo(FieldType.DOUBLE) == 0);
assertNotNull(atlasConversionInfo.targetType());
for (AtlasConversionConcern atlasConversionConcern : atlasConversionInfo.concerns()) {
assertNotNull(atlasConversionConcern.getMessage(atlasConversionInfo));
assertNotNull(atlasConversionConcern.value());
}
}
}
}
}
use of io.atlasmap.spi.AtlasConversionInfo in project atlasmap by atlasmap.
the class JavaMappingFieldPairValidator method validateClassConversion.
private void validateClassConversion(String mappingId, JavaField inputField, JavaField outField, List<Validation> validations) {
// skip converter check for COMPLEX source field (possible for conditional mapping)
if (inputField.getFieldType() == FieldType.COMPLEX) {
return;
}
Optional<AtlasConverter<?>> atlasConverter = conversionService.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.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(inputField.getFieldType()) == 0 && atlasConversionInfo.targetType().compareTo(outField.getFieldType()) == 0).findFirst().orElse(null);
if (conversionInfo != null) {
populateConversionConcerns(validations, mappingId, conversionInfo, service.getModuleFieldName(inputField), service.getModuleFieldName(outField));
}
}
}
use of io.atlasmap.spi.AtlasConversionInfo in project atlasmap by atlasmap.
the class FloatConverterTest method checkAnnotations.
@Test
public void checkAnnotations() throws Exception {
Class<?> aClass = FloatConverter.class;
Method[] methods = aClass.getMethods();
for (Method method : methods) {
if (method.isSynthetic()) {
// We are running in Eclipse or jacoco
continue;
}
if (method.getName().startsWith("convert")) {
Annotation[] annotations = method.getDeclaredAnnotations();
assertNotNull(annotations);
assertTrue(annotations.length > 0);
for (Annotation annotation : annotations) {
assertTrue(AtlasConversionInfo.class.isAssignableFrom(annotation.annotationType()));
AtlasConversionInfo atlasConversionInfo = (AtlasConversionInfo) annotation;
assertNotNull(atlasConversionInfo.sourceType());
assertTrue(atlasConversionInfo.sourceType().compareTo(FieldType.FLOAT) == 0);
assertNotNull(atlasConversionInfo.targetType());
for (AtlasConversionConcern atlasConversionConcern : atlasConversionInfo.concerns()) {
assertNotNull(atlasConversionConcern.getMessage(atlasConversionInfo));
assertNotNull(atlasConversionConcern.value());
}
}
}
}
}
use of io.atlasmap.spi.AtlasConversionInfo 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.spi.AtlasConversionInfo in project atlasmap by atlasmap.
the class StringConverter method toLong.
@AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.LONG, concerns = { AtlasConversionConcern.FORMAT, AtlasConversionConcern.RANGE })
public Long toLong(String value) throws AtlasConversionException {
if (value == null) {
return null;
}
BigDecimal bd = null;
Long l = null;
try {
l = Long.parseLong(value);
} catch (NumberFormatException nfe) {
try {
bd = new BigDecimal(value);
l = bd.longValue();
} catch (NumberFormatException nfe2) {
throw new AtlasConversionException(nfe);
}
}
if (bd != null && bd.compareTo(BigDecimal.valueOf(l)) != 0) {
throw new AtlasConversionException(String.format("String %s is greater than Long.MAX_VALUE or less than Long.MIN_VALUE", value));
}
return l;
}
Aggregations