Search in sources :

Example 1 with StepDiff

use of org.talend.dataprep.api.preparation.StepDiff in project data-prep by Talend.

the class PreparationUpdateAction method onExecute.

private HttpRequestBase onExecute(String preparationId, String stepId, AppendStep updatedStep) {
    try {
        final String url = preparationServiceUrl + "/preparations/" + preparationId + "/actions/" + stepId;
        final Optional<StepDiff> firstStepDiff = toStream(StepDiff.class, objectMapper, input).findFirst();
        if (firstStepDiff.isPresent()) {
            // Only interested in first one
            final StepDiff diff = firstStepDiff.get();
            updatedStep.setDiff(diff);
        }
        final String stepAsString = objectMapper.writeValueAsString(updatedStep);
        final HttpPut actionAppend = new HttpPut(url);
        final InputStream stepInputStream = new ByteArrayInputStream(stepAsString.getBytes());
        actionAppend.setHeader(new BasicHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE));
        actionAppend.setEntity(new InputStreamEntity(stepInputStream));
        return actionAppend;
    } catch (IOException e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StepDiff(org.talend.dataprep.api.preparation.StepDiff) IOException(java.io.IOException) HttpPut(org.apache.http.client.methods.HttpPut) BasicHeader(org.apache.http.message.BasicHeader) InputStreamEntity(org.apache.http.entity.InputStreamEntity)

Example 2 with StepDiff

use of org.talend.dataprep.api.preparation.StepDiff in project data-prep by Talend.

the class MetadataChangesOnActionsGeneratorTest method getActionCreatedColumns_should_return_created_columns_for_multiple_diffs.

@Test
public void getActionCreatedColumns_should_return_created_columns_for_multiple_diffs() throws Exception {
    // given
    RowMetadata workingMetadata = new RowMetadata();
    workingMetadata.addColumn(createColumnNamed("do"));
    workingMetadata.addColumn(createColumnNamed("ré"));
    workingMetadata.addColumn(createColumnNamed("mi"));
    // when
    // 
    doAnswer(answer(newArrayList("foo", "bar"), emptyList(), null)).when(// 
    firstRowAction).compile(// 
    any(ActionContext.class));
    // 
    doAnswer(answer(emptyList(), newArrayList("do", "ré"), null)).when(// s
    secondRowAction).compile(// 
    any(ActionContext.class));
    StepDiff stepDiff = onActionsGenerator.computeCreatedColumns(newArrayList(firstAction, secondAction), workingMetadata);
    // then
    assertEquals(newArrayList("0003", "0004"), stepDiff.getCreatedColumns());
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) StepDiff(org.talend.dataprep.api.preparation.StepDiff) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) Test(org.junit.Test)

Example 3 with StepDiff

use of org.talend.dataprep.api.preparation.StepDiff in project data-prep by Talend.

the class MetadataChangesOnActionsGeneratorTest method getActionCreatedColumns_firstActionCreatedColumnDoesNotCount.

@Test
public void getActionCreatedColumns_firstActionCreatedColumnDoesNotCount() throws Exception {
    // given
    RowMetadata rowMetadata = new RowMetadata();
    rowMetadata.addColumn(createColumnNamed("do"));
    rowMetadata.addColumn(createColumnNamed("ré"));
    rowMetadata.addColumn(createColumnNamed("mi"));
    // when
    // 
    doAnswer(answer(newArrayList("foo", "bar"), emptyList(), firstActionStuffInActionContext)).when(// 
    firstRowAction).compile(// 
    any(ActionContext.class));
    // 
    doAnswer(answer(newArrayList("beer"), newArrayList("do", "ré"), secondActionStuffInActionContext)).when(// 
    secondRowAction).compile(// 
    any(ActionContext.class));
    StepDiff diff = onActionsGenerator.computeCreatedColumns(rowMetadata, newArrayList(firstAction), newArrayList(secondAction));
    // then
    assertEquals(newArrayList("0005"), diff.getCreatedColumns());
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) StepDiff(org.talend.dataprep.api.preparation.StepDiff) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) Test(org.junit.Test)

Example 4 with StepDiff

use of org.talend.dataprep.api.preparation.StepDiff in project data-prep by Talend.

the class ReorderStepsUtilsTest method createAppendStep.

private static AppendStep createAppendStep(String usedColumnId, List<String> createdColumns) {
    AppendStep firstStep = new AppendStep();
    StepDiff firstStepDiff = new StepDiff();
    firstStepDiff.setCreatedColumns(createdColumns);
    firstStep.setDiff(firstStepDiff);
    Action firstStepAction = new Action();
    MixedContentMap parameters = new MixedContentMap();
    parameters.put(ImplicitParameters.COLUMN_ID.getKey(), usedColumnId);
    firstStepAction.setParameters(parameters);
    firstStep.setActions(asList(firstStepAction));
    return firstStep;
}
Also used : Action(org.talend.dataprep.api.preparation.Action) StepDiff(org.talend.dataprep.api.preparation.StepDiff) MixedContentMap(org.talend.dataprep.api.preparation.MixedContentMap) AppendStep(org.talend.dataprep.api.preparation.AppendStep)

Example 5 with StepDiff

use of org.talend.dataprep.api.preparation.StepDiff in project data-prep by Talend.

the class MetadataChangesOnActionsGenerator method computeCreatedColumns.

/**
 * Return the StepDiff for the given actions from the row metadata reference.
 *
 * @param newActions the actions to apply to compute the step diff.
 * @param reference the reference row metadata.
 * @return the StepDiff starting from the reference
 */
StepDiff computeCreatedColumns(List<RunnableAction> newActions, RowMetadata reference) {
    RowMetadata updatedMetadata = compileActionsOnMetadata(newActions, reference);
    updatedMetadata.diff(reference);
    List<String> createdColumnIds = updatedMetadata.getColumns().stream().filter(c -> Flag.NEW.getValue().equals(c.getDiffFlagValue())).map(ColumnMetadata::getId).collect(toList());
    StepDiff stepDiff = new StepDiff();
    stepDiff.setCreatedColumns(createdColumnIds);
    return stepDiff;
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) StepDiff(org.talend.dataprep.api.preparation.StepDiff)

Aggregations

StepDiff (org.talend.dataprep.api.preparation.StepDiff)7 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)4 Test (org.junit.Test)2 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpPut (org.apache.http.client.methods.HttpPut)1 InputStreamEntity (org.apache.http.entity.InputStreamEntity)1 BasicHeader (org.apache.http.message.BasicHeader)1 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)1 Action (org.talend.dataprep.api.preparation.Action)1 AppendStep (org.talend.dataprep.api.preparation.AppendStep)1 MixedContentMap (org.talend.dataprep.api.preparation.MixedContentMap)1 DataSetGetMetadata (org.talend.dataprep.command.dataset.DataSetGetMetadata)1 TDPException (org.talend.dataprep.exception.TDPException)1