Search in sources :

Example 61 with Value

use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.

the class GetObservationResponseXmlStreamWriter method writeGetObservationResponseDoc.

private void writeGetObservationResponseDoc() throws XMLStreamException, EncodingException {
    start(Sos2StreamingConstants.GET_OBSERVATION_RESPONSE);
    namespace(W3CConstants.NS_XLINK_PREFIX, W3CConstants.NS_XLINK);
    namespace(SosConstants.NS_SOS_PREFIX, Sos2Constants.NS_SOS_20);
    GetObservationResponse response = getElement();
    // get observation encoder
    ObservationEncoder<XmlObject, OmObservation> encoder = findObservationEncoder(response.getResponseFormat());
    // write schemaLocation
    schemaLocation(getSchemaLocation(encoder));
    EncodingContext ctx = getContext().with(XmlEncoderFlags.ENCODE_NAMESPACE, response.getResponseFormat()).with(XmlBeansEncodingFlags.DOCUMENT).with(StreamingEncoderFlags.EMBEDDED).without(XmlBeansEncodingFlags.PROPERTY_TYPE).without(XmlBeansEncodingFlags.TYPE);
    try {
        ObservationStream stream = response.getObservationCollection();
        if (encoder.shouldObservationsWithSameXBeMerged()) {
            stream = stream.merge();
        }
        while (stream.hasNext()) {
            OmObservation o = stream.next();
            if (o.getValue() instanceof ObservationStream) {
                ObservationStream value = (ObservationStream) o.getValue();
                if (encoder.supportsResultStreamingForMergedValues()) {
                    writeObservationData(ctx, o, encoder);
                } else {
                    while (value.hasNext()) {
                        writeObservationData(ctx, value.next(), encoder);
                    }
                }
            } else {
                writeObservationData(ctx, o, encoder);
            }
        }
    } catch (OwsExceptionReport owse) {
        throw new EncodingException(owse);
    }
    end(Sos2StreamingConstants.GET_OBSERVATION_RESPONSE);
}
Also used : EncodingContext(org.n52.svalbard.encode.EncodingContext) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) EncodingException(org.n52.svalbard.encode.exception.EncodingException) GetObservationResponse(org.n52.shetland.ogc.sos.response.GetObservationResponse) OmObservation(org.n52.shetland.ogc.om.OmObservation) XmlObject(org.apache.xmlbeans.XmlObject) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 62 with Value

use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.

the class WmlTVPEncoderv20XmlStreamWriter method writeInterpolationType.

/**
 * Write wml:interpolationType to stream
 *
 * @throws XMLStreamException
 *             If an error occurs when writing to stream
 */
private void writeInterpolationType(ObservationValue<?> value) throws XMLStreamException {
    empty(WaterMLConstants.QN_INTERPOLATION_TYPE);
    if (value != null && value.isSetMetadata() && value.getDefaultPointMetadata().isSetDefaultTVPMeasurementMetadata() && value.getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().isSetInterpolationType()) {
        InterpolationType interpolationtype = value.getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().getInterpolationtype();
        addXlinkHrefAttr(interpolationtype.getIdentifier());
        addXlinkTitleAttr(interpolationtype.getTitle());
    } else {
        addXlinkHrefAttr("http://www.opengis.net/def/timeseriesType/WaterML/2.0/continuous");
        addXlinkTitleAttr("Instantaneous");
    }
}
Also used : InterpolationType(org.n52.shetland.ogc.om.series.wml.WaterMLConstants.InterpolationType)

Example 63 with Value

use of org.n52.shetland.ogc.om.values.Value in project series-rest-api by 52North.

the class MultipleChartsRenderer method writeDataToChart.

@Override
public void writeDataToChart(DataCollection<QuantityData> data) {
    Map<String, QuantityData> allTimeseries = data.getAllSeries();
    List<? extends DatasetOutput> timeseriesMetadatas = getMetadataOutputs();
    int rendererCount = timeseriesMetadatas.size();
    for (int rendererIndex = 0; rendererIndex < timeseriesMetadatas.size(); rendererIndex++) {
        /*
             * For each index put data and its renderer configured to a particular style.
             *
             * As each timeseries may define its custom styling and different chart types we have to loop over
             * all timeseries to configure chart rendering.
             */
        DatasetOutput timeseriesMetadata = timeseriesMetadatas.get(rendererIndex);
        String timeseriesId = timeseriesMetadata.getId();
        StyleProperties style = getTimeseriesStyleFor(timeseriesId);
        QuantityData timeseriesData = allTimeseries.get(timeseriesId);
        String chartId = createChartId(timeseriesMetadata);
        ChartIndexConfiguration configuration = new ChartIndexConfiguration(chartId, rendererIndex);
        configuration.setData(timeseriesData, timeseriesMetadata, style);
        configuration.setRenderer(createRenderer(style));
        if (timeseriesData.hasReferenceValues()) {
            int referenceIndex = rendererCount;
            /*
                 * Configure timeseries reference value renderers with the same metadata and add it at the end
                 * of the plot's renderer list.
                 */
            QuantityDatasetMetadata metadata = timeseriesData.getMetadata();
            Map<String, QuantityData> referenceValues = metadata.getReferenceValues();
            for (Entry<String, QuantityData> referencedTimeseries : referenceValues.entrySet()) {
                String referenceTimeseriesId = referencedTimeseries.getKey();
                ReferenceValueOutput referenceOutput = getReferenceValue(referenceTimeseriesId, timeseriesMetadata);
                String referenceChartId = createChartId(timeseriesMetadata, referenceOutput.getLabel());
                QuantityData referenceData = referenceValues.get(referenceTimeseriesId);
                ChartIndexConfiguration referenceConfiguration = new ChartIndexConfiguration(referenceChartId, referenceIndex);
                StyleProperties referenceStyle = getTimeseriesStyleFor(timeseriesId, referenceTimeseriesId);
                referenceConfiguration.setReferenceData(referenceData, timeseriesMetadata, referenceStyle);
                referenceConfiguration.setRenderer(createRenderer(referenceStyle));
                referenceIndex++;
            }
        }
    }
}
Also used : ReferenceValueOutput(org.n52.io.response.dataset.ReferenceValueOutput) DatasetOutput(org.n52.io.response.dataset.DatasetOutput) StyleProperties(org.n52.io.request.StyleProperties) QuantityData(org.n52.io.response.dataset.quantity.QuantityData) QuantityDatasetMetadata(org.n52.io.response.dataset.quantity.QuantityDatasetMetadata)

Example 64 with Value

use of org.n52.shetland.ogc.om.values.Value in project series-rest-api by 52North.

the class BaseController method handleException.

@ExceptionHandler(value = { RuntimeException.class, Exception.class, Throwable.class })
public void handleException(Exception e, HttpServletRequest request, HttpServletResponse response) {
    if (e instanceof HttpMessageNotReadableException) {
        WebException wrappedException = new BadRequestException("The request could not been read.", e);
        wrappedException.addHint("Check the message which has been sent to the server. Probably it is not valid.");
        writeExceptionResponse(wrappedException, response, HttpStatus.BAD_REQUEST);
    } else {
        WebException wrappedException = new InternalServerException("Unexpected Exception occured.", e);
        writeExceptionResponse(wrappedException, response, HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
Also used : HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) WebException(org.n52.web.exception.WebException) InternalServerException(org.n52.web.exception.InternalServerException) BadRequestException(org.n52.web.exception.BadRequestException) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 65 with Value

use of org.n52.shetland.ogc.om.values.Value in project series-rest-api by 52North.

the class DataController method getSeriesCollectionChart.

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

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)28 Test (org.junit.Test)27 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)20 IoParameters (org.n52.io.request.IoParameters)19 SweField (org.n52.shetland.ogc.swe.SweField)16 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)13 QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)13 RequestSimpleParameterSet (org.n52.io.request.RequestSimpleParameterSet)12 List (java.util.List)9 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)9 AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)7 CategoryValue (org.n52.shetland.ogc.om.values.CategoryValue)7 CountValue (org.n52.shetland.ogc.om.values.CountValue)7 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)7 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)7 DecodingException (org.n52.svalbard.decode.exception.DecodingException)7 DateTime (org.joda.time.DateTime)6 ModelAndView (org.springframework.web.servlet.ModelAndView)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 ArrayList (java.util.ArrayList)5