Search in sources :

Example 1 with Observation

use of net.opengis.sos.x20.InsertObservationType.Observation in project arctic-sea by 52North.

the class SosDecoderv20 method parseInsertObservation.

private OwsServiceRequest parseInsertObservation(final InsertObservationDocument insertObservationDoc) throws DecodingException {
    // set namespace for default XML type (e.g. xs:string, xs:integer,
    // xs:boolean, ...)
    // Fix for problem with XmlBeans: namespace is not set in child elements
    // when defined in root of request (SOAP)
    final XmlCursor cursor = insertObservationDoc.newCursor();
    if (cursor.toFirstChild() && cursor.namespaceForPrefix(W3CConstants.NS_XS_PREFIX) == null) {
        cursor.prefixForNamespace(W3CConstants.NS_XS);
    }
    cursor.dispose();
    final InsertObservationRequest insertObservationRequest = new InsertObservationRequest();
    final InsertObservationType insertObservationType = insertObservationDoc.getInsertObservation();
    insertObservationRequest.setService(insertObservationType.getService());
    insertObservationRequest.setVersion(insertObservationType.getVersion());
    if (insertObservationDoc.getInsertObservation().getOfferingArray() != null) {
        insertObservationRequest.setOfferings(Arrays.asList(insertObservationType.getOfferingArray()));
    }
    insertObservationRequest.setExtensions(parseExtensibleRequest(insertObservationType));
    if (insertObservationType.getObservationArray() != null) {
        final int length = insertObservationType.getObservationArray().length;
        final Map<String, Time> phenomenonTimes = new HashMap<>(length);
        final Map<String, TimeInstant> resultTimes = new HashMap<>(length);
        final Map<String, AbstractFeature> features = new HashMap<>(length);
        CompositeException exceptions = new CompositeException();
        for (final Observation observation : insertObservationType.getObservationArray()) {
            final Object decodedObject = decodeXmlElement(observation.getOMObservation());
            if (decodedObject instanceof OmObservation) {
                final OmObservation sosObservation = (OmObservation) decodedObject;
                checkAndAddPhenomenonTime(sosObservation.getPhenomenonTime(), phenomenonTimes);
                checkAndAddResultTime(sosObservation.getResultTime(), resultTimes);
                checkAndAddFeatures(sosObservation.getObservationConstellation().getFeatureOfInterest(), features);
                insertObservationRequest.addObservation(sosObservation);
            } else {
                exceptions.add(new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested observation type (%s) is not supported by this server!", observation.getOMObservation().getDomNode().getNodeName()));
            }
        }
        checkReferencedElements(insertObservationRequest.getObservations(), phenomenonTimes, resultTimes, features);
        try {
            exceptions.throwIfNotEmpty();
        } catch (CompositeException ex) {
            throw new DecodingException(ex, Sos2Constants.InsertObservationParams.observation);
        }
    } else {
        // TODO MissingMandatoryParameterException?
        throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The request does not contain an observation");
    }
    return insertObservationRequest;
}
Also used : HashMap(java.util.HashMap) CompositeException(org.n52.janmayen.exception.CompositeException) OmObservation(org.n52.shetland.ogc.om.OmObservation) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) Time(org.n52.shetland.ogc.gml.time.Time) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlString(org.apache.xmlbeans.XmlString) InsertObservationType(net.opengis.sos.x20.InsertObservationType) XmlCursor(org.apache.xmlbeans.XmlCursor) InsertObservationRequest(org.n52.shetland.ogc.sos.request.InsertObservationRequest) OmObservation(org.n52.shetland.ogc.om.OmObservation) Observation(net.opengis.sos.x20.InsertObservationType.Observation) OwsServiceCommunicationObject(org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject) XmlObject(org.apache.xmlbeans.XmlObject) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 2 with Observation

use of net.opengis.sos.x20.InsertObservationType.Observation in project arctic-sea by 52North.

the class GetObservationByIdResponseEncoder method createResponse.

@Override
protected XmlObject createResponse(ObservationEncoder<XmlObject, OmObservation> encoder, GetObservationByIdResponse response) throws EncodingException {
    GetObservationByIdResponseDocument doc = GetObservationByIdResponseDocument.Factory.newInstance(getXmlOptions());
    GetObservationByIdResponseType xbResponse = doc.addNewGetObservationByIdResponse();
    ObservationStream observations = getObservationsAndCheckForStreaming(response, encoder);
    HashMap<CodeWithAuthority, String> gmlID4sfIdentifier = new HashMap<>();
    try {
        while (observations.hasNext()) {
            OmObservation observation = observations.next();
            EncodingContext codingContext = EncodingContext.empty();
            CodeWithAuthority foiId = observation.getObservationConstellation().getFeatureOfInterest().getIdentifierCodeWithAuthority();
            if (gmlID4sfIdentifier.containsKey(foiId)) {
                codingContext = codingContext.with(XmlBeansEncodingFlags.EXIST_FOI_IN_DOC, true);
            } else {
                gmlID4sfIdentifier.put(foiId, GML_ID);
                codingContext = codingContext.with(XmlBeansEncodingFlags.EXIST_FOI_IN_DOC, false);
            }
            codingContext = codingContext.with(XmlBeansEncodingFlags.GMLID, gmlID4sfIdentifier.get(foiId));
            xbResponse.addNewObservation().addNewOMObservation().set(encoder.encode(observation, codingContext));
        }
    } catch (OwsExceptionReport ex) {
        throw new EncodingException(ex);
    }
    XmlHelper.makeGmlIdsUnique(xbResponse.getDomNode());
    return doc;
}
Also used : ObservationStream(org.n52.shetland.ogc.om.ObservationStream) HashMap(java.util.HashMap) EncodingException(org.n52.svalbard.encode.exception.EncodingException) OmObservation(org.n52.shetland.ogc.om.OmObservation) GetObservationByIdResponseDocument(net.opengis.sos.x20.GetObservationByIdResponseDocument) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) GetObservationByIdResponseType(net.opengis.sos.x20.GetObservationByIdResponseType)

Example 3 with Observation

use of net.opengis.sos.x20.InsertObservationType.Observation in project arctic-sea by 52North.

the class GetObservationResponseEncoder method createResponse.

@Override
protected XmlObject createResponse(ObservationEncoder<XmlObject, OmObservation> encoder, GetObservationResponse response) throws EncodingException {
    try {
        GetObservationResponseDocument doc = GetObservationResponseDocument.Factory.newInstance(getXmlOptions());
        GetObservationResponseType xbResponse = doc.addNewGetObservationResponse();
        ObservationStream observationCollection = response.getObservationCollection();
        while (observationCollection.hasNext()) {
            xbResponse.addNewObservationData().addNewOMObservation().set(encoder.encode(observationCollection.next()));
        }
        // in a single observation the gml:ids must be unique
        XmlHelper.makeGmlIdsUnique(doc.getDomNode());
        return doc;
    } catch (OwsExceptionReport ex) {
        throw new EncodingException(ex);
    }
}
Also used : ObservationStream(org.n52.shetland.ogc.om.ObservationStream) EncodingException(org.n52.svalbard.encode.exception.EncodingException) GetObservationResponseType(net.opengis.sos.x20.GetObservationResponseType) GetObservationResponseDocument(net.opengis.sos.x20.GetObservationResponseDocument) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 4 with Observation

use of net.opengis.sos.x20.InsertObservationType.Observation in project arctic-sea by 52North.

the class InsertObservationRequestEncoderTest method shouldEncodeSwesExtensions.

@Test
public void shouldEncodeSwesExtensions() throws InvalidSridException, ParseException, EncodingException, DecodingException {
    String definition = Sos2Constants.Extensions.SplitDataArrayIntoObservations.name();
    boolean value = true;
    SweBoolean sweBoolean = new SweBoolean();
    sweBoolean.setValue(value);
    sweBoolean.setDefinition(definition);
    SwesExtension<SweBoolean> swesExtension = new SwesExtension<>();
    swesExtension.setValue(sweBoolean);
    InsertObservationRequest request = createInsertObservationRequest();
    request.addExtension(swesExtension);
    XmlObject encodedRequest = encoder.create(request);
    encodedRequest.xmlText();
    XmlHelper.validateDocument(encodedRequest);
    InsertObservationType insertObservation = ((InsertObservationDocument) encodedRequest).getInsertObservation();
    Assert.assertThat(insertObservation.sizeOfExtensionArray(), Is.is(1));
    XmlObject xbExtension = insertObservation.getExtensionArray(0);
    Assert.assertThat(xbExtension, Matchers.instanceOf(BooleanPropertyType.class));
    BooleanType xbBoolean = ((BooleanPropertyType) xbExtension).getBoolean();
    Assert.assertThat(xbBoolean.getDefinition(), Is.is(definition));
    Assert.assertThat(xbBoolean.getValue(), Is.is(value));
// no check for observation values, because that MUST be part of OmEncoderv20Test
}
Also used : InsertObservationDocument(net.opengis.sos.x20.InsertObservationDocument) InsertObservationRequest(org.n52.shetland.ogc.sos.request.InsertObservationRequest) BooleanType(net.opengis.swe.x20.BooleanType) XmlObject(org.apache.xmlbeans.XmlObject) SwesExtension(org.n52.shetland.ogc.swes.SwesExtension) BooleanPropertyType(net.opengis.swe.x20.BooleanPropertyType) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) InsertObservationType(net.opengis.sos.x20.InsertObservationType) Test(org.junit.Test)

Example 5 with Observation

use of net.opengis.sos.x20.InsertObservationType.Observation in project arctic-sea by 52North.

the class SwesDecoderv20 method parseMetadata.

private SosInsertionMetadata parseMetadata(final Metadata[] metadataArray) throws DecodingException {
    final SosInsertionMetadata sosMetadata = new SosInsertionMetadata();
    try {
        for (final Metadata metadata : metadataArray) {
            SosInsertionMetadataType xbSosInsertionMetadata = null;
            if (metadata.getInsertionMetadata() != null && metadata.getInsertionMetadata().schemaType() == SosInsertionMetadataType.type) {
                xbSosInsertionMetadata = (SosInsertionMetadataType) metadata.getInsertionMetadata();
            } else {
                if (metadata.getDomNode().hasChildNodes()) {
                    final Node node = getNodeFromNodeList(metadata.getDomNode().getChildNodes());
                    final SosInsertionMetadataPropertyType xbMetadata = SosInsertionMetadataPropertyType.Factory.parse(node);
                    xbSosInsertionMetadata = xbMetadata.getSosInsertionMetadata();
                }
            }
            if (xbSosInsertionMetadata != null) {
                // featureOfInterest types
                if (xbSosInsertionMetadata.getFeatureOfInterestTypeArray() != null) {
                    sosMetadata.setFeatureOfInterestTypes(Arrays.asList(xbSosInsertionMetadata.getFeatureOfInterestTypeArray()));
                }
                // observation types
                if (xbSosInsertionMetadata.getObservationTypeArray() != null) {
                    sosMetadata.setObservationTypes(Arrays.asList(xbSosInsertionMetadata.getObservationTypeArray()));
                }
            }
        }
    } catch (final XmlException xmle) {
        throw new DecodingException("An error occurred while parsing the metadata in the http post request", xmle);
    }
    return sosMetadata;
}
Also used : XmlException(org.apache.xmlbeans.XmlException) Node(org.w3c.dom.Node) SosInsertionMetadata(org.n52.shetland.ogc.sos.SosInsertionMetadata) Metadata(net.opengis.swes.x20.InsertSensorType.Metadata) SosInsertionMetadataPropertyType(net.opengis.sos.x20.SosInsertionMetadataPropertyType) SosInsertionMetadata(org.n52.shetland.ogc.sos.SosInsertionMetadata) DecodingException(org.n52.svalbard.decode.exception.DecodingException) SosInsertionMetadataType(net.opengis.sos.x20.SosInsertionMetadataType)

Aggregations

InsertObservationType (net.opengis.sos.x20.InsertObservationType)3 XmlObject (org.apache.xmlbeans.XmlObject)3 Test (org.junit.Test)3 InsertObservationRequest (org.n52.shetland.ogc.sos.request.InsertObservationRequest)3 HashMap (java.util.HashMap)2 InsertObservationDocument (net.opengis.sos.x20.InsertObservationDocument)2 SosInsertionMetadataType (net.opengis.sos.x20.SosInsertionMetadataType)2 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 DecodingException (org.n52.svalbard.decode.exception.DecodingException)2 EncodingException (org.n52.svalbard.encode.exception.EncodingException)2 GetObservationByIdResponseDocument (net.opengis.sos.x20.GetObservationByIdResponseDocument)1 GetObservationByIdResponseType (net.opengis.sos.x20.GetObservationByIdResponseType)1 GetObservationResponseDocument (net.opengis.sos.x20.GetObservationResponseDocument)1 GetObservationResponseType (net.opengis.sos.x20.GetObservationResponseType)1 Observation (net.opengis.sos.x20.InsertObservationType.Observation)1 SosInsertionMetadataPropertyType (net.opengis.sos.x20.SosInsertionMetadataPropertyType)1 BooleanPropertyType (net.opengis.swe.x20.BooleanPropertyType)1 BooleanType (net.opengis.swe.x20.BooleanType)1