Search in sources :

Example 1 with IoStyleContext

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

the class ChartRendererTest method shouldHaveUTCTimezoneIncludedInDomainAxisLabel.

@Test
public void shouldHaveUTCTimezoneIncludedInDomainAxisLabel() {
    IoStyleContext context = IoStyleContext.createEmpty();
    context.getChartStyleDefinitions().setTimespan(VALID_ISO8601_ABSOLUTE_START);
    MyChartRenderer chartRenderer = new MyChartRenderer(context);
    String label = chartRenderer.getXYPlot().getDomainAxis().getLabel();
    ISODateTimeFormat.dateTimeParser().withOffsetParsed().parseDateTime(VALID_ISO8601_ABSOLUTE_START.split("/")[1]);
    assertThat(label, is("Time (UTC)"));
}
Also used : IoStyleContext(org.n52.io.IoStyleContext) Test(org.junit.Test)

Example 2 with IoStyleContext

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

the class IoStyleContext method createContextForSingleSeries.

public static IoStyleContext createContextForSingleSeries(DatasetOutput metadata, IoParameters ioConfig) {
    RequestStyledParameterSet parameters = ioConfig.toStyledParameterSet();
    parameters.addSeriesWithStyleOptions(metadata.getId(), ioConfig.getStyle());
    return createContextWith(parameters, Collections.singletonList(metadata));
}
Also used : RequestStyledParameterSet(org.n52.io.request.RequestStyledParameterSet)

Example 3 with IoStyleContext

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

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

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

the class ChartRendererTest method shouldFormatTitleTemplateWhenPrerenderingTriggerIsActive.

@Test
public void shouldFormatTitleTemplateWhenPrerenderingTriggerIsActive() {
    QuantityDatasetOutput metadata = new QuantityDatasetOutput();
    SeriesParameters parameters = new SeriesParameters();
    parameters.setCategory(createParameter(new CategoryOutput(), "cat_1", "category"));
    parameters.setFeature(createParameter(new FeatureOutput(), "feat_1", "feature"));
    parameters.setOffering(createParameter(new OfferingOutput(), "off_1", "offering"));
    parameters.setPhenomenon(createParameter(new PhenomenonOutput(), "phen_1", "phenomenon"));
    parameters.setProcedure(createParameter(new ProcedureOutput(), "proc_1", "procedure"));
    parameters.setService(createParameter(new ServiceOutput(), "ser_1", "service"));
    metadata.setSeriesParameters(parameters);
    metadata.setId("timeseries");
    metadata.setUom("");
    PlatformOutput platformOutput = new PlatformOutput(PlatformType.STATIONARY_INSITU);
    platformOutput.setId("sta_1");
    platformOutput.setLabel("station");
    parameters.setPlatform(platformOutput);
    // build expected title
    StringBuilder expected = new StringBuilder();
    expected.append(parameters.getPlatform().getLabel());
    expected.append(" ").append(parameters.getPhenomenon().getLabel());
    expected.append(" ").append(parameters.getProcedure().getLabel());
    // expected.append(" ").append(parameters.getCategory().getLabel());
    expected.append(" (4 opted-out)");
    expected.append(" ").append(parameters.getOffering().getLabel());
    expected.append(" ").append(parameters.getFeature().getLabel());
    expected.append(" ").append(parameters.getService().getLabel());
    expected.append(" ").append(metadata.getUom());
    IoParameters ioConfig = createDefaults().extendWith("rendering_trigger", "prerendering");
    IoStyleContext context = IoStyleContext.createContextForSingleSeries(metadata, ioConfig);
    MyChartRenderer chartRenderer = new MyChartRenderer(context);
    // String template = "%1$s %2$s %3$s %4$s %5$s %6$s %7$s %8$s";
    String template = "%1$s %2$s %3$s (4 opted-out) %5$s %6$s %7$s %8$s";
    String actual = chartRenderer.formatTitle(metadata, template);
    assertThat(actual, is(expected.toString()));
}
Also used : OfferingOutput(org.n52.io.response.OfferingOutput) ServiceOutput(org.n52.io.response.ServiceOutput) FeatureOutput(org.n52.io.response.FeatureOutput) IoStyleContext(org.n52.io.IoStyleContext) IoParameters(org.n52.io.request.IoParameters) PlatformOutput(org.n52.io.response.PlatformOutput) CategoryOutput(org.n52.io.response.CategoryOutput) ProcedureOutput(org.n52.io.response.ProcedureOutput) SeriesParameters(org.n52.io.response.dataset.SeriesParameters) QuantityDatasetOutput(org.n52.io.response.dataset.quantity.QuantityDatasetOutput) PhenomenonOutput(org.n52.io.response.PhenomenonOutput) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 IoStyleContext (org.n52.io.IoStyleContext)4 IoParameters (org.n52.io.request.IoParameters)4 RequestStyledParameterSet (org.n52.io.request.RequestStyledParameterSet)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ChartDimension (org.n52.io.quantity.img.ChartDimension)1 RequestSimpleParameterSet (org.n52.io.request.RequestSimpleParameterSet)1 CategoryOutput (org.n52.io.response.CategoryOutput)1 FeatureOutput (org.n52.io.response.FeatureOutput)1 OfferingOutput (org.n52.io.response.OfferingOutput)1 PhenomenonOutput (org.n52.io.response.PhenomenonOutput)1 PlatformOutput (org.n52.io.response.PlatformOutput)1 ProcedureOutput (org.n52.io.response.ProcedureOutput)1 ServiceOutput (org.n52.io.response.ServiceOutput)1 SeriesParameters (org.n52.io.response.dataset.SeriesParameters)1 QuantityDatasetOutput (org.n52.io.response.dataset.quantity.QuantityDatasetOutput)1