use of io.atlasmap.java.v2.JavaField in project atlasmap by atlasmap.
the class JavaValidationServiceTest 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);
JavaField in = (JavaField) fieldMapping.getInputField().get(0);
in.setFieldType(FieldType.DOUBLE);
in.setClassName("java.lang.Double");
JavaField out = (JavaField) fieldMapping.getOutputField().get(0);
out.setFieldType(FieldType.LONG);
out.setClassName("java.lang.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.java.v2.JavaField 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.java.v2.JavaField in project atlasmap by atlasmap.
the class MapTest method testInspectJavaMapField.
@Test
public void testInspectJavaMapField() {
JavaClass c = classInspectionService.inspectClass(TestMapOrders.class);
assertNotNull(c);
assertEquals("io.atlasmap.java.test.TestMapOrders", c.getClassName());
assertNotNull(c.getJavaFields().getJavaField());
assertEquals(c.getJavaFields().getJavaField().size(), 1);
JavaField field = c.getJavaFields().getJavaField().get(0);
assertEquals(field.getCollectionType().value(), "Map");
}
use of io.atlasmap.java.v2.JavaField in project atlasmap by atlasmap.
the class TestListOrdersTest method testInspectJavaList.
@Test
public void testInspectJavaList() {
JavaClass c = classInspectionService.inspectClass(TestListOrders.class);
assertNotNull(c);
assertNull(c.getAnnotations());
assertNull(c.getArrayDimensions());
assertEquals("io.atlasmap.java.test.TestListOrders", c.getClassName());
assertNull(c.getCollectionClassName());
assertNull(c.getCollectionType());
assertNull(c.getGetMethod());
assertNotNull(c.getJavaEnumFields());
assertNotNull(c.getJavaEnumFields().getJavaEnumField());
assertEquals(Integer.valueOf(0), Integer.valueOf(c.getJavaEnumFields().getJavaEnumField().size()));
assertNotNull(c.getJavaFields());
assertNotNull(c.getJavaFields().getJavaField());
assertNull(c.getName());
assertEquals("io.atlasmap.java.test", c.getPackageName());
assertNull(c.getSetMethod());
assertNull(c.getFieldType());
assertNotNull(c.getUri());
assertEquals(String.format(AtlasJavaModelFactory.URI_FORMAT, "io.atlasmap.java.test.TestListOrders"), c.getUri());
assertNull(c.getValue());
assertEquals(Integer.valueOf(2), new Integer(c.getJavaFields().getJavaField().size()));
JavaField f1 = c.getJavaFields().getJavaField().get(0);
assertNotNull(f1);
assertTrue(f1 instanceof JavaClass);
JavaClass c2 = (JavaClass) f1;
assertNotNull(c2.getCollectionClassName());
assertEquals("java.util.List", c2.getCollectionClassName());
assertEquals(CollectionType.LIST, c2.getCollectionType());
boolean foundAddress = false;
boolean foundContact = false;
boolean foundCreated = false;
for (JavaField c2f : c2.getJavaFields().getJavaField()) {
if (c2f instanceof JavaClass) {
if ("io.atlasmap.java.test.BaseAddress".equals(((JavaClass) c2f).getClassName())) {
ClassValidationUtil.validateSimpleTestAddress(((JavaClass) c2f));
foundAddress = true;
} else if ("io.atlasmap.java.test.BaseContact".equals(((JavaClass) c2f).getClassName())) {
ClassValidationUtil.validateSimpleTestContact(((JavaClass) c2f));
foundContact = true;
} else if ("java.util.Date".equals(((JavaClass) c2f).getClassName())) {
ClassValidationUtil.validateCreated(c2f);
foundCreated = true;
} else {
fail("Unexpected class: " + ((JavaClass) c2f).getClassName());
}
} else if ("java.util.Date".equals(c2f.getClassName())) {
ClassValidationUtil.validateCreated(c2f);
foundCreated = true;
}
}
assertTrue(foundAddress);
assertTrue(foundContact);
assertTrue(foundCreated);
}
use of io.atlasmap.java.v2.JavaField in project atlasmap by atlasmap.
the class DocumentJavaFieldReader method read.
@Override
public void read(AtlasInternalSession session) throws AtlasException {
try {
Field sourceField = session.head().getSourceField();
Method getter = null;
if (sourceField.getFieldType() == null && (sourceField instanceof JavaField || sourceField instanceof JavaEnumField)) {
getter = resolveGetMethod(sourceDocument, sourceField);
if (getter == null) {
AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Unable to auto-detect sourceField type path=%s docId=%s", sourceField.getPath(), sourceField.getDocId()), sourceField.getPath(), AuditStatus.WARN, null);
return;
}
Class<?> returnType = getter.getReturnType();
sourceField.setFieldType(conversionService.fieldTypeFromClass(returnType));
if (LOG.isTraceEnabled()) {
LOG.trace("Auto-detected sourceField type p=" + sourceField.getPath() + " t=" + sourceField.getFieldType());
}
}
populateSourceFieldValue(session, sourceField, sourceDocument, getter);
if (LOG.isDebugEnabled()) {
LOG.debug("Processed input field sPath=" + sourceField.getPath() + " sV=" + sourceField.getValue() + " sT=" + sourceField.getFieldType() + " docId: " + sourceField.getDocId());
}
} catch (Exception e) {
throw new AtlasException(e);
}
}
Aggregations