Search in sources :

Example 16 with RequestSimpleParameterSet

use of org.n52.io.request.RequestSimpleParameterSet in project series-rest-api by 52North.

the class TimeseriesDataController method getCollectionData.

@RequestMapping(value = "/getData", produces = { "application/json" }, method = RequestMethod.POST)
public ModelAndView getCollectionData(HttpServletResponse response, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE) String locale, @RequestBody RequestSimpleParameterSet query) throws Exception {
    RequestUtils.overrideQueryLocaleWhenSet(locale, query);
    checkIfUnknownTimeseries(query, query.getDatasets());
    if (query.isSetRawFormat()) {
        getRawCollectionData(response, locale, query);
        return null;
    }
    DataCollection<QuantityData> seriesData = getTimeseriesData(query);
    DataCollection<?> formattedDataCollection = format(seriesData, query.getFormat());
    return new ModelAndView().addObject(formattedDataCollection.getAllSeries());
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) QuantityData(org.n52.io.response.dataset.quantity.QuantityData) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with RequestSimpleParameterSet

use of org.n52.io.request.RequestSimpleParameterSet in project series-rest-api by 52North.

the class TimeseriesDataController method getCollectionChart.

@RequestMapping(value = "/getData", produces = { "image/png" }, method = RequestMethod.POST)
public void getCollectionChart(HttpServletResponse response, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE) String locale, @RequestBody RequestStyledParameterSet query) throws Exception {
    RequestUtils.overrideQueryLocaleWhenSet(locale, query);
    IoParameters map = QueryParameters.createFromQuery(query);
    checkIfUnknownTimeseries(map, query.getDatasets());
    RequestSimpleParameterSet parameterSet = map.mergeToSimpleParameterSet(query);
    checkAgainstTimespanRestriction(parameterSet.getTimespan());
    parameterSet.setGeneralize(map.isGeneralize());
    parameterSet.setExpanded(map.isExpanded());
    parameterSet.setBase64(map.isBase64());
    response.setContentType(MimeType.IMAGE_PNG.getMimeType());
    createIoFactory(parameterSet).withStyledRequest(query).createHandler(MimeType.IMAGE_PNG.toString()).writeBinary(response.getOutputStream());
}
Also used : RequestSimpleParameterSet(org.n52.io.request.RequestSimpleParameterSet) IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with RequestSimpleParameterSet

use of org.n52.io.request.RequestSimpleParameterSet in project series-rest-api by 52North.

the class DataController method writeRawData.

private void writeRawData(RequestSimpleParameterSet parameters, HttpServletResponse response) throws InternalServerException, ResourceNotFoundException, BadRequestException {
    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)) {
        if (inputStream == null) {
            throw new ResourceNotFoundException("No raw data found.");
        }
        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) ResourceNotFoundException(org.n52.web.exception.ResourceNotFoundException)

Example 19 with RequestSimpleParameterSet

use of org.n52.io.request.RequestSimpleParameterSet in project series-rest-api by 52North.

the class DataController method getSeriesReport.

@RequestMapping(value = "/{seriesId}/data", produces = { "application/pdf" }, method = RequestMethod.GET)
public void getSeriesReport(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 report for '{}' with query: {}", seriesId, map);
    RequestSimpleParameterSet parameters = RequestSimpleParameterSet.createForSingleSeries(seriesId, map);
    checkAgainstTimespanRestriction(parameters.getTimespan());
    checkForUnknownDatasetIds(map, seriesId);
    final String datasetType = parameters.getValueType();
    String outputFormat = MimeType.APPLICATION_PDF.toString();
    response.setContentType(outputFormat);
    createIoFactory(datasetType).withSimpleRequest(parameters).createHandler(outputFormat).writeBinary(response.getOutputStream());
}
Also used : RequestSimpleParameterSet(org.n52.io.request.RequestSimpleParameterSet) IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RequestSimpleParameterSet (org.n52.io.request.RequestSimpleParameterSet)14 IoParameters (org.n52.io.request.IoParameters)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 IOException (java.io.IOException)3 IntervalWithTimeZone (org.n52.io.IntervalWithTimeZone)3 QuantityData (org.n52.io.response.dataset.quantity.QuantityData)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 InputStream (java.io.InputStream)2 RequestStyledParameterSet (org.n52.io.request.RequestStyledParameterSet)2 RawDataService (org.n52.series.spi.srv.RawDataService)2 InternalServerException (org.n52.web.exception.InternalServerException)2 ResourceNotFoundException (org.n52.web.exception.ResourceNotFoundException)2 FileOutputStream (java.io.FileOutputStream)1 GeneralizingQuantityService (org.n52.io.quantity.generalize.GeneralizingQuantityService)1 ChartDimension (org.n52.io.quantity.img.ChartDimension)1 Stopwatch (org.n52.web.common.Stopwatch)1 BadRequestException (org.n52.web.exception.BadRequestException)1