use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.
the class PDFReportGenerator method encodeAndWriteTo.
@Override
public void encodeAndWriteTo(DataCollection<QuantityData> data, OutputStream stream) throws IoParseException {
try {
generateOutput(data);
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = cfgBuilder.build(document.newInputStream());
FopFactory fopFactory = new FopFactoryBuilder(baseURI).setConfiguration(cfg).build();
final String mimeType = MimeType.APPLICATION_PDF.getMimeType();
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 (SAXException | ConfigurationException | IOException 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);
}
}
use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.
the class PDFReportGenerator method generateOutput.
public void generateOutput(DataCollection<QuantityData> data) throws IoParseException {
try {
generateTimeseriesChart(data);
generateTimeseriesMetadata();
} catch (IOException e) {
throw new IoParseException("Error handling (temp) file!", e);
}
}
use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.
the class PDFReportGenerator method addDataTable.
private void addDataTable(TimeSeries timeseries, TimeseriesMetadataOutput metadata, TvpDataCollection<QuantityData> dataCollection) {
TableType dataTable = timeseries.addNewTable();
// TODO add language context
dataTable.setLeftColHeader("Date");
dataTable.setRightColHeader(createValueTableHeader(metadata));
QuantityData data = dataCollection.getSeries(metadata.getId());
for (QuantityValue valueEntry : data.getValues()) {
Entry entry = dataTable.addNewEntry();
// TODO update TableType schema to allow start/end time
entry.setTime(new DateTime(valueEntry.getTimestamp()).toString());
entry.setValue(Double.toString(valueEntry.getValue()));
}
}
use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.
the class DataController method getSeriesChart.
@RequestMapping(value = "/{seriesId}/data", produces = { "image/png" }, method = RequestMethod.GET)
public void getSeriesChart(HttpServletResponse response, @PathVariable String seriesId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE) String locale, @RequestParam(required = false) MultiValueMap<String, String> query) throws Exception {
RequestUtils.overrideQueryLocaleWhenSet(locale, query);
IoParameters map = QueryParameters.createFromQuery(query);
LOGGER.debug("get data collection chart for '{}' with query: {}", seriesId, map);
checkAgainstTimespanRestriction(map.getTimespan().toString());
checkForUnknownDatasetIds(map, seriesId);
String handleAsValueTypeFallback = map.getAsString(Parameters.HANDLE_AS_VALUE_TYPE);
String valueType = ValueType.extractType(seriesId, handleAsValueTypeFallback);
RequestSimpleParameterSet parameters = map.toSimpleParameterSet();
String outputFormat = MimeType.IMAGE_PNG.toString();
response.setContentType(outputFormat);
createIoFactory(valueType).withSimpleRequest(parameters).createHandler(outputFormat).writeBinary(response.getOutputStream());
}
use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.
the class ParameterController method getExtras.
@Override
public Map<String, Object> getExtras(String resourceId, String locale, MultiValueMap<String, String> query) {
RequestUtils.overrideQueryLocaleWhenSet(locale, query);
IoParameters map = QueryParameters.createFromQuery(query);
LOGGER.debug("getExtras() with id '{}' and query '{}'", resourceId, map);
Map<String, Object> extras = new HashMap<>();
for (MetadataExtension<T> extension : metadataExtensions) {
T from = parameterService.getParameter(resourceId, map);
final Map<String, Object> furtherExtras = extension.getExtras(from, map);
Collection<String> overridableKeys = checkForOverridingData(extras, furtherExtras);
if (!overridableKeys.isEmpty()) {
String[] keys = overridableKeys.toArray(new String[0]);
LOGGER.warn("Metadata extension overrides existing extra data: {}", Arrays.toString(keys));
}
extras.putAll(furtherExtras);
}
return extras;
}
Aggregations