use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.
the class DataController method getSeriesAsCsv.
@RequestMapping(value = "/{datasetId}/observations", produces = { Constants.TEXT_CSV }, method = RequestMethod.GET)
public void getSeriesAsCsv(HttpServletRequest request, HttpServletResponse response, @PathVariable String datasetId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE, required = false) String httpLocale, @RequestParam(required = false) MultiValueMap<String, String> query) throws Exception {
IoParameters parameters = createParameters(datasetId, query, httpLocale, response);
LOGGER.debug("get data collection csv for '{}' with query: {}", datasetId, parameters);
checkAgainstTimespanRestriction(parameters.getTimespan());
checkForUnknownDatasetId(parameters, datasetId);
String extension = ".";
response.setCharacterEncoding(DEFAULT_RESPONSE_ENCODING);
if (Boolean.parseBoolean(parameters.getOther(Parameters.ZIP))) {
response.setContentType(Constants.APPLICATION_ZIP);
extension += Parameters.ZIP;
} else {
response.setContentType(Constants.TEXT_CSV);
extension += "csv";
}
response.setHeader(CONTENT_DISPOSITION_HEADER, CONTENT_DISPOSITION_VALUE_TEMPLATE + validateResponseSplitting(datasetId) + validateResponseSplitting(extension) + "\"");
// final String datasetType = getValueType(parameters);
final String valueType = getValueType(parameters, request.getRequestURI());
createIoFactory(valueType).setParameters(parameters).createHandler(Constants.TEXT_CSV).writeBinary(response.getOutputStream());
}
use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.
the class DataController method writeRawData.
private void writeRawData(IoParameters parameters, HttpServletResponse response) throws InternalServerException, ResourceNotFoundException, BadRequestException {
LOGGER.debug("get raw data collection with parameters: {}", parameters);
if (!dataService.supportsRawData()) {
throw new BadRequestException("Querying of raw timeseries data is not supported " + "by the underlying service!");
}
final RawDataService rawDataService = dataService.getRawDataService();
try (InputStream inputStream = rawDataService.getRawData(parameters)) {
response.setContentType(parameters.getRawFormat());
IOUtils.copyLarge(inputStream, response.getOutputStream());
} catch (IOException e) {
throw new InternalServerException("Error while querying raw data", e);
}
}
use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.
the class DataController method getSeriesReport.
@RequestMapping(value = "/{datasetId}/observations", produces = { Constants.APPLICATION_PDF }, method = RequestMethod.GET)
public void getSeriesReport(HttpServletRequest request, HttpServletResponse response, @PathVariable String datasetId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE, required = false) String httpLocale, @RequestParam(required = false) MultiValueMap<String, String> query) throws Exception {
IoParameters parameters = createParameters(datasetId, query, httpLocale, response);
LOGGER.debug("get data collection report for '{}' with query: {}", datasetId, parameters);
checkAgainstTimespanRestriction(parameters.getTimespan());
checkForUnknownDatasetId(parameters, datasetId);
// final String datasetType = getValueType(parameters);
final String valueType = getValueType(parameters, request.getRequestURI());
String outputFormat = Constants.APPLICATION_PDF;
response.setContentType(outputFormat);
response.setHeader(CONTENT_DISPOSITION_HEADER, CONTENT_DISPOSITION_VALUE_TEMPLATE + validateResponseSplitting(datasetId) + ".pdf\"");
createIoFactory(valueType).setParameters(parameters).createHandler(outputFormat).writeBinary(response.getOutputStream());
}
use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.
the class DataController method getSeriesAsZippedCsv.
@RequestMapping(value = "/{datasetId}/observations", produces = { Constants.APPLICATION_ZIP }, method = RequestMethod.GET)
public void getSeriesAsZippedCsv(HttpServletRequest request, HttpServletResponse response, @PathVariable String datasetId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE, required = false) String httpLocale, @RequestParam(required = false) MultiValueMap<String, String> query) throws Exception {
// Needed to retrieve Time Ends from Database
query.putIfAbsent(SHOWTIMEINTERVALS_QUERY_OPTION, Arrays.asList(Boolean.TRUE.toString()));
IoParameters parameters = createParameters(datasetId, query, httpLocale, response);
LOGGER.debug("get data collection zip for '{}' with query: {}", datasetId, parameters);
checkAgainstTimespanRestriction(parameters.getTimespan());
checkForUnknownDatasetId(parameters, datasetId);
response.setCharacterEncoding(DEFAULT_RESPONSE_ENCODING);
response.setContentType(Constants.APPLICATION_ZIP);
response.setHeader(CONTENT_DISPOSITION_HEADER, CONTENT_DISPOSITION_VALUE_TEMPLATE + validateResponseSplitting(datasetId) + ".zip\"");
// final String datasetType = getValueType(parameters);
final String valueType = getValueType(parameters, request.getRequestURI());
createIoFactory(valueType).setParameters(parameters).createHandler(Constants.APPLICATION_ZIP).writeBinary(response.getOutputStream());
}
use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.
the class TimeseriesDataController method getSeriesChart.
@RequestMapping(value = "/{datasetId}/observations", produces = { Constants.IMAGE_PNG }, method = RequestMethod.GET)
public void getSeriesChart(HttpServletRequest request, HttpServletResponse response, @PathVariable String datasetId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE, required = false) String httpLocale, @RequestParam(required = false) MultiValueMap<String, String> query) throws Exception {
IoParameters parameters = createParameters(datasetId, query, httpLocale, response);
LOGGER.debug("get data collection chart for '{}' with query: {}", datasetId, parameters);
checkAgainstTimespanRestriction(parameters.getTimespan());
checkForUnknownDatasetId(parameters, datasetId);
// String handleAsValueTypeFallback = parameters.getAsString(Parameters.HANDLE_AS_VALUE_TYPE);
// String valueType = ValueType.extractType(datasetId, handleAsValueTypeFallback);
String valueType = getValueType(parameters, request.getRequestURI());
String outputFormat = Constants.IMAGE_PNG;
response.setContentType(outputFormat);
createIoFactory(valueType).setParameters(parameters).createHandler(outputFormat).writeBinary(response.getOutputStream());
}
Aggregations