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"));
}
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());
}
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());
}
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;
}
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;
}
Aggregations