Search in sources :

Example 51 with DecodingException

use of org.n52.svalbard.decode.exception.DecodingException in project arctic-sea by 52North.

the class InsertSensorRequestDecoder method parseProcedureDescription.

private SosProcedureDescription<?> parseProcedureDescription(JsonNode path, String pdf) throws DecodingException {
    try {
        final XmlObject xb = XmlObject.Factory.parse(path.textValue());
        Decoder<?, XmlObject> decoder = getProcedureDescriptionDecoder(pdf, xb);
        if (decoder == null) {
            throw new DecodingException(JSONConstants.PROCEDURE_DESCRIPTION_FORMAT, "The requested %s is not supported!", JSONConstants.PROCEDURE_DESCRIPTION_FORMAT);
        }
        Object decode = decoder.decode(xb);
        if (decode instanceof SosProcedureDescription<?>) {
            return (SosProcedureDescription<?>) decode;
        } else if (decode instanceof AbstractFeature) {
            return new SosProcedureDescription<AbstractFeature>((AbstractFeature) decode);
        } else {
            throw new DecodingException("The decoded element {} is not of type {}!", decode.getClass().getName(), AbstractFeature.class.getName());
        }
    } catch (final XmlException xmle) {
        throw new DecodingException("Error while parsing procedure description of InsertSensor request!", xmle);
    }
}
Also used : 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) XmlObject(org.apache.xmlbeans.XmlObject)

Example 52 with DecodingException

use of org.n52.svalbard.decode.exception.DecodingException in project arctic-sea by 52North.

the class ObservationDecoder method parseParameter.

protected Collection<NamedValue<?>> parseParameter(JsonNode node) throws DecodingException {
    Set<NamedValue<?>> parameters = Sets.newTreeSet();
    JsonNode parameter = node.path(JSONConstants.PARAMETER);
    if (parameter.isArray()) {
        for (JsonNode jsonNode : parameter) {
            parameters.add(parseNamedValue(jsonNode));
        }
    } else if (parameter.isObject()) {
        parameters.add(parseNamedValue(parameter));
    }
    return parameters;
}
Also used : NamedValue(org.n52.shetland.ogc.om.NamedValue) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 53 with DecodingException

use of org.n52.svalbard.decode.exception.DecodingException in project arctic-sea by 52North.

the class ObservationDecoder method decodeJSON.

protected OmObservation decodeJSON(JsonNode node) throws DecodingException {
    if (node.isObject()) {
        OmObservation o = new OmObservation();
        o.setIdentifier(parseIdentifier(node));
        o.setValidTime(parseValidTime(node));
        o.setResultTime(parseResultTime(node));
        o.setValue(parseValue(node));
        o.setParameter(parseParameter(node));
        o.setObservationConstellation(parseObservationConstellation(node));
        return o;
    } else {
        return null;
    }
}
Also used : OmObservation(org.n52.shetland.ogc.om.OmObservation)

Example 54 with DecodingException

use of org.n52.svalbard.decode.exception.DecodingException in project arctic-sea by 52North.

the class ObservationDecoder method parseObservationConstellation.

public OmObservationConstellation parseObservationConstellation(JsonNode node) throws DecodingException {
    OmObservationConstellation oc = new OmObservationConstellation();
    oc.setProcedure(parseProcedure(node));
    oc.setObservableProperty(parseObservableProperty(node));
    oc.setObservationType(parseObservationType(node));
    oc.setFeatureOfInterest(parseFeatureOfInterest(node));
    return oc;
}
Also used : OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation)

Example 55 with DecodingException

use of org.n52.svalbard.decode.exception.DecodingException in project arctic-sea by 52North.

the class RelatedPartyJSONDecoder method decodeJSON.

@Override
public RelatedParty decodeJSON(JsonNode node, boolean validate) throws DecodingException {
    RelatedParty relatedParty = new RelatedParty();
    relatedParty.setContact(decodeJsonToNillable(node.path(AQDJSONConstants.CONTACT), Contact.class));
    relatedParty.setIndividualName(parseNillable(node.path(AQDJSONConstants.INDIVIDUAL_NAME)).map(this::parseFreeText));
    relatedParty.setOrganisationName(parseNillable(node.path(AQDJSONConstants.ORGANISATION_NAME)).map(this::parseFreeText));
    relatedParty.setPositionName(parseNillable(node.path(AQDJSONConstants.POSITION_NAME)).map(this::parseFreeText));
    for (JsonNode n : node.path(AQDJSONConstants.ROLES)) {
        relatedParty.addRole(parseNillableReference(n));
    }
    return relatedParty;
}
Also used : RelatedParty(org.n52.shetland.inspire.base2.RelatedParty) JsonNode(com.fasterxml.jackson.databind.JsonNode) Contact(org.n52.shetland.inspire.base2.Contact)

Aggregations

Test (org.junit.Test)92 DecodingException (org.n52.svalbard.decode.exception.DecodingException)63 XmlObject (org.apache.xmlbeans.XmlObject)52 JsonNode (com.fasterxml.jackson.databind.JsonNode)25 SweField (org.n52.shetland.ogc.swe.SweField)25 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)23 XmlException (org.apache.xmlbeans.XmlException)23 GetObservationRequest (org.n52.shetland.ogc.sos.request.GetObservationRequest)22 UnsupportedDecoderInputException (org.n52.svalbard.decode.exception.UnsupportedDecoderInputException)21 AbstractProcess (org.n52.shetland.ogc.sensorML.AbstractProcess)13 SystemType (net.opengis.sensorML.x101.SystemType)12 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)12 Before (org.junit.Before)11 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)11 SensorMLDocument (net.opengis.sensorML.x101.SensorMLDocument)10 DateTime (org.joda.time.DateTime)10 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)10 XmlString (org.apache.xmlbeans.XmlString)9 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)8 Geometry (org.locationtech.jts.geom.Geometry)8