Search in sources :

Example 41 with PreparationDTO

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;
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) PreparationSummaryGet(org.talend.dataprep.command.preparation.PreparationSummaryGet) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata)

Example 42 with PreparationDTO

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);
}
Also used : Action(org.talend.dataprep.api.preparation.Action) EntityBuilder.buildAction(org.talend.dataprep.api.service.EntityBuilder.buildAction) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) AppendStep(org.talend.dataprep.api.preparation.AppendStep) Test(org.junit.Test)

Example 43 with PreparationDTO

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

Example 44 with PreparationDTO

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

Example 45 with PreparationDTO

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