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