Search in sources :

Example 16 with Preparation

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

the class PreparationServiceTest method init.

private void init() throws IOException {
    createFolder(home.getId(), "foo");
    final Folder foo = getFolder(home.getId(), "foo");
    createFolder(home.getId(), "Folder Cr((eate Email A!ddressrrrbb[zzzz (copie-é'(-è_çà)+&.csv");
    final Folder specialChar = getFolder(home.getId(), "Folder Cr((eate Email A!ddressrrrbb[zzzz (copie-é'(-è_çà)+&.csv");
    Preparation preparation = new Preparation();
    preparation.setName("prep_name_foo");
    preparation.setDataSetId("1234");
    preparation.setRowMetadata(new RowMetadata());
    clientTest.createPreparation(preparation, foo.getId());
    preparation.setName("prep_name_home");
    clientTest.createPreparation(preparation, home.getId());
    preparation.setName("Cr((eate Email A!ddressrrrbb[zzzz (copie-é'(-è_çà)+&.csv");
    clientTest.createPreparation(preparation, foo.getId());
    preparation.setName("Cr((eate Email A!ddressrrrbb[zzzz (copie-é'(-è_çà)+&.csv");
    clientTest.createPreparation(preparation, specialChar.getId());
}
Also used : Preparation(org.talend.dataprep.api.preparation.Preparation) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) Folder(org.talend.dataprep.api.folder.Folder)

Example 17 with Preparation

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

the class PreparationClientTest method addStep.

/**
 * Append an action to a preparation.
 *
 * @param preparationId The preparation id.
 * @param stepContent The step content json.
 * @return The created stepContent id.
 */
public String addStep(final String preparationId, final String stepContent) throws IOException {
    final Response post = // 
    given().body(stepContent).contentType(// 
    JSON).when().post("/preparations/{id}/actions", preparationId);
    assertEquals("fail to add step : " + post.statusLine(), 200, post.statusCode());
    final Preparation preparation = preparationRepository.get(preparationId, Preparation.class);
    return preparation.getHeadId();
}
Also used : Response(com.jayway.restassured.response.Response) Preparation(org.talend.dataprep.api.preparation.Preparation)

Example 18 with Preparation

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

the class TransformationService method getPreparation.

/**
 * Get the preparation from the preparation service.
 *
 * @param preparationId the wanted preparation id.
 * @return the preparation from the preparation service.
 */
private Preparation getPreparation(@ApiParam(value = "The preparation id") @PathVariable String preparationId) {
    final Preparation preparation;
    try {
        final PreparationDetailsGet details = applicationContext.getBean(PreparationDetailsGet.class, preparationId);
        preparation = mapper.readerFor(Preparation.class).readValue(details.execute());
    } catch (IOException e) {
        throw new TDPException(PREPARATION_DOES_NOT_EXIST, e, build().put("id", preparationId));
    }
    return preparation;
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) Preparation(org.talend.dataprep.api.preparation.Preparation) PreparationDetailsGet(org.talend.dataprep.command.preparation.PreparationDetailsGet)

Example 19 with Preparation

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

the class TransformationServiceTest method testCache.

@Test
public void testCache() throws Exception {
    // given
    String dsId = createDataset("input_dataset.csv", "uppercase", "text/csv");
    String prepId = createEmptyPreparationFromDataset(dsId, "uppercase prep");
    applyActionFromFile(prepId, "uppercase_action.json");
    final Preparation preparation = getPreparation(prepId);
    final String headId = preparation.getHeadId();
    final TransformationCacheKey key = // 
    cacheKeyGenerator.generateContentKey(// 
    dsId, // 
    preparation.getId(), // 
    headId, // 
    JSON, // 
    HEAD, // no filter
    "");
    assertFalse(contentCache.has(key));
    // when
    // 
    given().expect().statusCode(200).log().ifError().when().get("/apply/preparation/{prepId}/dataset/{datasetId}/{format}", prepId, dsId, // 
    "JSON").asString();
    // then
    assertTrue(contentCache.has(key));
    // just to pass through the cache
    final Response response = // 
    given().expect().statusCode(200).log().ifError().when().get("/apply/preparation/{prepId}/dataset/{datasetId}/{format}", prepId, dsId, "JSON");
    Assert.assertThat(response.getStatusCode(), is(200));
}
Also used : TransformationCacheKey(org.talend.dataprep.cache.TransformationCacheKey) Response(com.jayway.restassured.response.Response) Preparation(org.talend.dataprep.api.preparation.Preparation) Test(org.junit.Test)

Example 20 with Preparation

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

the class OptimizedExportStrategyTest method testAcceptOK.

@Test
public void testAcceptOK() throws Exception {
    // Given
    final String datasetId = "1234";
    final String format = "";
    final String preparation = createEmptyPreparationFromDataset(datasetId, "test");
    applyAction(preparation, "[{}]");
    applyAction(preparation, "[{}]");
    final Preparation preparationDetails = getPreparation(preparation);
    for (Step step : preparationDetails.getSteps()) {
        try (OutputStream content = contentCache.put(cacheKeyGenerator.generateMetadataKey(preparation, step.id(), HEAD), ContentCache.TimeToLive.DEFAULT)) {
            content.write("{}".getBytes());
            content.flush();
        }
        final TransformationCacheKey key = // 
        cacheKeyGenerator.generateContentKey(// 
        datasetId, // 
        preparation, // 
        step.id(), // 
        format, // 
        HEAD, // 
        "");
        try (OutputStream content = contentCache.put(key, ContentCache.TimeToLive.DEFAULT)) {
            content.write("{}".getBytes());
            content.flush();
        }
    }
    ExportParameters exportParameters = new ExportParameters();
    exportParameters.setPreparationId(preparation);
    exportParameters.setDatasetId(datasetId);
    exportParameters.setExportType(format);
    exportParameters.setFrom(HEAD);
    // Then
    assertTrue(optimizedExportStrategy.accept(exportParameters));
}
Also used : TransformationCacheKey(org.talend.dataprep.cache.TransformationCacheKey) Preparation(org.talend.dataprep.api.preparation.Preparation) ExportParameters(org.talend.dataprep.api.export.ExportParameters) OutputStream(java.io.OutputStream) Step(org.talend.dataprep.api.preparation.Step) Test(org.junit.Test) TransformationServiceBaseTest(org.talend.dataprep.transformation.service.TransformationServiceBaseTest)

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