Search in sources :

Example 1 with ActionDetail

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

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

the class DefaultAtlasFieldActionsServiceTest method testProcessActionWithActionActionDetailObject.

@Test
public void testProcessActionWithActionActionDetailObject() throws AtlasException {
    ActionDetail actionDetail = null;
    Object sourceObject = "String";
    Action action = new Trim();
    assertEquals(sourceObject, fieldActionsService.processAction(action, actionDetail, sourceObject));
    action = new GenerateUUID();
    actionDetail = new ActionDetail();
    actionDetail.setClassName("io.atlasmap.actions.StringComplexFieldActions");
    actionDetail.setSourceType(FieldType.ANY);
    actionDetail.setMethod("genareteUUID");
    assertNotNull(fieldActionsService.processAction(action, actionDetail, sourceObject));
}
Also used : Action(io.atlasmap.v2.Action) ActionDetail(io.atlasmap.v2.ActionDetail) Trim(io.atlasmap.v2.Trim) GenerateUUID(io.atlasmap.v2.GenerateUUID) Test(org.junit.Test)

Example 3 with ActionDetail

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

the class DefaultAtlasFieldActionsServiceTest method testListActionDetails.

@Test
public void testListActionDetails() {
    assertNotNull(fieldActionsService);
    List<ActionDetail> actionDetails = fieldActionsService.listActionDetails();
    for (ActionDetail d : actionDetails) {
        if (d.getParameters() != null) {
            System.out.println("Action: " + d.getName());
            for (Property prop : d.getParameters().getProperty()) {
                System.out.println("\t param: " + prop.getName());
                System.out.println("\t type: " + prop.getFieldType().value());
            }
        }
    }
}
Also used : ActionDetail(io.atlasmap.v2.ActionDetail) Property(io.atlasmap.v2.Property) Test(org.junit.Test)

Example 4 with ActionDetail

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

the class OverloadedFieldActionsTest method testListActions.

@Test
public void testListActions() throws Exception {
    List<ActionDetail> actions = DefaultAtlasContextFactory.getInstance().getFieldActionService().listActionDetails();
    Integer found = 0;
    for (ActionDetail d : actions) {
        if (d.getName().equals("DayOfWeek")) {
            found++;
        }
    }
    assertEquals(Integer.valueOf(2), found);
}
Also used : ActionDetail(io.atlasmap.v2.ActionDetail) Test(org.junit.Test)

Example 5 with ActionDetail

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

the class DefaultAtlasFieldActionsServiceTest method testProcessActionWithActionActionDetailObjectAtlasExceptionNoMethod.

@Test(expected = AtlasException.class)
public void testProcessActionWithActionActionDetailObjectAtlasExceptionNoMethod() throws AtlasException {
    Action action = new AbsoluteValue();
    Object sourceObject = new Integer("1");
    ActionDetail actionDetail = new ActionDetail();
    actionDetail.setClassName("io.atlasmap.actions.NumberFieldActions");
    actionDetail.setSourceType(FieldType.NUMBER);
    // actionDetail.setMethod("absolute");
    fieldActionsService.processAction(action, actionDetail, sourceObject);
}
Also used : Action(io.atlasmap.v2.Action) AbsoluteValue(io.atlasmap.v2.AbsoluteValue) ActionDetail(io.atlasmap.v2.ActionDetail) Test(org.junit.Test)

Aggregations

ActionDetail (io.atlasmap.v2.ActionDetail)9 Test (org.junit.Test)7 Action (io.atlasmap.v2.Action)5 AtlasFieldAction (io.atlasmap.api.AtlasFieldAction)3 AbsoluteValue (io.atlasmap.v2.AbsoluteValue)2 GenerateUUID (io.atlasmap.v2.GenerateUUID)2 Trim (io.atlasmap.v2.Trim)2 Method (java.lang.reflect.Method)2 AtlasException (io.atlasmap.api.AtlasException)1 AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)1 Capitalize (io.atlasmap.v2.Capitalize)1 Field (io.atlasmap.v2.Field)1 FieldType (io.atlasmap.v2.FieldType)1 Lowercase (io.atlasmap.v2.Lowercase)1 PadStringLeft (io.atlasmap.v2.PadStringLeft)1 PadStringRight (io.atlasmap.v2.PadStringRight)1 Property (io.atlasmap.v2.Property)1 SeparateByDash (io.atlasmap.v2.SeparateByDash)1 SeparateByUnderscore (io.atlasmap.v2.SeparateByUnderscore)1 SimpleField (io.atlasmap.v2.SimpleField)1