Search in sources :

Example 31 with IoParameters

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

the class TimeseriesDataController method getCollectionChart.

@RequestMapping(value = "/getData", produces = { "image/png" }, method = RequestMethod.POST)
public void getCollectionChart(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());
    parameterSet.setBase64(map.isBase64());
    response.setContentType(MimeType.IMAGE_PNG.getMimeType());
    createIoFactory(parameterSet).withStyledRequest(query).createHandler(MimeType.IMAGE_PNG.toString()).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 32 with IoParameters

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

the class DataController method getSeriesReport.

@RequestMapping(value = "/{seriesId}/data", produces = { "application/pdf" }, method = RequestMethod.GET)
public void getSeriesReport(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 collection report for '{}' with query: {}", seriesId, map);
    RequestSimpleParameterSet parameters = RequestSimpleParameterSet.createForSingleSeries(seriesId, map);
    checkAgainstTimespanRestriction(parameters.getTimespan());
    checkForUnknownDatasetIds(map, seriesId);
    final String datasetType = parameters.getValueType();
    String outputFormat = MimeType.APPLICATION_PDF.toString();
    response.setContentType(outputFormat);
    createIoFactory(datasetType).withSimpleRequest(parameters).createHandler(outputFormat).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 33 with IoParameters

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

the class DataController method getSeriesCollectionReport.

@RequestMapping(value = "/data", produces = { "application/pdf" }, method = RequestMethod.POST)
public void getSeriesCollectionReport(HttpServletResponse response, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE) String locale, @RequestBody RequestStyledParameterSet parameters) throws Exception {
    RequestUtils.overrideQueryLocaleWhenSet(locale, parameters);
    IoParameters map = QueryParameters.createFromQuery(parameters);
    LOGGER.debug("get data collection report with query: {}", map);
    checkForUnknownSeriesIds(parameters, parameters.getDatasets());
    checkAgainstTimespanRestriction(parameters.getTimespan());
    final String datasetType = parameters.getValueType();
    String outputFormat = MimeType.APPLICATION_PDF.toString();
    response.setContentType(outputFormat);
    createIoFactory(datasetType).withStyledRequest(map.mergeToStyledParameterSet(parameters)).withSimpleRequest(map.mergeToSimpleParameterSet(parameters)).createHandler(outputFormat).writeBinary(response.getOutputStream());
}
Also used : IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 34 with IoParameters

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

the class QuantityIoFactory method createHandler.

@Override
public IoHandler<QuantityData> createHandler(String outputMimeType) {
    IoParameters parameters = getParameters();
    MimeType mimeType = MimeType.toInstance(outputMimeType);
    if (mimeType == MimeType.IMAGE_PNG) {
        return createMultiChartRenderer(mimeType);
    } else if (mimeType == MimeType.APPLICATION_PDF) {
        ChartIoHandler imgRenderer = createMultiChartRenderer(mimeType);
        PDFReportGenerator reportGenerator = new PDFReportGenerator(getRequestParameters(), createProcessChain(), imgRenderer);
        reportGenerator.setBaseURI(getBasePath());
        return reportGenerator;
    } else if (mimeType == MimeType.TEXT_CSV || mimeType == MimeType.APPLICATION_ZIP) {
        QuantityCsvIoHandler handler = new QuantityCsvIoHandler(getRequestParameters(), createProcessChain(), getMetadatas());
        handler.setTokenSeparator(parameters.getOther("tokenSeparator"));
        boolean zipOutput = parameters.getAsBoolean(MimeType.APPLICATION_ZIP.name());
        handler.setZipOutput(zipOutput || mimeType == MimeType.APPLICATION_ZIP);
        boolean byteOderMark = Boolean.parseBoolean(parameters.getOther("bom"));
        handler.setIncludeByteOrderMark(byteOderMark);
        return handler;
    }
    String msg = "The requested media type '" + outputMimeType + "' is not supported.";
    IllegalArgumentException exception = new IllegalArgumentException(msg);
    throw exception;
}
Also used : QuantityCsvIoHandler(org.n52.io.quantity.csv.QuantityCsvIoHandler) ChartIoHandler(org.n52.io.quantity.img.ChartIoHandler) IoParameters(org.n52.io.request.IoParameters) PDFReportGenerator(org.n52.io.quantity.report.PDFReportGenerator) MimeType(org.n52.io.MimeType)

Example 35 with IoParameters

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

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