use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.
the class PreparationAPI method previewDiff.
// ---------------------------------------------------------------------------------
// ----------------------------------------PREVIEW----------------------------------
// ---------------------------------------------------------------------------------
// @formatter:off
@RequestMapping(value = "/api/preparations/preview/diff", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get a preview diff between 2 steps of the same preparation.")
@Timed
public StreamingResponseBody previewDiff(@RequestBody final PreviewDiffParameters input) {
// @formatter:on
// get preparation details
final PreparationDTO preparation = internalGetPreparation(input.getPreparationId());
final List<Action> lastActiveStepActions = internalGetActions(preparation.getId(), input.getCurrentStepId());
final List<Action> previewStepActions = internalGetActions(preparation.getId(), input.getPreviewStepId());
final HystrixCommand<InputStream> transformation = getCommand(PreviewDiff.class, input, preparation, lastActiveStepActions, previewStepActions);
return executePreviewCommand(transformation);
}
use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.
the class PreparationAPITest method testPreparationUpdate.
// ------------------------------------------------------------------------------------------------------------------
// ----------------------------------------------------LIFECYCLE-----------------------------------------------------
// ------------------------------------------------------------------------------------------------------------------
@Test
public void testPreparationUpdate() throws Exception {
// given
String tagadaId = testClient.createDataset("dataset/dataset.csv", "tagada");
final String preparationId = testClient.createPreparationFromDataset(tagadaId, "original_name", home.getId());
JsonPath longFormat = when().get("/api/preparations/?format=long").jsonPath();
assertThat(longFormat.getList("name").size(), is(1));
assertThat(longFormat.getList("name").get(0), is("original_name"));
assertThat(longFormat.getList("id").size(), is(1));
assertThat(longFormat.getList("id").get(0), is(preparationId));
PreparationDTO preparation = new PreparationDTO();
preparation.setId(preparationId);
String newName = "updated_name";
preparation.setName(newName);
// when
given().contentType(ContentType.JSON).body(preparation).put("/api/preparations/{id}", preparationId).asString();
// then
longFormat = when().get("/api/preparations/?format=long").jsonPath();
assertThat(longFormat.getList("name").size(), is(1));
assertThat(longFormat.getList("name").get(0), is(newName));
}
use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.
the class PreparationAPITest method testPreparationsGet.
@Test
public void testPreparationsGet() throws Exception {
// given
String tagadaId = testClient.createDataset("dataset/dataset.csv", "tagada");
String preparationId = testClient.createPreparationFromDataset(tagadaId, "testPreparation", home.getId());
// when : long format
Response response1 = when().get("/api/preparations/{preparationId}/details", preparationId);
// then
PreparationDTO userPreparation = mapper.readerFor(PreparationDTO.class).readValue(response1.asInputStream());
assertThat(userPreparation.getDataSetId(), is(tagadaId));
assertThat(userPreparation.getAuthor(), is(security.getUserId()));
assertThat(userPreparation.getId(), is(preparationId));
}
use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.
the class PreparationAPITest method testOnTheFlyPreparationMigrationDatasetName_TDP_6195.
@Test
public void testOnTheFlyPreparationMigrationDatasetName_TDP_6195() throws IOException {
String datasetName = "my dataset - " + UUID.randomUUID().toString();
String datasetId = testClient.createDataset("/org/talend/dataprep/api/service/preparations/5L4Ccity_TDP-3858.csv", datasetName);
String preparationId = testClient.createPreparationFromDataset(datasetId, "5L4C city Preparation", home.getId());
PersistentPreparation persistentPreparation = preparationRepository.get(preparationId, PersistentPreparation.class);
persistentPreparation.setDataSetName(null);
preparationRepository.add(persistentPreparation);
// Our preparation do not have a dataset name
PreparationDTO preparationDetails = testClient.getPreparationSummary(preparationId);
assertNull(preparationDetails.getDataSetName());
// listing should trigger migration
testClient.listPreparations();
// then we have the dataset name set in the preparation
PreparationDTO preparationDetailsAfterList = testClient.getPreparationSummary(preparationId);
assertEquals(datasetName, preparationDetailsAfterList.getDataSetName());
}
use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.
the class PreparationAPITest method testPreparationUpdatePreview.
@Test
public void testPreparationUpdatePreview() throws Exception {
// given
final String preparationId = testClient.createPreparationFromFile("preview/preview_dataset.csv", "testPreview", home.getId());
testClient.applyActionFromFile(preparationId, "preview/upper_case_lastname.json");
testClient.applyActionFromFile(preparationId, "preview/upper_case_firstname.json");
testClient.applyActionFromFile(preparationId, "preview/delete_city.json");
final PreparationDTO preparationMessage = getPreparationDetails(preparationId);
final List<String> steps = preparationMessage.getSteps();
final String lastStep = steps.get(steps.size() - 1);
final String input = //
"{" + " \"preparationId\": \"" + preparationId + //
"\",\n" + " \"currentStepId\": \"" + lastStep + // action 1 + 2 + 3
"\",\n" + " \"updateStepId\": \"" + lastStep + // action 3
"\",\n" + //
" \"tdpIds\": [2, 4, 6]," + //
" \"action\": {" + //
" \"action\": \"delete_on_value\",\n" + //
" \"parameters\": {" + //
" \"column_id\": \"0006\"," + //
" \"value\": {\"token\": \"Coast city\", \"operator\": \"equals\"}," + //
" \"scope\": \"column\"" + //
" }" + //
" }" + "}";
final InputStream expectedDiffStream = PreparationAPITest.class.getResourceAsStream("preview/expected_update_preview.json");
// when
final String diff = given().contentType(ContentType.JSON).body(input).when().post("/api/preparations/preview/update").asString();
// then
assertThat(diff, sameJSONAsFile(expectedDiffStream));
}
Aggregations