Search in sources :

Example 1 with InsertSensorRequest

use of org.n52.shetland.ogc.sos.request.InsertSensorRequest in project arctic-sea by 52North.

the class InsertSensorRequestDecoder method decodeRequest.

@Override
protected InsertSensorRequest decodeRequest(JsonNode node) throws DecodingException {
    final InsertSensorRequest r = new InsertSensorRequest();
    final SosInsertionMetadata meta = new SosInsertionMetadata();
    meta.setFeatureOfInterestTypes(parseStringOrStringList(node.path(JSONConstants.FEATURE_OF_INTEREST_TYPE)));
    meta.setObservationTypes(parseStringOrStringList(node.path(JSONConstants.OBSERVATION_TYPE)));
    r.setMetadata(meta);
    r.setObservableProperty(parseStringOrStringList(node.path(JSONConstants.OBSERVABLE_PROPERTY)));
    r.setProcedureDescriptionFormat(node.path(JSONConstants.PROCEDURE_DESCRIPTION_FORMAT).textValue());
    r.setRelatedFeature(parseFeatureRelationships(node.path(JSONConstants.RELATED_FEATURE)));
    r.setProcedureDescription(parseProcedureDescription(node.path(JSONConstants.PROCEDURE_DESCRIPTION), r.getProcedureDescriptionFormat()));
    return r;
}
Also used : SosInsertionMetadata(org.n52.shetland.ogc.sos.SosInsertionMetadata) InsertSensorRequest(org.n52.shetland.ogc.sos.request.InsertSensorRequest)

Example 2 with InsertSensorRequest

use of org.n52.shetland.ogc.sos.request.InsertSensorRequest in project arctic-sea by 52North.

the class SwesDecoderv20 method parseInsertSensor.

private OwsServiceRequest parseInsertSensor(final InsertSensorDocument xbInsSensDoc) throws DecodingException {
    final InsertSensorRequest request = new InsertSensorRequest();
    final InsertSensorType xbInsertSensor = xbInsSensDoc.getInsertSensor();
    request.setService(xbInsertSensor.getService());
    request.setVersion(xbInsertSensor.getVersion());
    // format
    request.setProcedureDescriptionFormat(xbInsertSensor.getProcedureDescriptionFormat());
    // observable properties
    if (CollectionHelper.isNotNullOrEmpty(xbInsertSensor.getObservablePropertyArray())) {
        request.setObservableProperty(Arrays.asList(xbInsertSensor.getObservablePropertyArray()));
    }
    // related features
    if (CollectionHelper.isNotNullOrEmpty(xbInsertSensor.getRelatedFeatureArray())) {
        request.setRelatedFeature(parseRelatedFeature(xbInsertSensor.getRelatedFeatureArray()));
    }
    // metadata
    if (CollectionHelper.isNotNullOrEmpty(xbInsertSensor.getMetadataArray())) {
        request.setMetadata(parseMetadata(xbInsertSensor.getMetadataArray()));
    }
    // extensions
    request.setExtensions(parseExtensibleRequest(xbInsertSensor));
    try {
        final XmlObject xbProcedureDescription = XmlObject.Factory.parse(getNodeFromNodeList(xbInsertSensor.getProcedureDescription().getDomNode().getChildNodes()));
        checkFormatWithNamespace(xbInsertSensor.getProcedureDescriptionFormat(), XmlHelper.getNamespace(xbProcedureDescription));
        final Decoder<?, XmlObject> decoder = getDecoder(new XmlNamespaceDecoderKey(xbInsertSensor.getProcedureDescriptionFormat(), xbProcedureDescription.getClass()));
        if (decoder != null) {
            final Object decodedProcedureDescription = decoder.decode(xbProcedureDescription);
            if (decodedProcedureDescription instanceof SosProcedureDescription) {
                request.setProcedureDescription((SosProcedureDescription) decodedProcedureDescription);
            } else if (decodedProcedureDescription instanceof AbstractFeature) {
                request.setProcedureDescription(new SosProcedureDescription<>((AbstractFeature) decodedProcedureDescription));
            }
        }
    } catch (final XmlException xmle) {
        throw new DecodingException("Error while parsing procedure description of InsertSensor request!", xmle);
    }
    return request;
}
Also used : XmlException(org.apache.xmlbeans.XmlException) InsertSensorType(net.opengis.swes.x20.InsertSensorType) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) XmlObject(org.apache.xmlbeans.XmlObject) OwsServiceCommunicationObject(org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) InsertSensorRequest(org.n52.shetland.ogc.sos.request.InsertSensorRequest)

Example 3 with InsertSensorRequest

use of org.n52.shetland.ogc.sos.request.InsertSensorRequest in project arctic-sea by 52North.

the class InsertSensorRequestEncoder method addProcedureDescription.

private void addProcedureDescription(InsertSensorRequest request, InsertSensorType insertSensor) throws EncodingException {
    XmlObject xmlObj;
    if (request.getProcedureDescription() instanceof SosProcedureDescriptionUnknownType && request.getProcedureDescription().isSetXml()) {
        try {
            xmlObj = XmlHelper.parseXmlString(request.getProcedureDescription().getXml());
        } catch (DecodingException de) {
            throw new EncodingException("An xml error occured when parsing the request!", de);
        }
    }
    xmlObj = encodeObjectToXml(request.getProcedureDescriptionFormat(), request.getProcedureDescription().getProcedureDescription());
    insertSensor.addNewProcedureDescription().set(xmlObj);
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) SosProcedureDescriptionUnknownType(org.n52.shetland.ogc.sos.SosProcedureDescriptionUnknownType) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException)

Example 4 with InsertSensorRequest

use of org.n52.shetland.ogc.sos.request.InsertSensorRequest in project arctic-sea by 52North.

the class InsertSensorRequestEncoderTest method shouldThrowExceptionWhenProcedureDescriptionIsMissing.

@Test
public void shouldThrowExceptionWhenProcedureDescriptionIsMissing() throws EncodingException {
    thrown.expect(UnsupportedEncoderInputException.class);
    thrown.expectMessage(Is.is("Encoder " + InsertSensorRequestEncoder.class.getSimpleName() + " can not encode 'procedure description missing'"));
    InsertSensorRequest request = new InsertSensorRequest("service", "version");
    request.setProcedureDescriptionFormat("test-format");
    encoder.create(request);
}
Also used : InsertSensorRequest(org.n52.shetland.ogc.sos.request.InsertSensorRequest) Test(org.junit.Test)

Example 5 with InsertSensorRequest

use of org.n52.shetland.ogc.sos.request.InsertSensorRequest in project arctic-sea by 52North.

the class InsertSensorRequestEncoderTest method shouldThrowExceptionWhenMetadataIsMissing.

@Test
public void shouldThrowExceptionWhenMetadataIsMissing() throws EncodingException {
    thrown.expect(UnsupportedEncoderInputException.class);
    thrown.expectMessage(Is.is("Encoder " + InsertSensorRequestEncoder.class.getSimpleName() + " can not encode 'metadata field missing'"));
    InsertSensorRequest request = new InsertSensorRequest("service", "version");
    request.setProcedureDescriptionFormat("test-format");
    request.setProcedureDescription(createProcedureDescription());
    request.setObservableProperty(CollectionHelper.list("test-property"));
    encoder.create(request);
}
Also used : InsertSensorRequest(org.n52.shetland.ogc.sos.request.InsertSensorRequest) Test(org.junit.Test)

Aggregations

InsertSensorRequest (org.n52.shetland.ogc.sos.request.InsertSensorRequest)9 Test (org.junit.Test)6 XmlObject (org.apache.xmlbeans.XmlObject)2 SosInsertionMetadata (org.n52.shetland.ogc.sos.SosInsertionMetadata)2 DecodingException (org.n52.svalbard.decode.exception.DecodingException)2 InsertSensorType (net.opengis.swes.x20.InsertSensorType)1 XmlException (org.apache.xmlbeans.XmlException)1 XmlOptions (org.apache.xmlbeans.XmlOptions)1 Before (org.junit.Before)1 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)1 OwsServiceCommunicationObject (org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject)1 SosProcedureDescription (org.n52.shetland.ogc.sos.SosProcedureDescription)1 SosProcedureDescriptionUnknownType (org.n52.shetland.ogc.sos.SosProcedureDescriptionUnknownType)1 EncodingException (org.n52.svalbard.encode.exception.EncodingException)1