Search in sources :

Example 11 with PreparationDTO

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

the class PreparationAPITest method testPreparationsList_withFilterOnFolderPath.

@Test
public void testPreparationsList_withFilterOnFolderPath() throws Exception {
    // given
    String tagadaId = testClient.createDataset("dataset/dataset.csv", "tagada");
    String preparationName = "tagadaPreparation";
    String preparationId = testClient.createPreparationFromDataset(tagadaId, preparationName, home.getId());
    // when : short format
    final Response shouldNotBeEmpty = when().get("/api/preparations/?format=short&folder_path={folder_path}", "/");
    // then
    List<PreparationDTO> result = // 
    mapper.readerFor(// 
    PreparationDTO.class).<PreparationDTO>readValues(// 
    shouldNotBeEmpty.asInputStream()).readAll();
    assertThat(result.get(0).getId(), is(preparationId));
    // when
    final JsonPath shouldBeEmpty = when().get("/api/preparations/?format=short&folder_path={folder_path}", "/toto").jsonPath();
    // then
    assertThat(shouldBeEmpty.<String>getList("id"), is(empty()));
}
Also used : Response(com.jayway.restassured.response.Response) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 12 with PreparationDTO

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

the class PreparationService method getPreparationDetailsFull.

/**
 * Return a preparation details.
 *
 * @param id the wanted preparation id.
 * @param stepId the optional step id.
 * @return the preparation details.
 */
public PreparationDetailsDTO getPreparationDetailsFull(String id, String stepId) {
    final PreparationDTO prep = getPreparationDetails(id, stepId);
    final PreparationDetailsDTO details = injectActionsForms(beanConversionService.convert(prep, PreparationDetailsDTO.class));
    LOGGER.debug("returning details for {} -> {}", id, details);
    return details;
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) PreparationDetailsDTO(org.talend.dataprep.api.preparation.PreparationDetailsDTO)

Example 13 with PreparationDTO

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

the class ExportParametersUtil method populateFromPreparationExportParameter.

/**
 * Return a copy of the export parameter with all clean value for a preparation (good step Id and good datasetId)
 *
 * @param exportParam incoming export param
 * @return a full value copy of the export parameter
 */
public ExportParameters populateFromPreparationExportParameter(ExportParameters exportParam) throws IOException {
    ExportParameters result = new ExportParameters();
    result.setPreparationId(exportParam.getPreparationId());
    result.setExportType(exportParam.getExportType());
    result.setFrom(exportParam.getFrom());
    result.setContent(exportParam.getContent());
    result.setArguments(exportParam.getArguments());
    result.setExportName(exportParam.getExportName());
    result.setDatasetId(exportParam.getDatasetId());
    result.setFilter(exportParam.getFilter());
    // we deal with a preparation export parameter. We need to populate stepId and datasetId
    if (StringUtils.isNotEmpty(exportParam.getPreparationId())) {
        PreparationDTO prep = getPreparation(exportParam.getPreparationId(), exportParam.getStepId());
        result.setStepId(getCleanStepId(prep, exportParam.getStepId()));
        // for the preparation
        if (exportParam.getDatasetId() == null && exportParam.getContent() == null) {
            result.setDatasetId(prep.getDataSetId());
        }
    } else {
        // it'w a dataset export parameter. We need to switch stepId to empty
        result.setStepId("");
    }
    return result;
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO)

Example 14 with PreparationDTO

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

the class ExportAPITest method testExportCsvFromPreparationStep.

@Test
public void testExportCsvFromPreparationStep() throws Exception {
    // given
    final String preparationId = testClient.createPreparationFromFile("export/export_dataset.csv", "testExport", home.getId());
    testClient.applyActionFromFile(preparationId, "export/upper_case_firstname.json");
    testClient.applyActionFromFile(preparationId, "export/upper_case_lastname.json");
    testClient.applyActionFromFile(preparationId, "export/delete_city.json");
    final String expectedExport = IOUtils.toString(this.getClass().getResourceAsStream("export/expected_export_preparation_uppercase_firstname.csv"), UTF_8);
    final PreparationDTO preparationMessage = mapper.readValue(given().get("/api/preparations/{preparation}/details", preparationId).asInputStream(), PreparationDTO.class);
    final List<String> steps = preparationMessage.getSteps();
    // when
    final String export = testClient.exportPreparation(preparationId, steps.get(1)).asString();
    // then
    assertEquals(expectedExport, export);
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) Test(org.junit.Test)

Example 15 with PreparationDTO

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

the class StandardExportStrategiesIntegrationTest method initPreparationDetails.

private void initPreparationDetails() throws Exception {
    doReturn(preparationDetailsGet).when(applicationContext).getBean(eq(PreparationDetailsGet.class), anyString(), anyString());
    final PreparationDetailsDTO preparationDetailsDTO = mapper.readerFor(// 
    PreparationDetailsDTO.class).readValue(this.getClass().getResourceAsStream("preparation_details.json"));
    // 
    when(preparationDetailsGet.execute()).thenReturn(// 
    preparationDetailsDTO).thenReturn(preparationDetailsDTO);
    doReturn(preparationSummaryGet).when(applicationContext).getBean(eq(PreparationSummaryGet.class), anyString(), anyString());
    final PreparationDTO preparationDTO = mapper.readerFor(// 
    PreparationDTO.class).readValue(this.getClass().getResourceAsStream("preparation_details_summary.json"));
    when(preparationSummaryGet.execute()).thenReturn(preparationDTO, preparationDTO);
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) PreparationDetailsDTO(org.talend.dataprep.api.preparation.PreparationDetailsDTO) PreparationDetailsGet(org.talend.dataprep.command.preparation.PreparationDetailsGet) PreparationSummaryGet(org.talend.dataprep.command.preparation.PreparationSummaryGet)

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