Search in sources :

Example 6 with AbstractFeature

use of org.n52.shetland.ogc.gml.AbstractFeature in project arctic-sea by 52North.

the class FeatureOfInterestEncoder method encodeFeatureCollection.

private JsonNode encodeFeatureCollection(AbstractFeature t) throws EncodingException {
    FeatureCollection featureCollection = (FeatureCollection) t;
    ArrayNode a = nodeFactory().arrayNode();
    for (AbstractFeature af : featureCollection) {
        a.add(encodeObjectToJson(af));
    }
    return a;
}
Also used : FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 7 with AbstractFeature

use of org.n52.shetland.ogc.gml.AbstractFeature 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 8 with AbstractFeature

use of org.n52.shetland.ogc.gml.AbstractFeature in project arctic-sea by 52North.

the class SpecimenDecoderv20 method parseSpatialSamplingFeature.

private AbstractFeature parseSpatialSamplingFeature(final SFSpecimenType sfst) throws DecodingException {
    final SfSpecimen specimen = new SfSpecimen(null, sfst.getId());
    // parse identifier, names, description
    parseAbstractFeatureType(sfst, specimen);
    specimen.setSampledFeatures(getSampledFeatures(sfst.getSampledFeatureArray()));
    specimen.setXml(getXmlDescription(sfst));
    if (sfst.getParameterArray() != null) {
        specimen.setParameters(parseNamedValueTypeArray(sfst.getParameterArray()));
    }
    // TODO
    sfst.getMaterialClass();
    specimen.setMaterialClass((ReferenceType) decodeXmlElement(sfst.getMaterialClass()));
    specimen.setSamplingTime(getSamplingTime(sfst));
    // samplingLocation
    if (sfst.isSetSamplingLocation()) {
        specimen.setSamplingLocation(getGeometry(sfst));
    }
    // sfst.getProcessingDetailsArray();
    if (sfst.isSetSize()) {
        specimen.setSize(getSize(sfst.getSize()));
    }
    // }
    if (sfst.isSetSpecimenType()) {
        specimen.setSpecimenType((ReferenceType) decodeXmlElement(sfst.getSpecimenType()));
    }
    return specimen;
}
Also used : SfSpecimen(org.n52.shetland.ogc.om.features.samplingFeatures.SfSpecimen)

Example 9 with AbstractFeature

use of org.n52.shetland.ogc.gml.AbstractFeature 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 10 with AbstractFeature

use of org.n52.shetland.ogc.gml.AbstractFeature in project arctic-sea by 52North.

the class SwesDecoderv20 method parseUpdateSensorDescription.

/**
 * parses the Xmlbeans UpdateSensorDescription document to a SOS request.
 *
 * @param xbUpSenDoc
 *            UpdateSensorDescription document
 * @return SOS UpdateSensor request
 *
 * @throws DecodingException
 *             * if an error occurs.
 */
private OwsServiceRequest parseUpdateSensorDescription(final UpdateSensorDescriptionDocument xbUpSenDoc) throws DecodingException {
    final UpdateSensorRequest request = new UpdateSensorRequest();
    final UpdateSensorDescriptionType xbUpdateSensor = xbUpSenDoc.getUpdateSensorDescription();
    request.setService(xbUpdateSensor.getService());
    request.setVersion(xbUpdateSensor.getVersion());
    request.setProcedureIdentifier(xbUpdateSensor.getProcedure());
    request.setProcedureDescriptionFormat(xbUpdateSensor.getProcedureDescriptionFormat());
    // extensions
    request.setExtensions(parseExtensibleRequest(xbUpdateSensor));
    for (final Description description : xbUpdateSensor.getDescriptionArray()) {
        SensorDescriptionType sensorDescription = description.getSensorDescription();
        try {
            // TODO exception if valid time is set
            final XmlObject xmlObject = XmlObject.Factory.parse(getNodeFromNodeList(sensorDescription.getData().getDomNode().getChildNodes()));
            Decoder<?, XmlObject> decoder = getDecoder(getDecoderKey(xmlObject));
            if (decoder == null) {
                throw new DecodingException(UpdateSensorDescriptionParams.procedureDescriptionFormat, "The requested procedureDescritpionFormat is not supported!");
            }
            final Object decodedObject = decoder.decode(xmlObject);
            SosProcedureDescription<?> sosProcedureDescription = null;
            if (decodedObject instanceof SosProcedureDescription) {
                sosProcedureDescription = (SosProcedureDescription) decodedObject;
            } else if (decodedObject instanceof AbstractFeature) {
                sosProcedureDescription = new SosProcedureDescription<>((AbstractFeature) decodedObject);
            }
            if (sosProcedureDescription != null) {
                if (sensorDescription.isSetValidTime()) {
                    sosProcedureDescription.setValidTime(getValidTime(sensorDescription.getValidTime()));
                }
            }
            request.addProcedureDescriptionString(sosProcedureDescription);
        } catch (final XmlException xmle) {
            throw new DecodingException("Error while parsing procedure description of UpdateSensor request!", xmle);
        }
    }
    return request;
}
Also used : UpdateSensorDescriptionType(net.opengis.swes.x20.UpdateSensorDescriptionType) UpdateSensorRequest(org.n52.shetland.ogc.sos.request.UpdateSensorRequest) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription) Description(net.opengis.swes.x20.UpdateSensorDescriptionType.Description) XmlException(org.apache.xmlbeans.XmlException) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) OwsServiceCommunicationObject(org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject) XmlObject(org.apache.xmlbeans.XmlObject) SensorDescriptionType(net.opengis.swes.x20.SensorDescriptionType) UpdateSensorDescriptionType(net.opengis.swes.x20.UpdateSensorDescriptionType)

Aggregations

AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)33 XmlObject (org.apache.xmlbeans.XmlObject)23 XmlException (org.apache.xmlbeans.XmlException)10 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)10 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)9 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)9 OmObservation (org.n52.shetland.ogc.om.OmObservation)8 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)8 DecodingException (org.n52.svalbard.decode.exception.DecodingException)8 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)8 Test (org.junit.Test)6 LineString (org.locationtech.jts.geom.LineString)6 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)6 EncodingException (org.n52.svalbard.encode.exception.EncodingException)6 FeaturePropertyType (net.opengis.gml.x32.FeaturePropertyType)4 CodeType (org.n52.shetland.ogc.gml.CodeType)4 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)4 SosProcedureDescription (org.n52.shetland.ogc.sos.SosProcedureDescription)4 DateTime (org.joda.time.DateTime)3 Time (org.n52.shetland.ogc.gml.time.Time)3