Search in sources :

Example 21 with TransformationContext

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

the class PipelineTest method testCanceledAction.

@Test
public void testCanceledAction() throws Exception {
    // Given
    final RunnableAction mockAction = new RunnableAction() {

        @Override
        public DataSetRowAction getRowAction() {
            return (r, context) -> {
                context.get("Executed", p -> true);
                return r;
            };
        }
    };
    final ActionContext actionContext = new ActionContext(new TransformationContext());
    actionContext.setActionStatus(ActionContext.ActionStatus.CANCELED);
    final Node node = NodeBuilder.source().to(new ActionNode(mockAction, actionContext)).to(output).build();
    final RowMetadata rowMetadata = new RowMetadata();
    final DataSetRow row = new DataSetRow(rowMetadata);
    // when
    node.exec().receive(row, rowMetadata);
    // then
    assertFalse(actionContext.has("Executed"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) CoreMatchers(org.hamcrest.CoreMatchers) BasicLink(org.talend.dataprep.transformation.pipeline.link.BasicLink) HashMap(java.util.HashMap) Test(org.junit.Test) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) ArrayList(java.util.ArrayList) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) org.talend.dataprep.transformation.pipeline.node(org.talend.dataprep.transformation.pipeline.node) END_OF_STREAM(org.talend.dataprep.transformation.pipeline.Signal.END_OF_STREAM) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) CloneLink(org.talend.dataprep.transformation.pipeline.link.CloneLink) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) DataSetRowAction(org.talend.dataprep.transformation.api.action.DataSetRowAction) Assert(org.junit.Assert) DataSet(org.talend.dataprep.api.dataset.DataSet) NodeBuilder(org.talend.dataprep.transformation.pipeline.builder.NodeBuilder) Before(org.junit.Before) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 22 with TransformationContext

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

the class PipelineTest method testVisitorAndToString.

@Test
public void testVisitorAndToString() throws Exception {
    final Node node = // 
    NodeBuilder.source().to(// 
    new BasicNode()).dispatchTo(// 
    new BasicNode()).to(// 
    new ActionNode(new RunnableAction(), new ActionContext(new TransformationContext()))).to(// 
    output).build();
    final Pipeline pipeline = new Pipeline(node);
    final NodeClassVisitor visitor = new NodeClassVisitor();
    // when
    pipeline.accept(visitor);
    // then
    final Class[] expectedClasses = { Pipeline.class, SourceNode.class, BasicLink.class, BasicNode.class, CloneLink.class, ActionNode.class };
    assertThat(visitor.traversedClasses, CoreMatchers.hasItems(expectedClasses));
    assertNotNull(pipeline.toString());
}
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) Test(org.junit.Test)

Example 23 with TransformationContext

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

the class PipelineTest method testActionNode.

@Test
public void testActionNode() throws Exception {
    final ActionContext actionContext = new ActionContext(new TransformationContext());
    final RunnableAction mockAction = new RunnableAction();
    ActionNode compileNode = new ActionNode(mockAction, actionContext);
    assertEquals(actionContext, compileNode.getActionContext());
    assertEquals(mockAction, compileNode.getAction());
}
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) Test(org.junit.Test)

Example 24 with TransformationContext

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

the class MatchesPatternTest method buildPatternActionContext.

private ActionContext buildPatternActionContext(String regex) {
    ActionContext context = new ActionContext(new TransformationContext());
    // create and add a single column
    RowMetadata rowMetadata = new RowMetadata();
    ColumnMetadata column = new ColumnMetadata();
    column.setId("0000");
    column.setName("toto");
    column.setType(Type.STRING.name());
    rowMetadata.setColumns(Collections.singletonList(column));
    context.setRowMetadata(rowMetadata);
    // create and add minimalist parameters
    Map<String, String> parameters = new HashMap<>();
    parameters.put(MatchesPattern.PATTERN_PARAMETER, regex);
    parameters.put(ImplicitParameters.COLUMN_ID.getKey(), "0000");
    context.setParameters(parameters);
    action.compile(context);
    return context;
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext)

Example 25 with TransformationContext

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

the class MetadataChangesOnActionsGenerator method compileActionsOnMetadata.

/**
 * Compile the given actions, hence updating the given row metadata and return the later.
 *
 * @param actions the actions to compile.
 * @param startingRowMetadata the row metadata to start from.
 * @return the updated row metadata from the actions compilation.
 */
private RowMetadata compileActionsOnMetadata(List<RunnableAction> actions, final RowMetadata startingRowMetadata) {
    final RowMetadata updatedRowMetadata = startingRowMetadata.clone();
    TransformationContext transformationContext = new TransformationContext();
    // compile every action within the transformation context
    for (RunnableAction action : actions) {
        final DataSetRowAction rowAction = action.getRowAction();
        final ActionContext actionContext = transformationContext.create(rowAction, updatedRowMetadata);
        rowAction.compile(actionContext);
    }
    // the cleanup is REALLY important (as it can close http connection in case of a lookup for instance)
    transformationContext.cleanup();
    return updatedRowMetadata;
}
Also used : DataSetRowAction(org.talend.dataprep.transformation.api.action.DataSetRowAction) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext)

Aggregations

TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)27 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)26 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)22 Test (org.junit.Test)20 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)11 DataSetRowAction (org.talend.dataprep.transformation.api.action.DataSetRowAction)6 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