use of org.n52.io.handler.IoHandlerException in project series-rest-api by 52North.
the class PDFReportGenerator method generateOutput.
public void generateOutput(DataCollection<Data<QuantityValue>> data) throws IoHandlerException {
try {
generateTimeseriesChart(data);
generateTimeseriesMetadata();
} catch (IOException e) {
throw new IoHandlerException("Error handling (temp) file!", e);
}
}
use of org.n52.io.handler.IoHandlerException in project series-rest-api by 52North.
the class PreRenderingJob method renderWithStyle.
private void renderWithStyle(String datasetId, RenderingConfig renderingConfig, String interval) throws IOException, DatasetFactoryException, URISyntaxException {
IntervalWithTimeZone timespan = createTimespanFromInterval(datasetId, interval);
IoParameters parameters = createConfig(datasetId, timespan.toString(), renderingConfig);
String chartQualifier = renderingConfig.getChartQualifier();
FileOutputStream fos = createFile(datasetId, interval, chartQualifier);
try (FileOutputStream out = fos) {
createIoFactory(parameters).createHandler(IMAGE_EXTENSION).writeBinary(out);
fos.flush();
} catch (IoHandlerException | IOException e) {
LOGGER.error("Image creation occures error.", e);
}
}
use of org.n52.io.handler.IoHandlerException in project series-rest-api by 52North.
the class PreRenderingJob method renderWithStyle.
private void renderWithStyle(String datasetId, RenderingConfig renderingConfig, String interval) throws IOException, DatasetFactoryException, URISyntaxException {
IntervalWithTimeZone timespan = createTimespanFromInterval(datasetId, interval);
IoParameters config = createConfig(timespan.toString(), renderingConfig);
DatasetOutput<?, ?> metadata = datasetService.getParameter(datasetId, config);
IoStyleContext context = IoStyleContext.createContextForSingleSeries(metadata, config);
RequestStyledParameterSet styleDefinition = context.getChartStyleDefinitions();
context.setDimensions(new ChartDimension(styleDefinition.getWidth(), styleDefinition.getHeight()));
RequestSimpleParameterSet parameters = RequestSimpleParameterSet.createForSingleSeries(datasetId, config);
String chartQualifier = renderingConfig.getChartQualifier();
FileOutputStream fos = createFile(datasetId, interval, chartQualifier);
try (FileOutputStream out = fos) {
createIoFactory(parameters).createHandler(IMAGE_EXTENSION).writeBinary(out);
fos.flush();
} catch (IoHandlerException | IOException e) {
LOGGER.error("Image creation occures error.", e);
}
}
use of org.n52.io.handler.IoHandlerException in project series-rest-api by 52North.
the class TimeseriesDataController method getTimeseriesAsCsv.
private void getTimeseriesAsCsv(String timeseriesId, IoParameters query, HttpServletResponse response) throws IoHandlerException, DatasetFactoryException, URISyntaxException, MalformedURLException, IOException {
checkIfUnknownTimeseries(query, timeseriesId);
RequestSimpleParameterSet parameters = RequestSimpleParameterSet.createForSingleSeries(timeseriesId, query);
checkAgainstTimespanRestriction(parameters.getTimespan());
parameters.setGeneralize(query.isGeneralize());
parameters.setExpanded(query.isExpanded());
response.setCharacterEncoding("UTF-8");
if (Boolean.parseBoolean(query.getOther(MimeType.APPLICATION_ZIP.name()))) {
response.setContentType(MimeType.APPLICATION_ZIP.toString());
} else {
response.setContentType(MimeType.TEXT_CSV.toString());
}
createIoFactory(parameters).createHandler(MimeType.TEXT_CSV.toString()).writeBinary(response.getOutputStream());
}
use of org.n52.io.handler.IoHandlerException in project series-rest-api by 52North.
the class PDFReportGenerator method encodeAndWriteTo.
@Override
public void encodeAndWriteTo(DataCollection<Data<QuantityValue>> data, OutputStream stream) throws IoHandlerException {
try {
generateOutput(data);
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = cfgBuilder.build(document.newInputStream());
URI baseURI = new File(".").toURI();
FopFactory fopFactory = new FopFactoryBuilder(baseURI).setConfiguration(cfg).build();
final String mimeType = Constants.APPLICATION_PDF;
Fop fop = fopFactory.newFop(mimeType, stream);
// FopFactory fopFactory = FopFactory.newInstance(cfg);
// Fop fop = fopFactory.newFop(APPLICATION_PDF.getMimeType(), stream);
// FopFactory fopFactory = fopFactoryBuilder.build();
// Fop fop = fopFactory.newFop(APPLICATION_PDF.getMimeType(), stream);
// Create PDF via XSLT transformation
TransformerFactory transFact = TransformerFactory.newInstance();
StreamSource transformationRule = getTransforamtionRule();
Transformer transformer = transFact.newTransformer(transformationRule);
Source source = new StreamSource(document.newInputStream());
Result result = new SAXResult(fop.getDefaultHandler());
if (LOGGER.isDebugEnabled()) {
try {
File tempFile = File.createTempFile(TEMP_FILE_PREFIX, ".xml");
StreamResult debugResult = new StreamResult(tempFile);
transformer.transform(source, debugResult);
String xslResult = XmlObject.Factory.parse(tempFile).xmlText();
LOGGER.debug("xsl-fo input (locale '{}'): {}", i18n.getTwoDigitsLanguageCode(), xslResult);
} catch (IOException | TransformerException | XmlException e) {
LOGGER.error("Could not debug XSL result output!", e);
}
}
// XXX debug, diagram is not embedded
transformer.transform(source, result);
} catch (FOPException e) {
throw new IoParseException("Failed to create Formatting Object Processor (FOP)", e);
} catch (ConfigurationException e) {
throw new IoParseException("Failed to read config for Formatting Object Processor (FOP)", e);
} catch (TransformerConfigurationException e) {
throw new IoParseException("Invalid transform configuration. Inspect xslt!", e);
} catch (TransformerException e) {
throw new IoParseException("Could not generate PDF report!", e);
}
}
Aggregations