Search in sources :

Example 6 with IntervalWithTimeZone

use of org.n52.io.IntervalWithTimeZone 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 7 with IntervalWithTimeZone

use of org.n52.io.IntervalWithTimeZone 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 8 with IntervalWithTimeZone

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

the class IoParametersTest method when_timespanWithNow_then_normalizeWithDateString.

@Test
public void when_timespanWithNow_then_normalizeWithDateString() {
    DateTimeFormatter dateFormat = DateTimeFormat.forPattern("YYYY-MM-dd");
    String now = dateFormat.print(new DateTime());
    IoParameters parameters = createDefaults().extendWith(Parameters.TIMESPAN, "PT4h/now");
    IntervalWithTimeZone expected = new IntervalWithTimeZone("PT4h/" + now);
    assertThat(parameters.getNormalizedTimespan(dateFormat), is(expected.toString()));
}
Also used : IntervalWithTimeZone(org.n52.io.IntervalWithTimeZone) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 9 with IntervalWithTimeZone

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

the class RequestParameterSet method setTimespan.

/**
 * @param timespan
 *        the timespan to set.
 */
public void setTimespan(String timespan) {
    IntervalWithTimeZone nonNullTimespan = timespan == null ? IoParameters.createDefaultTimespan() : validateTimespan(timespan);
    setParameter(Parameters.TIMESPAN, IoParameters.getJsonNodeFrom(nonNullTimespan.toString()));
}
Also used : IntervalWithTimeZone(org.n52.io.IntervalWithTimeZone)

Aggregations

IntervalWithTimeZone (org.n52.io.IntervalWithTimeZone)8 IoParameters (org.n52.io.request.IoParameters)4 DateTime (org.joda.time.DateTime)3 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 RequestSimpleParameterSet (org.n52.io.request.RequestSimpleParameterSet)2 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1 Test (org.junit.jupiter.api.Test)1 IoHandlerException (org.n52.io.handler.IoHandlerException)1 ChartDimension (org.n52.io.quantity.img.ChartDimension)1 RequestStyledParameterSet (org.n52.io.request.RequestStyledParameterSet)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1