use of io.atlasmap.spi.AtlasConversionInfo in project atlasmap by atlasmap.
the class IntegerConverterTest method checkAnnotations.
@Test
public void checkAnnotations() throws Exception {
Class<?> aClass = IntegerConverter.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.INTEGER) == 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 LongConverterTest method checkAnnotations.
@Test
public void checkAnnotations() throws Exception {
Class<?> aClass = LongConverter.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.LONG) == 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 MappingFieldPairValidator method doValidateFieldTypes.
/**
* Validates field types.
* @param validations a container to put the result {@link Validation}.
* @param mappingId mapping ID
* @param sourceField source field
* @param targetField target field
* @param sourceFieldType source field type
*/
protected void doValidateFieldTypes(List<Validation> validations, String mappingId, Field sourceField, Field targetField, FieldType sourceFieldType) {
if (sourceField == null && targetField == null || sourceField.getFieldType() == targetField.getFieldType()) {
return;
}
FieldType targetFieldType = targetField.getFieldType();
if (sourceFieldType == null || targetFieldType == null) {
return;
}
if (sourceFieldType == FieldType.ANY || targetFieldType == FieldType.ANY) {
return;
}
// skip converter check for COMPLEX source field (possible for conditional mapping)
if (sourceField.getFieldType() == FieldType.COMPLEX) {
return;
}
Optional<AtlasConverter<?>> atlasConverter = service.getConversionService().findMatchingConverter(sourceFieldType, targetFieldType);
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", sourceField.getFieldType(), targetField.getFieldType()));
validation.setStatus(ValidationStatus.ERROR);
validations.add(validation);
} else {
AtlasConversionInfo conversionInfo;
// find the method that does the conversion
FieldType sft = sourceFieldType;
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(sft) == 0 && atlasConversionInfo.targetType().compareTo(targetFieldType) == 0)).findFirst().orElse(null);
if (conversionInfo != null) {
populateConversionConcerns(validations, mappingId, conversionInfo, service.getFieldName(sourceField), service.getFieldName(targetField));
}
}
}
use of io.atlasmap.spi.AtlasConversionInfo in project atlasmap by atlasmap.
the class BooleanConverterTest method checkAnnotations.
@Test
public void checkAnnotations() throws Exception {
Class<?> aClass = BooleanConverter.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.BOOLEAN) == 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 CharSequenceConverter method toShort.
/**
* Converts to {@link Short}.
* @param value value
* @return converted
* @throws AtlasConversionException out of range or not a number
*/
@AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.SHORT, concerns = { AtlasConversionConcern.FORMAT, AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART })
public Short toShort(CharSequence value) throws AtlasConversionException {
if (value == null) {
return null;
}
String str = value.toString();
Short shortty = null;
try {
shortty = Short.parseShort(str);
} catch (NumberFormatException nfe) {
try {
BigDecimal bd = new BigDecimal(str);
if (bd.compareTo(new BigDecimal(Short.MIN_VALUE)) < 0 || bd.compareTo(new BigDecimal(Short.MAX_VALUE)) > 0) {
throw new AtlasConversionException(String.format("String %s is greater than Short.MAX_VALUE or less than Short.MIN_VALUE", str));
}
shortty = bd.shortValue();
} catch (NumberFormatException nfe2) {
throw new AtlasConversionException(nfe2);
}
}
return shortty;
}
Aggregations