use of io.atlasmap.v2.FieldType in project atlasmap by atlasmap.
the class XmlFieldReaderTest method testXmlFieldDoubleMinRangeOut.
@Test
public void testXmlFieldDoubleMinRangeOut() throws Exception {
String fieldPath = "/primitive/value";
FieldType fieldType = FieldType.DOUBLE;
Path path = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "xmlFields" + File.separator + "test-read-field-double-min-range-out.xml");
AtlasInternalSession session = readFromFile(fieldPath, fieldType, path);
assertEquals(0.0, session.head().getSourceField().getValue());
assertEquals(0, session.getAudits().getAudit().size());
}
use of io.atlasmap.v2.FieldType in project atlasmap by atlasmap.
the class XmlFieldReaderTest method testXmlFieldFloatMinRangeOut.
@Test
public void testXmlFieldFloatMinRangeOut() throws Exception {
String fieldPath = "/primitive/value";
FieldType fieldType = FieldType.FLOAT;
Path path = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "xmlFields" + File.separator + "test-read-field-float-min-range-out.xml");
AtlasInternalSession session = readFromFile(fieldPath, fieldType, path);
assertEquals(0.0f, session.head().getSourceField().getValue());
assertEquals(0, session.getAudits().getAudit().size());
}
use of io.atlasmap.v2.FieldType in project atlasmap by atlasmap.
the class BaseAtlasModule method processLookupField.
protected void processLookupField(AtlasInternalSession session, LookupTable lookupTable, Object sourceValue, Field targetField) throws AtlasException {
String lookupValue = null;
FieldType lookupType = null;
for (LookupEntry lkp : lookupTable.getLookupEntry()) {
if (lkp.getSourceValue().equals(sourceValue)) {
lookupValue = lkp.getTargetValue();
lookupType = lkp.getTargetType();
break;
}
}
Object targetValue = null;
if (lookupType == null || FieldType.STRING.equals(lookupType)) {
targetValue = lookupValue;
} else {
targetValue = atlasConversionService.convertType(lookupValue, FieldType.STRING, lookupType);
}
if (targetField.getFieldType() != null && !targetField.getFieldType().equals(lookupType)) {
targetValue = atlasConversionService.convertType(targetValue, lookupType, targetField.getFieldType());
}
targetField.setValue(targetValue);
}
use of io.atlasmap.v2.FieldType 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.FieldType in project atlasmap by atlasmap.
the class SchemaInspector method printAttributes.
private void printAttributes(XSComplexType xsComplexType, String rootName, XmlComplexType xmlComplexType) {
Collection<? extends XSAttributeUse> c = xsComplexType.getDeclaredAttributeUses();
for (XSAttributeUse aC : c) {
XmlField xmlField = AtlasXmlModelFactory.createXmlField();
XSAttributeDecl attributeDecl = aC.getDecl();
xmlField.setName(getNameNS(attributeDecl));
if (attributeDecl.getDefaultValue() != null) {
xmlField.setValue(attributeDecl.getDefaultValue().value);
} else if (attributeDecl.getFixedValue() != null) {
xmlField.setValue(attributeDecl.getFixedValue().value);
}
xmlField.setPath(rootName + "/" + "@" + getNameNS(attributeDecl));
FieldType attrType = getFieldType(attributeDecl.getType().getName());
xmlField.setFieldType(attrType);
if (xmlField.getFieldType() == null) {
// check the simple types in the schema....
XSSimpleType simpleType = xsComplexType.getRoot().getSimpleType(xsComplexType.getTargetNamespace(), attributeDecl.getType().getName());
if (simpleType != null) {
FieldType fieldType = getFieldType(simpleType.getBaseType().getName());
xmlField.setFieldType(fieldType);
xmlField.setTypeName(attributeDecl.getType().getName());
if (simpleType.asRestriction() != null) {
mapRestrictions(xmlField, simpleType.asRestriction());
}
} else {
// cannot figure it out....
xmlField.setFieldType(FieldType.UNSUPPORTED);
}
}
xmlComplexType.getXmlFields().getXmlField().add(xmlField);
}
}
Aggregations