Search in sources :

Example 26 with ActionContext

use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.

the class ReplaceCellValueTest method should_not_compile_no_replacement_value.

@Test
public void should_not_compile_no_replacement_value() throws Exception {
    // given
    ActionContext context = getActionContext(new SimpleEntry<>(ROW_ID.getKey(), "2"));
    // when
    action.compile(context);
    // then
    assertEquals(CANCELED, context.getActionStatus());
}
Also used : ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest) Test(org.junit.Test)

Example 27 with ActionContext

use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.

the class ReplaceCellValueTest method getActionContext.

@SafeVarargs
private final ActionContext getActionContext(SimpleEntry<String, String>... entries) {
    Map<String, String> parameters = new HashMap<>();
    for (SimpleEntry<String, String> entry : entries) {
        parameters.put(entry.getKey(), entry.getValue());
    }
    ActionContext context = new ActionContext(new TransformationContext());
    context.setParameters(parameters);
    return context;
}
Also used : ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext)

Example 28 with ActionContext

use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.

the class ReplaceCellValueTest method should_not_compile_invalid_row_value.

@Test
public void should_not_compile_invalid_row_value() throws Exception {
    // given
    ActionContext context = getActionContext(// 
    new SimpleEntry<>(NEW_VALUE_PARAMETER, "toto"), // 
    new SimpleEntry<>(ROW_ID.getKey(), "toto"));
    // when
    action.compile(context);
    // then
    assertEquals(CANCELED, context.getActionStatus());
}
Also used : ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest) Test(org.junit.Test)

Example 29 with ActionContext

use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.

the class TransformationService method applyActionsOnMetadata.

private void applyActionsOnMetadata(RowMetadata metadata, String actionsAsJson) {
    List<RunnableAction> actions = actionParser.parse(actionsAsJson);
    TransformationContext transformationContext = new TransformationContext();
    try {
        for (RunnableAction action : actions) {
            final ActionContext actionContext = transformationContext.create(action.getRowAction(), metadata);
            action.getRowAction().compile(actionContext);
        }
    } finally {
        // cleanup the transformation context is REALLY important as it can close open http connections
        transformationContext.cleanup();
    }
}
Also used : RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext)

Aggregations

ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)29 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)26 Test (org.junit.Test)23 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)21 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)18 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)16 HashMap (java.util.HashMap)14 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)14 DataSetRowAction (org.talend.dataprep.transformation.api.action.DataSetRowAction)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)4 LinkedHashMap (java.util.LinkedHashMap)3 Before (org.junit.Before)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CoreMatchers (org.hamcrest.CoreMatchers)2 CoreMatchers.is (org.hamcrest.CoreMatchers.is)2 Assert (org.junit.Assert)2 DataSet (org.talend.dataprep.api.dataset.DataSet)2 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)2