Search in sources :

Example 1 with Preparation

use of org.talend.dataprep.api.preparation.Preparation 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());
    if (StringUtils.isNotEmpty(exportParam.getFilter())) {
        result.setFilter(mapper.readTree(exportParam.getFilter()));
    }
    // we deal with a preparation export parameter. We need to populate stepId and datasetId
    if (StringUtils.isNotEmpty(exportParam.getPreparationId())) {
        Preparation prep = getPreparation(exportParam.getPreparationId(), exportParam.getStepId());
        result.setStepId(getCleanStepId(prep, exportParam.getStepId()));
        if (exportParam.getFrom() != ExportParameters.SourceType.FILTER) {
            result.setDatasetId(prep.getDataSetId());
        }
    } else {
        // it'w a dataset export parameter. We need to switch stepId to empty
        result.setStepId("");
    }
    return result;
}
Also used : Preparation(org.talend.dataprep.api.preparation.Preparation)

Example 2 with Preparation

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

the class PreparationAPITest method should_change_preparation_head.

@Test
public void should_change_preparation_head() throws Exception {
    // given
    final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "testPreparation", home.getId());
    testClient.applyActionFromFile(preparationId, "transformation/upper_case_firstname.json");
    Preparation preparation = preparationRepository.get(preparationId, Preparation.class);
    final String newHead = preparationRepository.get(preparation.getHeadId(), Step.class).getParent();
    // when
    given().when().put("/api/preparations/{id}/head/{stepId}", preparationId, // 
    newHead).then().statusCode(200);
    // then
    preparation = preparationRepository.get(preparationId, Preparation.class);
    assertThat(preparation.getHeadId(), is(newHead));
}
Also used : StandalonePreparation(org.talend.dataprep.StandalonePreparation) EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) Preparation(org.talend.dataprep.api.preparation.Preparation) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation) AppendStep(org.talend.dataprep.api.preparation.AppendStep) Step(org.talend.dataprep.api.preparation.Step) Test(org.junit.Test)

Example 3 with Preparation

use of org.talend.dataprep.api.preparation.Preparation 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));
    Preparation preparation = new Preparation();
    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 : StandalonePreparation(org.talend.dataprep.StandalonePreparation) EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) Preparation(org.talend.dataprep.api.preparation.Preparation) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation) JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 4 with Preparation

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

the class PreparationAPITest method shouldCopySteps.

@Test
public void shouldCopySteps() throws Exception {
    // given
    final String referenceId = testClient.createPreparationFromFile("dataset/dataset.csv", "reference", home.getId());
    testClient.applyActionFromFile(referenceId, "transformation/upper_case_firstname.json");
    Preparation reference = preparationRepository.get(referenceId, Preparation.class);
    final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "prep", home.getId());
    // when
    final Response response = // 
    given().param("from", // 
    referenceId).expect().statusCode(200).log().ifError().when().put("/api/preparations/{id}/steps/copy", preparationId);
    // then
    assertThat(response.getStatusCode(), is(200));
    final Preparation preparation = preparationRepository.get(preparationId, Preparation.class);
    assertNotEquals(reference.getHeadId(), preparation.getHeadId());
    assertEquals(preparation.getSteps().size(), reference.getSteps().size());
    assertThat(preparation.getSteps().get(0).getId(), is(Step.ROOT_STEP.id()));
    assertEquals(preparation.getSteps().get(1).getContent(), reference.getSteps().get(1).getContent());
}
Also used : Response(com.jayway.restassured.response.Response) StandalonePreparation(org.talend.dataprep.StandalonePreparation) EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) Preparation(org.talend.dataprep.api.preparation.Preparation) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation) Test(org.junit.Test)

Example 5 with Preparation

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

the class PreparationAPITest method shouldCopyPreparation.

@Test
public void shouldCopyPreparation() throws Exception {
    // given
    Folder destination = folderRepository.addFolder(home.getId(), "/destination");
    Folder origin = folderRepository.addFolder(home.getId(), "/from");
    final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "super preparation", origin.getId());
    // when
    String newPreparationName = "NEW super preparation";
    final Response response = // 
    given().queryParam("destination", // 
    destination.getId()).queryParam("newName", // 
    newPreparationName).when().expect().statusCode(200).log().ifError().post("api/preparations/{id}/copy", preparationId);
    // then
    assertEquals(200, response.getStatusCode());
    String copyId = response.asString();
    // check the folder entry
    final List<FolderEntry> entries = getEntries(destination.getId());
    assertThat(entries.size(), greaterThan(0));
    final FolderEntry entry = entries.get(0);
    assertEquals(entry.getContentId(), copyId);
    // check the name
    final Preparation actual = preparationRepository.get(copyId, Preparation.class);
    assertEquals(newPreparationName, actual.getName());
}
Also used : Response(com.jayway.restassured.response.Response) StandalonePreparation(org.talend.dataprep.StandalonePreparation) EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) Preparation(org.talend.dataprep.api.preparation.Preparation) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation) FolderEntry(org.talend.dataprep.api.folder.FolderEntry) Folder(org.talend.dataprep.api.folder.Folder) Test(org.junit.Test)

Aggregations

Preparation (org.talend.dataprep.api.preparation.Preparation)65 Test (org.junit.Test)44 Step (org.talend.dataprep.api.preparation.Step)18 List (java.util.List)14 ServiceBaseTest (org.talend.ServiceBaseTest)11 ArrayList (java.util.ArrayList)10 Action (org.talend.dataprep.api.preparation.Action)10 PreparationActions (org.talend.dataprep.api.preparation.PreparationActions)10 Response (com.jayway.restassured.response.Response)9 Arrays (java.util.Arrays)8 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)8 ExportParameters (org.talend.dataprep.api.export.ExportParameters)8 UserPreparation (org.talend.dataprep.preparation.service.UserPreparation)8 TransformationCacheKey (org.talend.dataprep.cache.TransformationCacheKey)7 PreparationRepository (org.talend.dataprep.preparation.store.PreparationRepository)7 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)6 Folder (org.talend.dataprep.api.folder.Folder)6 TDPException (org.talend.dataprep.exception.TDPException)6 PersistentStep (org.talend.dataprep.preparation.store.PersistentStep)6 PreparationRepositoryTest (org.talend.dataprep.preparation.store.PreparationRepositoryTest)6