Search in sources :

Example 26 with PreparationDTO

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

the class StandardExportStrategiesIntegrationTest method idOfPrepWith2StepsOrMore.

private String idOfPrepWith2StepsOrMore() throws IOException {
    reset(preparationDetailsGet);
    final PreparationDetailsDTO preparationDetailsDTO = mapper.readerFor(// 
    PreparationDetailsDTO.class).readValue(this.getClass().getResourceAsStream("two_steps_preparation_details.json"));
    // 
    when(preparationDetailsGet.execute()).thenReturn(// 
    preparationDetailsDTO).thenReturn(preparationDetailsDTO);
    final PreparationDTO preparationDTO = mapper.readerFor(// 
    PreparationDTO.class).readValue(this.getClass().getResourceAsStream("two_steps_preparation_details_summary.json"));
    // 
    when(preparationSummaryGet.execute()).thenReturn(// 
    preparationDTO).thenReturn(preparationDTO);
    return "prepId-1234";
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) PreparationDetailsDTO(org.talend.dataprep.api.preparation.PreparationDetailsDTO)

Example 27 with PreparationDTO

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

the class PreparationExportStrategy method performPreparation.

public void performPreparation(final ExportParameters parameters, final OutputStream outputStream) {
    final String stepId = parameters.getStepId();
    final String preparationId = parameters.getPreparationId();
    final String formatName = parameters.getExportType();
    final PreparationDTO preparation = getPreparation(preparationId, stepId);
    final String dataSetId = preparation.getDataSetId();
    final ExportFormat format = getFormat(parameters.getExportType());
    boolean releasedIdentity = false;
    // Allow get dataset and get dataset metadata access whatever share status is
    securityProxy.asTechnicalUserForDataSet();
    try (DataSet dataSet = datasetClient.getDataSet(dataSetId, false, true)) {
        // head is not allowed as step id
        final String version = getCleanStepId(preparation, stepId);
        // All good, can already release identity
        securityProxy.releaseIdentity();
        releasedIdentity = true;
        // get the actions to apply (no preparation ==> dataset export ==> no actions)
        final String actions = getActions(preparationId, version);
        final TransformationCacheKey key = // 
        cacheKeyGenerator.generateContentKey(// 
        dataSetId, // 
        preparationId, // 
        version, // 
        formatName, // 
        parameters.getFrom(), // 
        parameters.getArguments(), // 
        parameters.getFilter());
        LOGGER.debug("Cache key: {}", key.getKey());
        LOGGER.debug("Cache key details: {}", key.toString());
        try (final TeeOutputStream tee = new TeeOutputStream(outputStream, contentCache.put(key, ContentCache.TimeToLive.DEFAULT))) {
            final Configuration configuration = Configuration.builder().args(// 
            parameters.getArguments()).outFilter(// 
            rm -> filterService.build(parameters.getFilter(), rm)).sourceType(parameters.getFrom()).format(// 
            format.getName()).actions(// 
            actions).preparation(// 
            preparation).stepId(// 
            version).volume(// 
            Configuration.Volume.SMALL).output(// 
            tee).limit(// 
            limit).build();
            factory.get(configuration).buildExecutable(dataSet, configuration).execute();
            tee.flush();
        } catch (Throwable e) {
            // NOSONAR
            contentCache.evict(key);
            throw e;
        }
    } catch (TalendRuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new TDPException(TransformationErrorCodes.UNABLE_TO_TRANSFORM_DATASET, e);
    } finally {
        if (!releasedIdentity) {
            // Release identity in case of error.
            securityProxy.releaseIdentity();
        }
    }
}
Also used : ExportFormat(org.talend.dataprep.format.export.ExportFormat) TDPException(org.talend.dataprep.exception.TDPException) TransformationErrorCodes(org.talend.dataprep.exception.error.TransformationErrorCodes) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Configuration(org.talend.dataprep.transformation.api.transformer.configuration.Configuration) StringUtils(org.apache.commons.lang3.StringUtils) DatasetClient(org.talend.dataprep.dataset.adapter.DatasetClient) CacheKeyGenerator(org.talend.dataprep.cache.CacheKeyGenerator) TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) ExportUtils(org.talend.dataprep.transformation.service.ExportUtils) DataSet(org.talend.dataprep.api.dataset.DataSet) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) OutputStream(java.io.OutputStream) ExportParameters(org.talend.dataprep.api.export.ExportParameters) Logger(org.slf4j.Logger) HEAD(org.talend.dataprep.api.export.ExportParameters.SourceType.HEAD) BaseExportStrategy(org.talend.dataprep.transformation.service.BaseExportStrategy) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) ContentCache(org.talend.dataprep.cache.ContentCache) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) SecurityProxy(org.talend.dataprep.security.SecurityProxy) CSVFormat(org.talend.dataprep.transformation.format.CSVFormat) Component(org.springframework.stereotype.Component) TransformationCacheKey(org.talend.dataprep.cache.TransformationCacheKey) TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) Configuration(org.talend.dataprep.transformation.api.transformer.configuration.Configuration) DataSet(org.talend.dataprep.api.dataset.DataSet) ExportFormat(org.talend.dataprep.format.export.ExportFormat) TDPException(org.talend.dataprep.exception.TDPException) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) TransformationCacheKey(org.talend.dataprep.cache.TransformationCacheKey) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) TDPException(org.talend.dataprep.exception.TDPException) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO)

Example 28 with PreparationDTO

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

the class OptimizedExportStrategyTest method testAcceptKO_stepIdIsRootStep.

@Test
public void testAcceptKO_stepIdIsRootStep() throws Exception {
    // Given
    final String datasetId = "1234";
    final String format = "";
    final String preparation = createEmptyPreparationFromDataset(datasetId, "test");
    applyAction(preparation, "[{}]");
    applyAction(preparation, "[{}]");
    final PreparationDTO preparationDetails = getPreparation(preparation);
    final List<String> stepsWithoutRootStep = new ArrayList<>(preparationDetails.getSteps());
    stepsWithoutRootStep.remove(0);
    putTransformationAndMetadataInCacheForSteps(stepsWithoutRootStep, preparation, datasetId, format);
    ExportParameters exportParameters = new ExportParameters();
    exportParameters.setPreparationId(preparation);
    exportParameters.setDatasetId(datasetId);
    exportParameters.setExportType(format);
    exportParameters.setFrom(HEAD);
    exportParameters.setStepId(Step.ROOT_STEP.id());
    // Then
    assertFalse("The OptimizedExportStrategy should not be acceptable if version is ROOT_STEP", optimizedExportStrategy.test(exportParameters));
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) ExportParameters(org.talend.dataprep.api.export.ExportParameters) ArrayList(java.util.ArrayList) Test(org.junit.Test) TransformationServiceBaseTest(org.talend.dataprep.transformation.service.TransformationServiceBaseTest)

Example 29 with PreparationDTO

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

the class OptimizedExportStrategyTest method testExecute.

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

Example 30 with PreparationDTO

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

the class OptimizedExportStrategyTest method testAcceptKO_withMetadataCacheNoContentCache.

@Test
public void testAcceptKO_withMetadataCacheNoContentCache() throws Exception {
    // Given
    final String preparation = createEmptyPreparationFromDataset("1234", "test");
    applyAction(preparation, "[{}]");
    applyAction(preparation, "[{}]");
    final PreparationDTO preparationDetails = getPreparation(preparation);
    for (String step : preparationDetails.getSteps()) {
        try (OutputStream content = contentCache.put(cacheKeyGenerator.generateMetadataKey(preparation, step, HEAD), ContentCache.TimeToLive.DEFAULT)) {
            content.write("{}".getBytes());
            content.flush();
        }
    }
    ExportParameters exportParameters = new ExportParameters();
    exportParameters.setPreparationId(preparation);
    exportParameters.setFrom(HEAD);
    // Then
    assertFalse(optimizedExportStrategy.test(exportParameters));
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) ExportParameters(org.talend.dataprep.api.export.ExportParameters) OutputStream(java.io.OutputStream) Test(org.junit.Test) TransformationServiceBaseTest(org.talend.dataprep.transformation.service.TransformationServiceBaseTest)

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