Search in sources :

Example 21 with IoParameters

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

the class PreRenderingJob method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    if (interrupted) {
        return;
    }
    LOGGER.info("Start prerendering task");
    final Stopwatch stopwatch = Stopwatch.startStopwatch();
    final JobDetail details = context.getJobDetail();
    JobDataMap jobDataMap = details.getJobDataMap();
    taskConfigPrerendering = readJobConfig(jobDataMap.getString(JOB_DATA_CONFIG_FILE));
    webappFolder = jobDataMap.getString(JOB_DATA_WEBAPP_FOLDER);
    List<RenderingConfig> phenomenonStyles = taskConfigPrerendering.getPhenomenonStyles();
    List<RenderingConfig> styles = taskConfigPrerendering.getSeriesStyles();
    for (RenderingConfig config : phenomenonStyles) {
        Map<String, String> parameters = new HashMap<>();
        parameters.put("phenomenon", config.getId());
        IoParameters query = QueryParameters.createFromQuery(parameters);
        for (DatasetOutput<?, ?> metadata : datasetService.getCondensedParameters(query)) {
            String timeseriesId = metadata.getId();
            renderConfiguredIntervals(timeseriesId, config);
            if (interrupted) {
                return;
            }
        }
    }
    for (RenderingConfig config : styles) {
        renderConfiguredIntervals(config.getId(), config);
        if (interrupted) {
            return;
        }
    }
    LOGGER.debug("prerendering took '{}'", stopwatch.stopInSeconds());
}
Also used : JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) HashMap(java.util.HashMap) Stopwatch(org.n52.web.common.Stopwatch) IoParameters(org.n52.io.request.IoParameters) RenderingConfig(org.n52.io.PrerenderingJobConfig.RenderingConfig)

Example 22 with IoParameters

use of org.n52.io.request.IoParameters 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 23 with IoParameters

use of org.n52.io.request.IoParameters 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 24 with IoParameters

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

the class ChartRendererTest method shouldPrintExplicitlySetOutputTimezoneInDomainAxisLabel.

@Test
public void shouldPrintExplicitlySetOutputTimezoneInDomainAxisLabel() {
    IoParameters config = IoParameters.createDefaults().removeAllOf("outputTimezone").extendWith("outputTimezone", "America/Los_Angeles");
    IoStyleContext context = IoStyleContext.create(config);
    String label = new MyChartRenderer(context).getXYPlot().getDomainAxis().getLabel();
    assertThat(label, is("Time (PDT)"));
}
Also used : IoStyleContext(org.n52.io.IoStyleContext) IoParameters(org.n52.io.request.IoParameters) Test(org.junit.Test)

Example 25 with IoParameters

use of org.n52.io.request.IoParameters 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)

Aggregations

IoParameters (org.n52.io.request.IoParameters)31 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)20 RequestSimpleParameterSet (org.n52.io.request.RequestSimpleParameterSet)14 ModelAndView (org.springframework.web.servlet.ModelAndView)7 Test (org.junit.Test)5 IntervalWithTimeZone (org.n52.io.IntervalWithTimeZone)4 Stopwatch (org.n52.web.common.Stopwatch)4 IoStyleContext (org.n52.io.IoStyleContext)3 RequestStyledParameterSet (org.n52.io.request.RequestStyledParameterSet)3 ResourceNotFoundException (org.n52.web.exception.ResourceNotFoundException)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 WKTReader (com.vividsolutions.jts.io.WKTReader)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1 I18N (org.n52.io.I18N)1