Search in sources :

Example 1 with FieldType

use of io.atlasmap.v2.FieldType in project atlasmap by atlasmap.

the class DefaultAtlasFieldActionService method internalProcessActions.

protected Field internalProcessActions(Actions actions, Object sourceObject, FieldType targetType) throws AtlasException {
    Field processedField = new SimpleField();
    processedField.setValue(sourceObject);
    processedField.setFieldType(targetType);
    if (FieldType.COMPLEX.equals(targetType)) {
        return processedField;
    }
    Object tmpSourceObject = sourceObject;
    FieldType sourceType = (sourceObject != null ? getConversionService().fieldTypeFromClass(sourceObject.getClass()) : FieldType.NONE);
    if (actions == null || actions.getActions() == null || actions.getActions().isEmpty()) {
        if (sourceObject == null) {
            return processedField;
        }
        processedField.setValue(getConversionService().convertType(sourceObject, sourceType, targetType));
        processedField.setFieldType(targetType);
        return processedField;
    }
    FieldType currentType = sourceType;
    for (Action action : actions.getActions()) {
        ActionDetail detail = findActionDetail(action.getDisplayName(), currentType);
        if (!detail.getSourceType().equals(currentType) && !FieldType.ANY.equals(detail.getSourceType())) {
            tmpSourceObject = getConversionService().convertType(sourceObject, currentType, detail.getSourceType());
        }
        processedField.setValue(processAction(action, detail, tmpSourceObject));
        processedField.setFieldType(detail.getTargetType());
        currentType = detail.getTargetType();
    }
    return processedField;
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) AtlasFieldAction(io.atlasmap.api.AtlasFieldAction) Action(io.atlasmap.v2.Action) ActionDetail(io.atlasmap.v2.ActionDetail) SimpleField(io.atlasmap.v2.SimpleField) FieldType(io.atlasmap.v2.FieldType)

Example 2 with FieldType

use of io.atlasmap.v2.FieldType in project atlasmap by atlasmap.

the class XmlFieldWriterTest method readFromFile.

private AtlasInternalSession readFromFile(String fieldPath, FieldType fieldType, Path path) throws Exception {
    String input = new String(Files.readAllBytes(path));
    reader.setDocument(input, false);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath(fieldPath);
    xmlField.setPrimitive(Boolean.TRUE);
    xmlField.setFieldType(fieldType);
    assertNull(xmlField.getValue());
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    reader.read(session);
    return session;
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField)

Example 3 with FieldType

use of io.atlasmap.v2.FieldType in project atlasmap by atlasmap.

the class DefaultAtlasConversionServiceTest method findMatchingConverterByFieldTypes.

@Test
public void findMatchingConverterByFieldTypes() {
    assertNotNull(service);
    Optional<AtlasConverter<?>> atlasConverter = service.findMatchingConverter(FieldType.STRING, FieldType.BOOLEAN);
    assertTrue(atlasConverter.isPresent());
    assertNotNull(atlasConverter);
    assertEquals(StringConverter.class, atlasConverter.get().getClass());
    StringConverter stringConverter = (StringConverter) atlasConverter.get();
    assertNotNull(stringConverter);
    assertThat("io.atlasmap.converters.StringConverter", is(atlasConverter.get().getClass().getCanonicalName()));
    Boolean t = stringConverter.toBoolean("T", null, null);
    assertNotNull(t);
    assertTrue(t);
    Boolean f = stringConverter.toBoolean("F", null, null);
    assertNotNull(f);
    assertFalse(f);
    service.findMatchingConverter(null, FieldType.BOOLEAN);
    service.findMatchingConverter(FieldType.STRING, null);
    FieldType fieldType = null;
    service.findMatchingConverter(fieldType, fieldType);
}
Also used : AtlasConverter(io.atlasmap.api.AtlasConverter) StringConverter(io.atlasmap.converters.StringConverter) FieldType(io.atlasmap.v2.FieldType) Test(org.junit.Test)

Example 4 with FieldType

use of io.atlasmap.v2.FieldType in project atlasmap by atlasmap.

the class XmlFieldReaderTest method readFromFile.

private AtlasInternalSession readFromFile(String fieldPath, FieldType fieldType, Path path) throws Exception {
    String input = new String(Files.readAllBytes(path));
    reader.setDocument(input, false);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath(fieldPath);
    xmlField.setPrimitive(Boolean.TRUE);
    xmlField.setFieldType(fieldType);
    assertNull(xmlField.getValue());
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    reader.read(session);
    return session;
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField)

Example 5 with FieldType

use of io.atlasmap.v2.FieldType in project atlasmap by atlasmap.

the class BaseDefaultAtlasContextTest method populateSourceField.

protected Field populateSourceField(Mapping mapping, FieldType type, Object value) {
    Field field = new SimpleField();
    field.setFieldType(type);
    field.setPath("/testPath" + value);
    mapping.getInputField().add(field);
    reader.sources.put(field.getPath(), value);
    return field;
}
Also used : SimpleField(io.atlasmap.v2.SimpleField) Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField)

Aggregations

FieldType (io.atlasmap.v2.FieldType)13 Field (io.atlasmap.v2.Field)8 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)6 SimpleField (io.atlasmap.v2.SimpleField)6 Test (org.junit.Test)4 Head (io.atlasmap.spi.AtlasInternalSession.Head)3 Audits (io.atlasmap.v2.Audits)3 XmlField (io.atlasmap.xml.v2.XmlField)3 Path (java.nio.file.Path)3 AtlasConverter (io.atlasmap.api.AtlasConverter)2 AtlasException (io.atlasmap.api.AtlasException)2 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)2 JavaField (io.atlasmap.java.v2.JavaField)2 Method (java.lang.reflect.Method)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 XSAttributeDecl (com.sun.xml.xsom.XSAttributeDecl)1 XSAttributeUse (com.sun.xml.xsom.XSAttributeUse)1 XSSimpleType (com.sun.xml.xsom.XSSimpleType)1 AtlasConversionException (io.atlasmap.api.AtlasConversionException)1 AtlasConversionService (io.atlasmap.api.AtlasConversionService)1