Search in sources :

Example 11 with RequestSimpleParameterSet

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

the class DataController method getSeriesData.

@RequestMapping(value = "/{seriesId}/data", produces = { "application/json" }, method = RequestMethod.GET)
public ModelAndView getSeriesData(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 for item '{}' with query: {}", seriesId, map);
    IntervalWithTimeZone timespan = map.getTimespan();
    checkAgainstTimespanRestriction(timespan.toString());
    checkForUnknownDatasetIds(map, seriesId);
    RequestSimpleParameterSet parameters = RequestSimpleParameterSet.createForSingleSeries(seriesId, map);
    String handleAsValueTypeFallback = map.getAsString(Parameters.HANDLE_AS_VALUE_TYPE);
    String valueType = ValueType.extractType(seriesId, handleAsValueTypeFallback);
    IoProcessChain<?> ioChain = createIoFactory(valueType).withSimpleRequest(parameters).createProcessChain();
    DataCollection<?> formattedDataCollection = ioChain.getProcessedData();
    final Map<String, ?> processed = formattedDataCollection.getAllSeries();
    return map.isExpanded() ? new ModelAndView().addObject(processed) : new ModelAndView().addObject(processed.get(seriesId));
}
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) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with RequestSimpleParameterSet

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

the class TimeseriesDataController method getCollectionReport.

@RequestMapping(value = "/getData", produces = { "application/pdf" }, method = RequestMethod.POST)
public void getCollectionReport(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());
    response.setContentType(MimeType.APPLICATION_PDF.getMimeType());
    createIoFactory(parameterSet).withStyledRequest(map.mergeToStyledParameterSet(query)).createHandler(MimeType.APPLICATION_PDF.getMimeType()).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 13 with RequestSimpleParameterSet

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

the class TimeseriesDataController method getReport.

@RequestMapping(value = "/{timeseriesId}/getData", produces = { "application/pdf" }, method = RequestMethod.GET)
public void getReport(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 parameters = RequestSimpleParameterSet.createForSingleSeries(timeseriesId, map);
    checkAgainstTimespanRestriction(parameters.getTimespan());
    parameters.setGeneralize(map.isGeneralize());
    parameters.setExpanded(map.isExpanded());
    response.setContentType(MimeType.APPLICATION_PDF.getMimeType());
    createIoFactory(parameters).createHandler(MimeType.APPLICATION_PDF.getMimeType()).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 14 with RequestSimpleParameterSet

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

the class PreRenderingJob method renderWithStyle.

private void renderWithStyle(String datasetId, RenderingConfig renderingConfig, String interval) throws IOException, DatasetFactoryException, URISyntaxException {
    IntervalWithTimeZone timespan = createTimespanFromInterval(datasetId, interval);
    IoParameters config = createConfig(timespan.toString(), renderingConfig);
    DatasetOutput<?, ?> metadata = datasetService.getParameter(datasetId, config);
    IoStyleContext context = IoStyleContext.createContextForSingleSeries(metadata, config);
    RequestStyledParameterSet styleDefinition = context.getChartStyleDefinitions();
    context.setDimensions(new ChartDimension(styleDefinition.getWidth(), styleDefinition.getHeight()));
    RequestSimpleParameterSet parameters = RequestSimpleParameterSet.createForSingleSeries(datasetId, config);
    String chartQualifier = renderingConfig.getChartQualifier();
    FileOutputStream fos = createFile(datasetId, interval, chartQualifier);
    try (FileOutputStream out = fos) {
        createIoFactory(parameters).createHandler(IMAGE_EXTENSION).writeBinary(out);
        fos.flush();
    } catch (IoHandlerException | IOException e) {
        LOGGER.error("Image creation occures error.", e);
    }
}
Also used : RequestStyledParameterSet(org.n52.io.request.RequestStyledParameterSet) RequestSimpleParameterSet(org.n52.io.request.RequestSimpleParameterSet) FileOutputStream(java.io.FileOutputStream) ChartDimension(org.n52.io.quantity.img.ChartDimension) IoParameters(org.n52.io.request.IoParameters) IOException(java.io.IOException)

Example 15 with RequestSimpleParameterSet

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

the class TimeseriesDataController method getTimeseriesAsCsv.

private void getTimeseriesAsCsv(String timeseriesId, IoParameters query, HttpServletResponse response) throws IoHandlerException, DatasetFactoryException, URISyntaxException, MalformedURLException, IOException {
    checkIfUnknownTimeseries(query, timeseriesId);
    RequestSimpleParameterSet parameters = RequestSimpleParameterSet.createForSingleSeries(timeseriesId, query);
    checkAgainstTimespanRestriction(parameters.getTimespan());
    parameters.setGeneralize(query.isGeneralize());
    parameters.setExpanded(query.isExpanded());
    response.setCharacterEncoding("UTF-8");
    if (Boolean.parseBoolean(query.getOther(MimeType.APPLICATION_ZIP.name()))) {
        response.setContentType(MimeType.APPLICATION_ZIP.toString());
    } else {
        response.setContentType(MimeType.TEXT_CSV.toString());
    }
    createIoFactory(parameters).createHandler(MimeType.TEXT_CSV.toString()).writeBinary(response.getOutputStream());
}
Also used : RequestSimpleParameterSet(org.n52.io.request.RequestSimpleParameterSet)

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