Search in sources :

Example 61 with Field

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

the class DefaultAtlasFieldActionsServiceTest method testProcessActionsActionsField.

@Test
public void testProcessActionsActionsField() throws AtlasException {
    Actions actions = null;
    SimpleField field = new SimpleField();
    field.setFieldType(FieldType.COMPLEX);
    fieldActionsService.processActions(actions, field);
    field.setValue(null);
    field.setFieldType(FieldType.INTEGER);
    fieldActionsService.processActions(actions, field);
    field.setValue(new Integer(0));
    field.setFieldType(FieldType.INTEGER);
    fieldActionsService.processActions(actions, field);
    @SuppressWarnings("serial")
    class MockActions extends Actions {

        @Override
        public List<Action> getActions() {
            return null;
        }
    }
    fieldActionsService.processActions(new MockActions(), field);
    actions = new Actions();
    fieldActionsService.processActions(actions, field);
    actions.getActions().add(new Trim());
    field.setValue("testString");
    field.setFieldType(FieldType.STRING);
    fieldActionsService.processActions(actions, field);
    field.setValue(new Integer(8));
    field.setFieldType(FieldType.NUMBER);
    fieldActionsService.processActions(actions, field);
}
Also used : Action(io.atlasmap.v2.Action) Actions(io.atlasmap.v2.Actions) Trim(io.atlasmap.v2.Trim) SimpleField(io.atlasmap.v2.SimpleField) Test(org.junit.Test)

Example 62 with Field

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

the class DefaultAtlasFieldActionsServiceTest method testProcessActionsActionsFieldAtlasConversionException.

@Test(expected = AtlasConversionException.class)
public void testProcessActionsActionsFieldAtlasConversionException() throws AtlasException {
    Actions actions = null;
    SimpleField field = new SimpleField();
    Object value = new Object();
    field.setValue(value);
    field.setFieldType(FieldType.INTEGER);
    fieldActionsService.processActions(actions, field);
}
Also used : Actions(io.atlasmap.v2.Actions) SimpleField(io.atlasmap.v2.SimpleField) Test(org.junit.Test)

Example 63 with Field

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

the class DefaultAtlasFieldActionsServiceTest method testprocessActionsActionsObjectFieldTypeAtlasConversionException.

@Test(expected = AtlasConversionException.class)
public void testprocessActionsActionsObjectFieldTypeAtlasConversionException() throws AtlasException {
    Actions actions = null;
    SimpleField field = new SimpleField();
    Object value = new Object();
    field.setValue(value);
    field.setFieldType(FieldType.INTEGER);
    fieldActionsService.processActions(actions, field);
}
Also used : Actions(io.atlasmap.v2.Actions) SimpleField(io.atlasmap.v2.SimpleField) Test(org.junit.Test)

Example 64 with Field

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

the class XmlModule method processTargetFieldMapping.

@Override
public void processTargetFieldMapping(AtlasInternalSession session) throws AtlasException {
    Field sourceField = session.head().getSourceField();
    Field targetField = session.head().getTargetField();
    // Attempt to Auto-detect field type based on input value
    if (targetField.getFieldType() == null && sourceField.getValue() != null) {
        targetField.setFieldType(getConversionService().fieldTypeFromClass(sourceField.getValue().getClass()));
    }
    Object outputValue = null;
    // Do auto-conversion
    if (sourceField.getFieldType() != null && sourceField.getFieldType().equals(targetField.getFieldType())) {
        outputValue = sourceField.getValue();
    } else if (sourceField.getValue() != null) {
        try {
            outputValue = getConversionService().convertType(sourceField.getValue(), sourceField.getFormat(), targetField.getFieldType(), targetField.getFormat());
        } catch (AtlasConversionException e) {
            AtlasUtil.addAudit(session, targetField.getDocId(), String.format("Unable to auto-convert for sT=%s tT=%s tF=%s msg=%s", sourceField.getFieldType(), targetField.getFieldType(), targetField.getPath(), e.getMessage()), targetField.getPath(), AuditStatus.ERROR, null);
            return;
        }
    }
    targetField.setValue(outputValue);
    LookupTable lookupTable = session.head().getLookupTable();
    if (lookupTable != null) {
        processLookupField(session, lookupTable, targetField.getValue(), targetField);
    }
    if (isAutomaticallyProcessOutputFieldActions() && targetField.getActions() != null && targetField.getActions().getActions() != null) {
        getFieldActionService().processActions(targetField.getActions(), targetField);
    }
    XmlFieldWriter writer = session.getFieldWriter(getDocId(), XmlFieldWriter.class);
    writer.write(session);
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processTargetFieldMapping completed: SourceField:[docId={}, path={}, type={}, value={}], TargetField:[docId={}, path={}, type={}, value={}]", getDocId(), sourceField.getDocId(), sourceField.getPath(), sourceField.getFieldType(), sourceField.getValue(), targetField.getDocId(), targetField.getPath(), targetField.getFieldType(), targetField.getValue());
    }
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) AtlasConversionException(io.atlasmap.api.AtlasConversionException) LookupTable(io.atlasmap.v2.LookupTable) XmlFieldWriter(io.atlasmap.xml.core.XmlFieldWriter)

Example 65 with Field

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

the class AtlasServiceTest method testActionDeserialization.

@Test
public void testActionDeserialization() throws Exception {
    File file = new File("src/test/resources/atlasmapping-actions.json");
    AtlasMapping mapping = mapper.readValue(file, AtlasMapping.class);
    Mappings mappings = mapping.getMappings();
    for (BaseMapping baseMapping : mappings.getMapping()) {
        if (MappingType.MAP.equals(baseMapping.getMappingType())) {
            List<Field> fields = ((Mapping) baseMapping).getOutputField();
            for (Field f : fields) {
                if (f.getActions() != null && f.getActions().getActions() != null && !f.getActions().getActions().isEmpty()) {
                    System.out.println("Found actions: " + f.getActions().getActions().size());
                }
            }
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping) File(java.io.File) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.Test)

Aggregations

Field (io.atlasmap.v2.Field)66 Test (org.junit.Test)27 JavaField (io.atlasmap.java.v2.JavaField)26 AtlasMapping (io.atlasmap.v2.AtlasMapping)26 Mapping (io.atlasmap.v2.Mapping)25 BaseMapping (io.atlasmap.v2.BaseMapping)17 SimpleField (io.atlasmap.v2.SimpleField)17 Validation (io.atlasmap.v2.Validation)14 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)13 AtlasException (io.atlasmap.api.AtlasException)12 FieldType (io.atlasmap.v2.FieldType)12 JsonField (io.atlasmap.json.v2.JsonField)10 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)10 XmlField (io.atlasmap.xml.v2.XmlField)9 LookupTable (io.atlasmap.v2.LookupTable)8 ArrayList (java.util.ArrayList)8 AtlasConversionException (io.atlasmap.api.AtlasConversionException)7 ConstantField (io.atlasmap.v2.ConstantField)7 JavaClass (io.atlasmap.java.v2.JavaClass)6 Head (io.atlasmap.spi.AtlasInternalSession.Head)6