Search in sources :

Example 6 with RequestSimpleParameterSet

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

the class TimeseriesDataController method processRawDataRequest.

private void processRawDataRequest(HttpServletResponse response, RequestSimpleParameterSet query) {
    if (!timeseriesDataService.supportsRawData()) {
        throwNewRawDataQueryNotSupportedException();
    }
    final RawDataService rawDataService = timeseriesDataService.getRawDataService();
    try (InputStream inputStream = rawDataService.getRawData(query)) {
        if (inputStream == null) {
            throw new ResourceNotFoundException("No raw data found.");
        }
        response.setContentType(query.getFormat());
        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) IOException(java.io.IOException) ResourceNotFoundException(org.n52.web.exception.ResourceNotFoundException)

Example 7 with RequestSimpleParameterSet

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

the class TimeseriesDataController method getTimeseriesData.

private DataCollection<QuantityData> getTimeseriesData(RequestSimpleParameterSet parameters) {
    Stopwatch stopwatch = Stopwatch.startStopwatch();
    DataCollection<QuantityData> timeseriesData = parameters.isGeneralize() ? new GeneralizingQuantityService(timeseriesDataService).getData(parameters) : timeseriesDataService.getData(parameters);
    LOGGER.debug("Processing request took {} seconds.", stopwatch.stopInSeconds());
    return timeseriesData;
}
Also used : Stopwatch(org.n52.web.common.Stopwatch) GeneralizingQuantityService(org.n52.io.quantity.generalize.GeneralizingQuantityService) QuantityData(org.n52.io.response.dataset.quantity.QuantityData)

Example 8 with RequestSimpleParameterSet

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

the class TimeseriesDataController method getChart.

@RequestMapping(value = "/{timeseriesId}/getData", produces = { "image/png" }, method = RequestMethod.GET)
public void getChart(HttpServletResponse response, @PathVariable String timeseriesId, @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);
    checkIfUnknownTimeseries(map, timeseriesId);
    RequestSimpleParameterSet parameterSet = RequestSimpleParameterSet.createForSingleSeries(timeseriesId, map);
    RequestStyledParameterSet styledParameters = map.toStyledParameterSet();
    checkAgainstTimespanRestriction(parameterSet.getTimespan());
    parameterSet.setGeneralize(map.isGeneralize());
    parameterSet.setBase64(map.isBase64());
    parameterSet.setExpanded(map.isExpanded());
    response.setContentType(MimeType.IMAGE_PNG.getMimeType());
    createIoFactory(parameterSet).withStyledRequest(styledParameters).createHandler(MimeType.IMAGE_PNG.toString()).writeBinary(response.getOutputStream());
}
Also used : RequestSimpleParameterSet(org.n52.io.request.RequestSimpleParameterSet) RequestStyledParameterSet(org.n52.io.request.RequestStyledParameterSet) IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with RequestSimpleParameterSet

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

the class TimeseriesDataController method getData.

@RequestMapping(value = "/{timeseriesId}/getData", produces = { "application/json" }, method = RequestMethod.GET)
public ModelAndView getData(HttpServletResponse response, @PathVariable String timeseriesId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE) String locale, @RequestParam(required = false) MultiValueMap<String, String> query) {
    RequestUtils.overrideQueryLocaleWhenSet(locale, query);
    IoParameters map = QueryParameters.createFromQuery(query);
    checkIfUnknownTimeseries(map, timeseriesId);
    IntervalWithTimeZone timespan = map.getTimespan();
    checkAgainstTimespanRestriction(timespan.toString());
    RequestSimpleParameterSet parameters = RequestSimpleParameterSet.createForSingleSeries(timeseriesId, map);
    if (map.getResultTime() != null) {
        parameters.setResultTime(map.getResultTime().toString());
    }
    parameters.setGeneralize(map.isGeneralize());
    parameters.setExpanded(map.isExpanded());
    // TODO add paging
    DataCollection<QuantityData> seriesData = getTimeseriesData(parameters);
    DataCollection<?> formattedDataCollection = format(seriesData, map.getFormat());
    if (map.isExpanded()) {
        return new ModelAndView().addObject(formattedDataCollection.getAllSeries());
    }
    Object formattedTimeseries = formattedDataCollection.getAllSeries().get(timeseriesId);
    return new ModelAndView().addObject(formattedTimeseries);
}
Also used : RequestSimpleParameterSet(org.n52.io.request.RequestSimpleParameterSet) ModelAndView(org.springframework.web.servlet.ModelAndView) IoParameters(org.n52.io.request.IoParameters) IntervalWithTimeZone(org.n52.io.IntervalWithTimeZone) QuantityData(org.n52.io.response.dataset.quantity.QuantityData) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with RequestSimpleParameterSet

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

the class RequestSimpleParameterSet method createForSingleSeries.

public static RequestSimpleParameterSet createForSingleSeries(String seriesId, IoParameters parameters) {
    RequestSimpleParameterSet parameterSet = parameters.toSimpleParameterSet();
    parameterSet.setDatasets(new String[] { seriesId });
    IntervalWithTimeZone timespan = parameters.getTimespan();
    parameterSet.setTimespan(timespan.toString());
    return parameterSet;
}
Also used : IntervalWithTimeZone(org.n52.io.IntervalWithTimeZone)

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