Search in sources :

Example 1 with SchemaLocation

use of org.n52.shetland.w3c.SchemaLocation in project arctic-sea by 52North.

the class GetDataAvailabilityV20StreamWriter method writeGetDataAvailabilityResponse.

@Override
protected void writeGetDataAvailabilityResponse() throws XMLStreamException, EncodingException {
    start(GetDataAvailabilityConstants.GDA_GET_DATA_AVAILABILITY_20_RESPONSE);
    namespace(GetDataAvailabilityConstants.NS_GDA_PREFIX, GetDataAvailabilityConstants.NS_GDA_20);
    namespace(GmlConstants.NS_GML_PREFIX, GmlConstants.NS_GML_32);
    namespace(SweConstants.NS_SWE_PREFIX, SweConstants.NS_SWE_20);
    namespace(W3CConstants.NS_XLINK_PREFIX, W3CConstants.NS_XLINK);
    schemaLocation(Sets.newHashSet(GetDataAvailabilityConstants.GET_DATA_AVAILABILITY_20_SCHEMA_LOCATION));
    for (DataAvailability da : getElement()) {
        wirteDataAvailabilityMember(da);
    }
    end(GetDataAvailabilityConstants.GDA_GET_DATA_AVAILABILITY_20_RESPONSE);
}
Also used : DataAvailability(org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse.DataAvailability)

Example 2 with SchemaLocation

use of org.n52.shetland.w3c.SchemaLocation in project arctic-sea by 52North.

the class GetFeatureOfInterestXmlStreamWriter method writeGetFeatureOfInterestResponseDoc.

private void writeGetFeatureOfInterestResponseDoc() throws XMLStreamException, EncodingException {
    start(Sos2StreamingConstants.QN_GET_FEATURE_OF_INTEREST_RESPONSE);
    namespace(W3CConstants.NS_XLINK_PREFIX, W3CConstants.NS_XLINK);
    namespace(Sos2Constants.NS_SOS_PREFIX, Sos2Constants.NS_SOS_20);
    // write schemaLocation
    schemaLocation(getSchemaLocation());
    AbstractFeature feature = getElement().getAbstractFeature();
    if (feature instanceof FeatureCollection) {
        for (AbstractFeature f : (FeatureCollection) feature) {
            writeFeatureMember(f);
        }
    } else if (feature instanceof AbstractSamplingFeature) {
        writeFeatureMember(feature);
    }
    end(Sos2StreamingConstants.QN_GET_FEATURE_OF_INTEREST_RESPONSE);
}
Also used : AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature)

Example 3 with SchemaLocation

use of org.n52.shetland.w3c.SchemaLocation in project arctic-sea by 52North.

the class UpdateSensorResponseEncoderTest method should_return_correct_schema_location.

@Test
public void should_return_correct_schema_location() {
    assertThat(encoder.getSchemaLocations().size(), is(1));
    SchemaLocation schemLoc = encoder.getSchemaLocations().iterator().next();
    assertThat(schemLoc.getNamespace(), is("http://www.opengis.net/swes/2.0"));
    assertThat(schemLoc.getSchemaFileUrl(), is("http://schemas.opengis.net/swes/2.0/swes.xsd"));
}
Also used : SchemaLocation(org.n52.shetland.w3c.SchemaLocation) Test(org.junit.Test)

Example 4 with SchemaLocation

use of org.n52.shetland.w3c.SchemaLocation 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 5 with SchemaLocation

use of org.n52.shetland.w3c.SchemaLocation in project arctic-sea by 52North.

the class AbstractWmlEncoderv20 method createWmlGetObservationResponse.

/**
 * Encodes a SOS GetObservationResponse to a single WaterML 2.0 observation
 * or to a WaterML 1.0 ObservationCollection
 *
 * @param getObservationResonse
 *            SOS GetObservationResponse
 * @return Encoded response
 * @throws EncodingException
 *             If an error occurs
 */
protected XmlObject createWmlGetObservationResponse(GetObservationResponse getObservationResonse) throws EncodingException {
    // TODO: set schemaLocation if final
    Map<CodeWithAuthority, String> gmlID4sfIdentifier = Maps.newHashMap();
    int sfIdCounter = 1;
    try {
        if (getObservationResonse.getObservationCollection() != null && !getObservationResonse.getObservationCollection().hasNext()) {
            ObservationStream observations = getObservationResonse.getObservationCollection();
            OmObservation observation = observations.next();
            if (!observations.hasNext()) {
                OMObservationDocument omObservationDoc = OMObservationDocument.Factory.newInstance(getXmlOptions());
                omObservationDoc.setOMObservation(encodeObservation(observation, gmlID4sfIdentifier, sfIdCounter));
                sfIdCounter++;
                return omObservationDoc;
            } else {
                CollectionDocument xmlCollectionDoc = CollectionDocument.Factory.newInstance(getXmlOptions());
                CollectionType wmlCollection = xmlCollectionDoc.addNewCollection();
                wmlCollection.addNewObservationMember().setOMObservation(encodeObservation(observation, gmlID4sfIdentifier, sfIdCounter));
                sfIdCounter++;
                while (observations.hasNext()) {
                    wmlCollection.addNewObservationMember().setOMObservation(encodeObservation(observations.next(), gmlID4sfIdentifier, sfIdCounter));
                    sfIdCounter++;
                }
                return xmlCollectionDoc;
            }
        } else {
            // TODO: HydrologieProfile-Exception
            throw new EncodingException("Combination does not exists!");
        }
    } catch (NoSuchElementException | OwsExceptionReport e) {
        throw new EncodingException(e);
    }
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) CollectionDocument(net.opengis.waterml.x20.CollectionDocument) OmObservation(org.n52.shetland.ogc.om.OmObservation) OMObservationDocument(net.opengis.om.x20.OMObservationDocument) WmlMonitoringPoint(org.n52.shetland.ogc.om.series.wml.WmlMonitoringPoint) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) CollectionType(net.opengis.waterml.x20.CollectionType) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

SchemaLocation (org.n52.shetland.w3c.SchemaLocation)5 XmlObject (org.apache.xmlbeans.XmlObject)3 Test (org.junit.Test)3 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)2 OmObservation (org.n52.shetland.ogc.om.OmObservation)2 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)2 DataAvailability (org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse.DataAvailability)2 EncodingException (org.n52.svalbard.encode.exception.EncodingException)2 NoSuchElementException (java.util.NoSuchElementException)1 OMObservationDocument (net.opengis.om.x20.OMObservationDocument)1 CollectionDocument (net.opengis.waterml.x20.CollectionDocument)1 CollectionType (net.opengis.waterml.x20.CollectionType)1 XmlString (org.apache.xmlbeans.XmlString)1 EReportingHeader (org.n52.shetland.aqd.EReportingHeader)1 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)1 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)1 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)1 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)1 WmlMonitoringPoint (org.n52.shetland.ogc.om.series.wml.WmlMonitoringPoint)1 CodedException (org.n52.shetland.ogc.ows.exception.CodedException)1