Search in sources :

Example 1 with InsertObservationDocument

use of net.opengis.sos.x20.InsertObservationDocument 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 InsertObservationDocument

use of net.opengis.sos.x20.InsertObservationDocument 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 3 with InsertObservationDocument

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

the class InsertObservationRequestEncoder method create.

@Override
protected XmlObject create(InsertObservationRequest request) throws EncodingException {
    validateInput(request);
    InsertObservationDocument doc = InsertObservationDocument.Factory.newInstance(getXmlOptions());
    InsertObservationType insertObservation = doc.addNewInsertObservation();
    insertObservation.setService(request.getService());
    insertObservation.setVersion(request.getVersion());
    addExtensions(request.getExtensions(), insertObservation);
    addOfferings(request.getOfferings(), insertObservation);
    addObservations(request.getObservations(), insertObservation);
    return doc;
}
Also used : InsertObservationDocument(net.opengis.sos.x20.InsertObservationDocument) InsertObservationType(net.opengis.sos.x20.InsertObservationType)

Example 4 with InsertObservationDocument

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

the class InsertObservationRequestEncoderTest method shouldEncodeInsertObservationRequest.

@Test
public void shouldEncodeInsertObservationRequest() throws EncodingException, InvalidSridException, ParseException, DecodingException {
    InsertObservationRequest request = createInsertObservationRequest();
    XmlObject encodedRequest = encoder.create(request);
    XmlHelper.validateDocument(encodedRequest);
    Assert.assertThat(encodedRequest, Matchers.notNullValue());
    Assert.assertThat(encodedRequest, Matchers.instanceOf(InsertObservationDocument.class));
    InsertObservationType insertObservation = ((InsertObservationDocument) encodedRequest).getInsertObservation();
    Assert.assertThat(insertObservation.getOfferingArray(), Matchers.notNullValue());
    Assert.assertThat(insertObservation.getOfferingArray().length, Is.is(1));
    Assert.assertThat(insertObservation.getOfferingArray(0), Is.is(OFFERING_ID));
    Assert.assertThat(insertObservation.getObservationArray(), Matchers.notNullValue());
    Assert.assertThat(insertObservation.getObservationArray().length, Is.is(1));
// 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) XmlObject(org.apache.xmlbeans.XmlObject) InsertObservationType(net.opengis.sos.x20.InsertObservationType) Test(org.junit.Test)

Aggregations

InsertObservationType (net.opengis.sos.x20.InsertObservationType)4 InsertObservationDocument (net.opengis.sos.x20.InsertObservationDocument)3 XmlObject (org.apache.xmlbeans.XmlObject)3 InsertObservationRequest (org.n52.shetland.ogc.sos.request.InsertObservationRequest)3 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Observation (net.opengis.sos.x20.InsertObservationType.Observation)1 BooleanPropertyType (net.opengis.swe.x20.BooleanPropertyType)1 BooleanType (net.opengis.swe.x20.BooleanType)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 XmlString (org.apache.xmlbeans.XmlString)1 CompositeException (org.n52.janmayen.exception.CompositeException)1 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)1 Time (org.n52.shetland.ogc.gml.time.Time)1 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)1 OmObservation (org.n52.shetland.ogc.om.OmObservation)1 OwsServiceCommunicationObject (org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject)1 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)1 SwesExtension (org.n52.shetland.ogc.swes.SwesExtension)1 DecodingException (org.n52.svalbard.decode.exception.DecodingException)1