use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.
the class ExportAPI method getExportNameAndConsolidateParameters.
private String getExportNameAndConsolidateParameters(ExportParameters parameters) {
// export file name comes from :
// 1. the form parameter
// 2. the preparation name
// 3. the dataset name
String exportName = EMPTY;
if (parameters.getArguments().containsKey(PREFIX + "fileName")) {
return parameters.getArguments().get(PREFIX + "fileName");
}
// deal with preparation (update the export name and dataset id if needed)
if (StringUtils.isNotBlank(parameters.getPreparationId())) {
final PreparationSummaryGet preparationSummaryGet = getCommand(PreparationSummaryGet.class, parameters.getPreparationId());
final PreparationDTO preparation = preparationSummaryGet.execute();
if (StringUtils.isBlank(exportName)) {
exportName = preparation.getName();
}
// update the dataset id in the parameters if needed
if (StringUtils.isBlank(parameters.getDatasetId())) {
parameters.setDatasetId(preparation.getDataSetId());
}
} else if (StringUtils.isBlank(exportName)) {
// deal export name in case of dataset
final DataSetMetadata metadata = datasetClient.getDataSetMetadata(parameters.getDatasetId());
exportName = metadata.getName();
}
return exportName;
}
use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.
the class PreparationAPITest method testMoveStep.
@Test
public void testMoveStep() throws Exception {
final String datasetId = testClient.createDataset("preview/preview_dataset.csv", "testPreview");
String testPrepId = testClient.createPreparationFromDataset(datasetId, "testPrep", home.getId());
AppendStep appendStep = new AppendStep();
final Action actionToBeMoved = buildAction("uppercase", buildParametersMap("column_id", "0001", "column_name", "firstname", "scope", "column"));
appendStep.setActions(Arrays.asList(buildAction("uppercase", buildParametersMap("column_id", "0002", "column_name", "lastname", "scope", "column")), actionToBeMoved));
appendStepsToPrep(testPrepId, appendStep);
// Adding steps
PreparationDTO testPrepDetails = getPreparationDetails(testPrepId);
List<String> stepsCreated = testPrepDetails.getSteps();
String rootStep = stepsCreated.get(0);
String secondStep = stepsCreated.get(2);
// changing steps order
changePreparationStepsOrder(testPrepId, rootStep, secondStep);
PreparationDTO testPrepDetailsAfter = getPreparationDetails(testPrepId);
final Action initialUpperCaseAction = getActions(testPrepDetails.getSteps().get(2)).get(1);
assertEquals(actionToBeMoved, initialUpperCaseAction);
final Action movedAction = getActions(testPrepDetailsAfter.getSteps().get(1)).get(0);
assertEquals(initialUpperCaseAction, movedAction);
}
use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.
the class PreparationAPITest method testPreparationContentWithActions.
@Test
public void testPreparationContentWithActions() throws Exception {
// given
final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "testPreparationContentGet", home.getId());
PreparationDTO preparation = getPreparationDetails(preparationId);
List<String> steps = preparation.getSteps();
assertThat(steps.size(), is(1));
assertThat(steps.get(0), is(Step.ROOT_STEP.id()));
// when
testClient.applyActionFromFile(preparationId, "transformation/upper_case_firstname.json");
// then
final PreparationDTO preparationMessage = getPreparationDetails(preparationId);
steps = preparationMessage.getSteps();
assertThat(steps.size(), is(2));
assertThat(steps.get(0), is(Step.ROOT_STEP.id()));
// Request preparation content at different versions (preparation has 2 steps -> Root + Upper Case).
assertThat(testClient.getPreparation(preparationId).asString(), sameJSONAsFile(PreparationAPITest.class.getResourceAsStream("dataset/expected_dataset_firstname_uppercase_with_column.json")));
assertThat(testClient.getPreparation(preparationId, "head").asString(), sameJSONAsFile(PreparationAPITest.class.getResourceAsStream("dataset/expected_dataset_firstname_uppercase_with_column.json")));
assertThat(testClient.getPreparation(preparationId, steps.get(0)).asString(), sameJSONAsFile(PreparationAPITest.class.getResourceAsStream("dataset/expected_dataset_with_columns.json")));
assertThat(testClient.getPreparation(preparationId, steps.get(1)).asString(), sameJSONAsFile(PreparationAPITest.class.getResourceAsStream("dataset/expected_dataset_firstname_uppercase_with_column.json")));
assertThat(testClient.getPreparation(preparationId, "origin").asString(), sameJSONAsFile(PreparationAPITest.class.getResourceAsStream("dataset/expected_dataset_with_columns.json")));
assertThat(testClient.getPreparation(preparationId, Step.ROOT_STEP.id()).asString(), sameJSONAsFile(PreparationAPITest.class.getResourceAsStream("dataset/expected_dataset_with_columns.json")));
}
use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.
the class PreparationAPITest method testSetPreparationHead_TDP_2562.
/**
* Verify a data set is not locked when used by a step that is not used in any preparation.
* see <a href="https://jira.talendforge.org/browse/TDP-2562">TDP-2562</a>
*/
@Test
public void testSetPreparationHead_TDP_2562() throws Exception {
// Three data sets
final String lookupDataSetId = testClient.createDataset("dataset/dataset.csv", "lookup_ds");
final String dataSetId = testClient.createDataset("dataset/dataset_cars.csv", "cars");
String carsPreparationId = testClient.createPreparationFromDataset(dataSetId, "cars_preparation", home.getId());
String action = IOUtils.toString(getClass().getResource("preparations/cars_lookup_action.json"), UTF_8);
testClient.applyAction(carsPreparationId, action.replace("{lookup_ds_id}", lookupDataSetId));
// Try to delete lookup dataset => fail because used
expect().statusCode(CONFLICT.value()).when().delete("/api/datasets/{id}", lookupDataSetId);
PreparationDTO preparationDetails = getPreparationDetails(carsPreparationId);
String firstStepId = preparationDetails.getSteps().get(0);
// Now undo
expect().statusCode(OK.value()).when().put("/api/preparations/{id}/head/{headId}", carsPreparationId, firstStepId);
// Try again to delete lookup dataset
expect().statusCode(OK.value()).when().get("/api/datasets/{id}", lookupDataSetId);
}
use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.
the class PreparationAPITest method shouldAddMultipleActionStepAfterHead.
@Test
public void shouldAddMultipleActionStepAfterHead() throws Exception {
// / when: 1 AppendStep with 2 actions
final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "testPreparation", home.getId());
// when
testClient.applyActionFromFile(preparationId, "transformation/upper_case_lastname_firstname.json");
// then : it should have appended 2 actions
final PreparationDTO preparationMessage = getPreparationDetails(preparationId);
final List<String> steps = preparationMessage.getSteps();
assertThat(steps.size(), is(3));
assertThat(steps.get(0), is(Step.ROOT_STEP.id()));
}
Aggregations