Search in sources :

Example 6 with DatasetParameters

use of org.n52.io.response.dataset.DatasetParameters in project series-rest-api by 52North.

the class ChartRendererTest method shouldFormatTitleTemplateWhenPrerenderingTriggerIsActive.

@Test
public void shouldFormatTitleTemplateWhenPrerenderingTriggerIsActive() {
    DatasetParameters datasetParameters = new DatasetParameters();
    datasetParameters.setCategory(createParameter(new CategoryOutput(), "cat_1", "category"));
    FeatureOutput feature = createParameter(new FeatureOutput(), "feat_1", "feature");
    datasetParameters.setOffering(createParameter(new OfferingOutput(), "off_1", "offering"));
    datasetParameters.setPhenomenon(createParameter(new PhenomenonOutput(), "phen_1", "phenomenon"));
    datasetParameters.setProcedure(createParameter(new ProcedureOutput(), "proc_1", "procedure"));
    datasetParameters.setService(createParameter(new ServiceOutput(), "ser_1", "service"));
    DatasetOutput<?> metadata = new DatasetOutput();
    metadata.setFeature(OptionalOutput.of(feature));
    metadata.setDatasetParameters(OptionalOutput.of(datasetParameters)).setUom(OptionalOutput.of("")).setId("timeseries");
    PlatformOutput platformOutput = new PlatformOutput();
    platformOutput.setId("plat_1");
    platformOutput.setLabel(OptionalOutput.of("platform"));
    datasetParameters.setPlatform(platformOutput);
    // build expected title
    StringBuilder expected = new StringBuilder();
    // ParameterOutput platform = datasetParameters.getPlatform();
    // expected.append(platform.getLabel());
    ParameterOutput phenomenon = datasetParameters.getPhenomenon();
    ParameterOutput procedure = datasetParameters.getProcedure();
    ParameterOutput offering = datasetParameters.getOffering();
    ParameterOutput service = datasetParameters.getService();
    ParameterOutput category = datasetParameters.getCategory();
    expected.append(platformOutput.getLabel()).append(" ").append(phenomenon.getLabel()).append(" ").append(procedure.getLabel()).append(" (4 opted-out)").append(" ").append(offering.getLabel()).append(" ").append(feature.getLabel()).append(" ").append(service.getLabel()).append(" ").append(metadata.getUom());
    IoParameters ioConfig = createDefaults().extendWith("rendering_trigger", "prerendering");
    IoStyleContext context = IoStyleContext.createContextWith(ioConfig, Collections.singletonList(metadata));
    MyChartRenderer chartRenderer = new MyChartRenderer(ioConfig, 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) DatasetParameters(org.n52.io.response.dataset.DatasetParameters) DatasetOutput(org.n52.io.response.dataset.DatasetOutput) ParameterOutput(org.n52.io.response.ParameterOutput) PhenomenonOutput(org.n52.io.response.PhenomenonOutput) Test(org.junit.jupiter.api.Test)

Example 7 with DatasetParameters

use of org.n52.io.response.dataset.DatasetParameters in project series-rest-api by 52North.

the class ChartIoHandler method formatTitle.

protected String formatTitle(DatasetOutput<?> metadata, String title) {
    DatasetParameters parameters = metadata.getDatasetParameters();
    Object[] varargs = { // index important to reference in config!
    parameters.getPlatform().getLabel(), parameters.getPhenomenon().getLabel(), parameters.getProcedure().getLabel(), parameters.getCategory().getLabel(), parameters.getOffering().getLabel(), metadata.getFeature().getLabel(), parameters.getService().getLabel(), metadata.getUom() };
    try {
        return String.format(title, varargs);
    } catch (Exception e) {
        String datasetId = metadata.getId();
        LOGGER.info("Couldn't format title while prerendering dataset '{}'", datasetId, e);
        // return template as fallback
        return title;
    }
}
Also used : DatasetParameters(org.n52.io.response.dataset.DatasetParameters) IoParseException(org.n52.io.IoParseException) IOException(java.io.IOException)

Example 8 with DatasetParameters

use of org.n52.io.response.dataset.DatasetParameters in project series-rest-api by 52North.

the class PDFReportGenerator method addTimeseries.

private TimeSeries addTimeseries(DatasetOutput<?> output) {
    DocumentStructureType report = document.getDocumentStructure();
    TimeSeries timeseries = report.addNewTimeSeries();
    DatasetParameters parameters = output.getDatasetParameters();
    timeseries.setFeatureOfInterestID(output.getFeature().getLabel());
    timeseries.setPhenomenID(parameters.getPhenomenon().getLabel());
    timeseries.setProcedureID(parameters.getProcedure().getLabel());
    return timeseries;
}
Also used : TimeSeries(org.n52.oxf.DocumentStructureType.TimeSeries) DatasetParameters(org.n52.io.response.dataset.DatasetParameters) DocumentStructureType(org.n52.oxf.DocumentStructureType)

Example 9 with DatasetParameters

use of org.n52.io.response.dataset.DatasetParameters in project series-rest-api by 52North.

the class PDFReportGenerator method createValueTableHeader.

private String createValueTableHeader(TimeseriesMetadataOutput metadata) {
    DatasetParameters parameters = metadata.getDatasetParameters();
    String phenomenon = parameters.getPhenomenon().getLabel();
    return phenomenon + " (" + metadata.getUom() + ")";
}
Also used : DatasetParameters(org.n52.io.response.dataset.DatasetParameters)

Aggregations

DatasetParameters (org.n52.io.response.dataset.DatasetParameters)9 ParameterOutput (org.n52.io.response.ParameterOutput)3 IOException (java.io.IOException)1 Test (org.junit.jupiter.api.Test)1 IoParseException (org.n52.io.IoParseException)1 IoStyleContext (org.n52.io.IoStyleContext)1 IoParameters (org.n52.io.request.IoParameters)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 DatasetOutput (org.n52.io.response.dataset.DatasetOutput)1 TimeseriesMetadataOutput (org.n52.io.response.dataset.TimeseriesMetadataOutput)1 DocumentStructureType (org.n52.oxf.DocumentStructureType)1 TimeSeries (org.n52.oxf.DocumentStructureType.TimeSeries)1