use of org.talend.dataprep.api.export.ExportParameters in project data-prep by Talend.
the class CachedExportStrategy method execute.
@Override
public StreamingResponseBody execute(ExportParameters parameters) {
final TransformationCacheKey contentKey = getCacheKey(parameters);
//
ExportUtils.setExportHeaders(//
parameters.getExportName(), //
parameters.getArguments().get(ExportFormat.PREFIX + CSVFormat.ParametersCSV.ENCODING), getFormat(parameters.getExportType()));
return outputStream -> {
try (InputStream cachedContent = contentCache.get(contentKey)) {
IOUtils.copy(cachedContent, outputStream);
}
};
}
use of org.talend.dataprep.api.export.ExportParameters in project data-prep by Talend.
the class DataSetExportStrategy method execute.
@Override
public StreamingResponseBody execute(ExportParameters parameters) {
final String formatName = parameters.getExportType();
final ExportFormat format = getFormat(formatName);
//
ExportUtils.setExportHeaders(//
parameters.getExportName(), //
parameters.getArguments().get(ExportFormat.PREFIX + CSVFormat.ParametersCSV.ENCODING), format);
return outputStream -> {
// get the dataset content (in an auto-closable block to make sure it is properly closed)
final String datasetId = parameters.getDatasetId();
final DataSetGet dataSetGet = applicationContext.getBean(DataSetGet.class, datasetId, false, true);
final DataSetGetMetadata dataSetGetMetadata = applicationContext.getBean(DataSetGetMetadata.class, datasetId);
try (InputStream datasetContent = dataSetGet.execute()) {
try (JsonParser parser = mapper.getFactory().createParser(new InputStreamReader(datasetContent, UTF_8))) {
// Create dataset
final DataSet dataSet = mapper.readerFor(DataSet.class).readValue(parser);
dataSet.setMetadata(dataSetGetMetadata.execute());
// get the actions to apply (no preparation ==> dataset export ==> no actions)
Configuration configuration = //
Configuration.builder().args(//
parameters.getArguments()).outFilter(//
rm -> filterService.build(parameters.getFilter(), rm)).format(//
format.getName()).volume(//
Configuration.Volume.SMALL).output(//
outputStream).limit(//
limit).build();
factory.get(configuration).buildExecutable(dataSet, configuration).execute();
}
} catch (TDPException e) {
throw e;
} catch (Exception e) {
throw new TDPException(TransformationErrorCodes.UNABLE_TO_TRANSFORM_DATASET, e);
}
};
}
use of org.talend.dataprep.api.export.ExportParameters in project data-prep by Talend.
the class ApplyPreparationExportStrategyTest method shouldNotAcceptIfPreparationParameterNotSet.
@Test
public void shouldNotAcceptIfPreparationParameterNotSet() throws Exception {
// Given
final ExportParameters parameters = new ExportParameters();
parameters.setDatasetId("1234");
parameters.setPreparationId("");
parameters.setStepId("0");
parameters.setExportType("text");
parameters.setFrom(ExportParameters.SourceType.HEAD);
// Then
assertFalse(applyPreparationExportStrategy.accept(parameters));
}
use of org.talend.dataprep.api.export.ExportParameters in project data-prep by Talend.
the class CachedExportStrategyTest method shouldNotAcceptNullParameterContent.
@Test
public void shouldNotAcceptNullParameterContent() throws Exception {
// Then
final ExportParameters parameters = new ExportParameters();
parameters.setContent(null);
assertFalse(cachedExportStrategy.accept(parameters));
}
use of org.talend.dataprep.api.export.ExportParameters 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));
}
Aggregations