use of org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody in project data-prep by Talend.
the class PreparationExportStrategyTest method shouldUsedVersionedPreparation.
@Test
public void shouldUsedVersionedPreparation() throws IOException {
// Given
final ExportParameters parameters = new ExportParameters();
parameters.setExportType("JSON");
parameters.setPreparationId("prep-1234");
parameters.setStepId("step-1234");
final Preparation preparation = new Preparation();
preparation.setId("prep-1234");
preparation.setHeadId("step-1234");
configurePreparation(preparation, "prep-1234", "step-1234");
// When
final StreamingResponseBody body = strategy.execute(parameters);
body.writeTo(new NullOutputStream());
// Then
final ArgumentCaptor<Configuration> captor = ArgumentCaptor.forClass(Configuration.class);
verify(transformer).buildExecutable(any(), captor.capture());
assertEquals("prep-1234", captor.getValue().getPreparationId());
assertEquals("step-1234", captor.getValue().getPreparation().getHeadId());
}
use of org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody in project data-prep by Talend.
the class OptimizedExportStrategy 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 -> performOptimizedTransform(parameters, outputStream);
}
use of org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody in project data-prep by Talend.
the class PreparationExportStrategyTest method shouldUsedHeadPreparation.
@Test
public void shouldUsedHeadPreparation() throws IOException {
// Given
final ExportParameters parameters = new ExportParameters();
parameters.setExportType("JSON");
parameters.setPreparationId("prep-1234");
parameters.setStepId("head");
final Preparation preparation = new Preparation();
preparation.setId("prep-1234");
preparation.setHeadId("head");
configurePreparation(preparation, "prep-1234", "head");
// When
final StreamingResponseBody body = strategy.execute(parameters);
body.writeTo(new NullOutputStream());
// Then
final ArgumentCaptor<Configuration> captor = ArgumentCaptor.forClass(Configuration.class);
verify(transformer).buildExecutable(any(), captor.capture());
assertEquals("prep-1234", captor.getValue().getPreparationId());
assertEquals("head", captor.getValue().getPreparation().getHeadId());
}
use of org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody in project data-prep by Talend.
the class TransformationService method addPreparationInCache.
/**
* Add the following preparation in cache.
*
* @param preparation the preparation to cache.
* @param stepId the preparation step id.
*/
private void addPreparationInCache(Preparation preparation, String stepId) {
final ExportParameters exportParameters = new ExportParameters();
exportParameters.setPreparationId(preparation.getId());
exportParameters.setExportType("JSON");
exportParameters.setStepId(stepId);
exportParameters.setDatasetId(preparation.getDataSetId());
final StreamingResponseBody streamingResponseBody = executeSampleExportStrategy(exportParameters);
try {
// the result is not important here as it will be cached !
streamingResponseBody.writeTo(new NullOutputStream());
} catch (IOException e) {
throw new TDPException(UNEXPECTED_EXCEPTION, e);
}
}
use of org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody in project data-prep by Talend.
the class ApplyPreparationExportStrategy 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 -> executeApplyPreparation(parameters, outputStream);
}
Aggregations