Search in sources :

Example 31 with RunnableAction

use of org.talend.dataprep.transformation.actions.common.RunnableAction 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)

Example 32 with RunnableAction

use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.

the class PreparationService method buildActions.

/**
 * Given a list of actions recreate but with the Spring Context {@link ActionDefinition}. It is mandatory to use any
 * action parsed from JSON.
 */
private List<RunnableAction> buildActions(List<Action> allActions) {
    final List<RunnableAction> builtActions = new ArrayList<>(allActions.size() + 1);
    for (Action parsedAction : allActions) {
        if (parsedAction != null && parsedAction.getName() != null) {
            String actionNameLowerCase = parsedAction.getName().toLowerCase();
            final ActionDefinition metadata = actionRegistry.get(actionNameLowerCase);
            builtActions.add(factory.create(metadata, parsedAction.getParameters()));
        }
    }
    return builtActions;
}
Also used : RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition)

Aggregations

RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)32 Test (org.junit.Test)23 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)22 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)21 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)20 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)18 HashMap (java.util.HashMap)15 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)14 DataSetRowAction (org.talend.dataprep.transformation.api.action.DataSetRowAction)6 ActionDefinition (org.talend.dataprep.api.action.ActionDefinition)4 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)4 Action (org.talend.dataprep.api.preparation.Action)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Before (org.junit.Before)3 DataSet (org.talend.dataprep.api.dataset.DataSet)3 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)3 CoreMatchers (org.hamcrest.CoreMatchers)2