Search in sources :

Example 1 with ScopeCategory

use of org.talend.dataprep.transformation.actions.category.ScopeCategory in project data-prep by Talend.

the class AbstractActionMetadata method compile.

/**
 * Called by transformation process <b>before</b> the first transformation occurs. This method allows action
 * implementation to compute reusable objects in actual transformation execution. Implementations may also indicate
 * that action is not applicable and should be discarded ( {@link ActionContext.ActionStatus#CANCELED}.
 *
 * @param actionContext The action context that contains the parameters and allows compile step to change action
 * status.
 * @see ActionContext#setActionStatus(ActionContext.ActionStatus)
 */
@Override
public void compile(ActionContext actionContext) {
    final RowMetadata input = actionContext.getRowMetadata();
    final ScopeCategory scope = actionContext.getScope();
    if (scope != null) {
        switch(scope) {
            case CELL:
            case COLUMN:
                // Stop action if: there's actually column information in input AND column is not found
                if (input != null && !input.getColumns().isEmpty() && input.getById(actionContext.getColumnId()) == null) {
                    actionContext.setActionStatus(ActionContext.ActionStatus.CANCELED);
                    return;
                }
                break;
            case LINE:
            case DATASET:
            default:
                break;
        }
    }
    actionContext.setActionStatus(ActionContext.ActionStatus.OK);
}
Also used : ScopeCategory(org.talend.dataprep.transformation.actions.category.ScopeCategory) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata)

Example 2 with ScopeCategory

use of org.talend.dataprep.transformation.actions.category.ScopeCategory in project data-prep by Talend.

the class ActionFactory method create.

public final RunnableAction create(ActionDefinition actionDefinition, Map<String, String> parameters) {
    if (parameters == null) {
        throw new IllegalArgumentException("Parameters cannot be null.");
    }
    validator.checkScopeConsistency(actionDefinition, parameters);
    final Map<String, String> parametersCopy = new HashMap<>(parameters);
    final ScopeCategory scope = getScope(parametersCopy);
    actionDefinition = actionDefinition.adapt(scope);
    return // 
    builder().withName(actionDefinition.getName()).withParameters(// 
    parametersCopy).withCompile(new CompileDataSetRowAction(parametersCopy, actionDefinition, scope)).withRow(// 
    new ApplyDataSetRowAction(actionDefinition, parameters, scope)).build();
}
Also used : HashMap(java.util.HashMap) ScopeCategory(org.talend.dataprep.transformation.actions.category.ScopeCategory)

Aggregations

ScopeCategory (org.talend.dataprep.transformation.actions.category.ScopeCategory)2 HashMap (java.util.HashMap)1 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)1