Search in sources :

Example 1 with SimpleField

use of io.atlasmap.v2.SimpleField 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 SimpleField

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

the class DefaultAtlasContext method processSeparateField.

private List<Field> processSeparateField(DefaultAtlasSession session, Mapping mapping, Field sourceField) throws AtlasException {
    List<Field> answer = new ArrayList<>();
    String sourceValue;
    try {
        sourceValue = (String) factory.getConversionService().convertType(sourceField.getValue(), sourceField.getFormat(), FieldType.STRING, null);
    } catch (AtlasConversionException e) {
        AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Suitable converter for sourceField.path=%s hasn't been found", sourceField.getPath()), sourceField.getPath(), AuditStatus.WARN, null);
        sourceValue = sourceField.getValue().toString();
    }
    List<String> separatedValues = null;
    StringDelimiter delimiter = StringDelimiter.fromName(mapping.getDelimiter());
    if (mapping.getDelimiter() != null) {
        separatedValues = session.getAtlasContext().getContextFactory().getSeparateStrategy().separateValue(sourceValue, delimiter);
    } else {
        separatedValues = session.getAtlasContext().getContextFactory().getSeparateStrategy().separateValue(sourceValue);
    }
    if (separatedValues == null || separatedValues.isEmpty()) {
        LOG.debug(String.format("Empty string for Separate mapping sourceField.path=%s", sourceField.getPath()));
    } else {
        for (String separatedValue : separatedValues) {
            SimpleField simpleField = AtlasModelFactory.cloneFieldToSimpleField(sourceField);
            simpleField.setValue(separatedValue);
            simpleField.setFieldType(FieldType.STRING);
            answer.add(simpleField);
        }
    }
    return answer;
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) ConstantField(io.atlasmap.v2.ConstantField) AtlasConversionException(io.atlasmap.api.AtlasConversionException) ArrayList(java.util.ArrayList) SimpleField(io.atlasmap.v2.SimpleField) StringDelimiter(io.atlasmap.spi.StringDelimiter)

Example 3 with SimpleField

use of io.atlasmap.v2.SimpleField 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)

Example 4 with SimpleField

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

the class BaseDefaultAtlasContextTest method prepareTargetField.

protected Field prepareTargetField(Mapping mapping, String path) {
    Field field = new SimpleField();
    field.setPath(path);
    mapping.getOutputField().add(field);
    return field;
}
Also used : SimpleField(io.atlasmap.v2.SimpleField) Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField)

Example 5 with SimpleField

use of io.atlasmap.v2.SimpleField 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)

Aggregations

SimpleField (io.atlasmap.v2.SimpleField)7 Field (io.atlasmap.v2.Field)4 Actions (io.atlasmap.v2.Actions)3 Test (org.junit.Test)3 Action (io.atlasmap.v2.Action)2 AtlasConversionException (io.atlasmap.api.AtlasConversionException)1 AtlasFieldAction (io.atlasmap.api.AtlasFieldAction)1 StringDelimiter (io.atlasmap.spi.StringDelimiter)1 ActionDetail (io.atlasmap.v2.ActionDetail)1 ConstantField (io.atlasmap.v2.ConstantField)1 FieldType (io.atlasmap.v2.FieldType)1 PropertyField (io.atlasmap.v2.PropertyField)1 Trim (io.atlasmap.v2.Trim)1 ArrayList (java.util.ArrayList)1