Search in sources :

Example 1 with RenderingConfig

use of org.n52.io.task.PreRenderingConfig.RenderingConfig 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 parameters = createConfig(datasetId, timespan.toString(), renderingConfig);
    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 : IoHandlerException(org.n52.io.handler.IoHandlerException) FileOutputStream(java.io.FileOutputStream) IntervalWithTimeZone(org.n52.io.IntervalWithTimeZone) IoParameters(org.n52.io.request.IoParameters) IOException(java.io.IOException)

Example 2 with RenderingConfig

use of org.n52.io.task.PreRenderingConfig.RenderingConfig 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 3 with RenderingConfig

use of org.n52.io.task.PreRenderingConfig.RenderingConfig 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 4 with RenderingConfig

use of org.n52.io.task.PreRenderingConfig.RenderingConfig in project series-rest-api by 52North.

the class PreRenderingJob method executeInternal.

@Override
protected void executeInternal(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.getDatasetStyles();
    for (RenderingConfig config : phenomenonStyles) {
        Map<String, String> parameters = new HashMap<>();
        parameters.put(Parameters.PHENOMENA, config.getId());
        parameters.put(Parameters.FILTER_DATASET_TYPES, "timeseries");
        parameters.put(Parameters.FILTER_OBSERVATION_TYPES, "simple");
        parameters.put(Parameters.FILTER_VALUE_TYPES, "quantity");
        IoParameters query = IoParameters.createFromSingleValueMap(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.task.PreRenderingConfig.RenderingConfig)

Aggregations

IoParameters (org.n52.io.request.IoParameters)4 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Stopwatch (org.n52.web.common.Stopwatch)2 JobDataMap (org.quartz.JobDataMap)2 JobDetail (org.quartz.JobDetail)2 IntervalWithTimeZone (org.n52.io.IntervalWithTimeZone)1 RenderingConfig (org.n52.io.PrerenderingJobConfig.RenderingConfig)1 IoHandlerException (org.n52.io.handler.IoHandlerException)1 ChartDimension (org.n52.io.quantity.img.ChartDimension)1 RequestSimpleParameterSet (org.n52.io.request.RequestSimpleParameterSet)1 RequestStyledParameterSet (org.n52.io.request.RequestStyledParameterSet)1 RenderingConfig (org.n52.io.task.PreRenderingConfig.RenderingConfig)1