Search in sources :

Example 6 with PreparationDTO

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);
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) PreparationDeleteAction(org.talend.dataprep.api.service.command.preparation.PreparationDeleteAction) Action(org.talend.dataprep.api.preparation.Action) PreparationAddAction(org.talend.dataprep.api.PreparationAddAction) PreparationUpdateAction(org.talend.dataprep.api.service.command.preparation.PreparationUpdateAction) InputStream(java.io.InputStream) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with PreparationDTO

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));
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 8 with PreparationDTO

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));
}
Also used : Response(com.jayway.restassured.response.Response) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) Test(org.junit.Test)

Example 9 with PreparationDTO

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());
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) Test(org.junit.Test)

Example 10 with PreparationDTO

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));
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

PreparationDTO (org.talend.dataprep.api.preparation.PreparationDTO)45 Test (org.junit.Test)22 ExportParameters (org.talend.dataprep.api.export.ExportParameters)9 ApiOperation (io.swagger.annotations.ApiOperation)7 InputStream (java.io.InputStream)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ArrayList (java.util.ArrayList)6 Action (org.talend.dataprep.api.preparation.Action)6 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)5 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)5 Preparation (org.talend.dataprep.api.preparation.Preparation)5 PreparationDetailsDTO (org.talend.dataprep.api.preparation.PreparationDetailsDTO)5 TransformationCacheKey (org.talend.dataprep.cache.TransformationCacheKey)5 TDPException (org.talend.dataprep.exception.TDPException)5 OutputStream (java.io.OutputStream)4 StringUtils (org.apache.commons.lang3.StringUtils)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Component (org.springframework.stereotype.Component)4