Search in sources :

Example 26 with Data

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());
}
Also used : IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with Data

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);
    }
}
Also used : RawDataService(org.n52.series.spi.srv.RawDataService) InputStream(java.io.InputStream) InternalServerException(org.n52.web.exception.InternalServerException) BadRequestException(org.n52.web.exception.BadRequestException) IOException(java.io.IOException)

Example 28 with Data

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());
}
Also used : IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with Data

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());
}
Also used : IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with Data

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());
}
Also used : IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IoParameters (org.n52.io.request.IoParameters)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 Data (org.n52.io.response.dataset.Data)13 IOException (java.io.IOException)12 QuantityValue (org.n52.io.response.dataset.quantity.QuantityValue)11 HashMap (java.util.HashMap)6 RequestSimpleParameterSet (org.n52.io.request.RequestSimpleParameterSet)6 QuantityData (org.n52.io.response.dataset.quantity.QuantityData)6 InputStream (java.io.InputStream)5 XmlObject (org.apache.xmlbeans.XmlObject)5 IoParseException (org.n52.io.IoParseException)5 File (java.io.File)4 Test (org.junit.Test)4 InternalServerException (org.n52.web.exception.InternalServerException)4 ModelAndView (org.springframework.web.servlet.ModelAndView)4 BigDecimal (java.math.BigDecimal)3 ElasticsearchAwareTest (org.n52.iceland.statistics.basetests.ElasticsearchAwareTest)3 ResultTimeClassifiedData (org.n52.io.format.ResultTimeClassifiedData)3 RawDataService (org.n52.series.spi.srv.RawDataService)3 DecodingException (org.n52.svalbard.decode.exception.DecodingException)3