Search in sources :

Example 6 with DecodingException

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

the class ContactJSONDecoder method decodeJSON.

@Override
public Contact decodeJSON(JsonNode node, boolean validate) throws DecodingException {
    Contact contact = new Contact();
    contact.setAddress(decodeJsonToNillable(node.path(AQDJSONConstants.ADDRESS), AddressRepresentation.class));
    contact.setContactInstructions(parseNillable(node.path(AQDJSONConstants.CONTACT_INSTRUCTIONS)).map(this::parseFreeText));
    contact.setElectronicMailAddress(parseNillableString(node.path(AQDJSONConstants.ELECTRONIC_MAIL_ADDRESS)));
    contact.setHoursOfService(parseNillable(node.path(AQDJSONConstants.HOURS_OF_SERVICE)).map(this::parseFreeText));
    contact.setWebsite(parseNillableString(node.path(AQDJSONConstants.WEBSITE)));
    JsonNode tfNode = node.path(AQDJSONConstants.TELEPHONE_FACSIMILE);
    if (tfNode.isArray()) {
        for (JsonNode n : tfNode) {
            contact.addTelephoneFacsimile(parseNillableString(n));
        }
    } else {
        contact.addTelephoneFacsimile(parseNillableString(tfNode));
    }
    JsonNode tvNode = node.path(AQDJSONConstants.TELEPHONE_VOICE);
    if (tvNode.isArray()) {
        for (JsonNode n : tvNode) {
            contact.addTelephoneVoice(parseNillableString(n));
        }
    } else {
        contact.addTelephoneVoice(parseNillableString(tvNode));
    }
    return contact;
}
Also used : AddressRepresentation(org.n52.shetland.inspire.ad.AddressRepresentation) JsonNode(com.fasterxml.jackson.databind.JsonNode) Contact(org.n52.shetland.inspire.base2.Contact)

Example 7 with DecodingException

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

the class EReportingHeaderJSONDecoder method decodeJSON.

@Override
public EReportingHeader decodeJSON(JsonNode node, boolean validate) throws DecodingException {
    EReportingHeader header = new EReportingHeader();
    header.setChange(decodeJsonToObject(node.path(AQDJSONConstants.CHANGE), EReportingChange.class));
    header.setIdentifier(decodeJsonToObject(node.path(AQDJSONConstants.INSPIRE_ID), Identifier.class));
    header.setReportingAuthority(decodeJsonToObject(node.path(AQDJSONConstants.REPORTING_AUTHORITY), RelatedParty.class));
    header.setReportingPeriod(parseReferenceableTime(node.path(AQDJSONConstants.REPORTING_PERIOD)));
    for (JsonNode child : node.path(AQDJSONConstants.CONTENT)) {
        header.addContent(decodeJsonToReferencable(child, AbstractFeature.class));
    }
    for (JsonNode child : node.path(AQDJSONConstants.DELETE)) {
        header.addDelete(decodeJsonToReferencable(child, AbstractFeature.class));
    }
    return header;
}
Also used : Identifier(org.n52.shetland.inspire.base.Identifier) EReportingHeader(org.n52.shetland.aqd.EReportingHeader) RelatedParty(org.n52.shetland.inspire.base2.RelatedParty) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) JsonNode(com.fasterxml.jackson.databind.JsonNode) EReportingChange(org.n52.shetland.aqd.EReportingChange)

Example 8 with DecodingException

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

the class FieldDecoder method decodeJSON.

public SweField decodeJSON(JsonNode node) throws DecodingException {
    final String type = node.path(JSONConstants.TYPE).textValue();
    final SweAbstractDataComponent element;
    if (type.equals(JSONConstants.BOOLEAN_TYPE)) {
        element = decodeBoolean(node);
    } else if (type.equals(JSONConstants.COUNT_TYPE)) {
        element = decodeCount(node);
    } else if (type.equals(JSONConstants.COUNT_RANGE_TYPE)) {
        element = decodeCountRange(node);
    } else if (type.equals(JSONConstants.OBSERVABLE_PROPERTY_TYPE)) {
        element = decodeObservableProperty(node);
    } else if (type.equals(JSONConstants.QUALITY_TYPE)) {
        element = decodeQuality(node);
    } else if (type.equals(JSONConstants.TEXT_TYPE)) {
        element = decodeText(node);
    } else if (type.equals(JSONConstants.QUANTITY_TYPE)) {
        element = decodeQuantity(node);
    } else if (type.equals(JSONConstants.QUANTITY_RANGE_TYPE)) {
        element = decodeQuantityRange(node);
    } else if (type.equals(JSONConstants.TIME_TYPE)) {
        element = decodeTime(node);
    } else if (type.equals(JSONConstants.TIME_RANGE_TYPE)) {
        element = decodeTimeRange(node);
    } else if (type.equals(JSONConstants.CATEGORY_TYPE)) {
        element = decodeCategory(node);
    } else {
        throw new UnsupportedDecoderInputException(this, node);
    }
    final String name = node.path(JSONConstants.NAME).textValue();
    element.setDescription(node.path(JSONConstants.DESCRIPTION).textValue());
    element.setIdentifier(node.path(JSONConstants.IDENTIFIER).textValue());
    element.setDefinition(node.path(JSONConstants.DEFINITION).textValue());
    element.setLabel(node.path(JSONConstants.LABEL).textValue());
    return new SweField(name, element);
}
Also used : SweField(org.n52.shetland.ogc.swe.SweField) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) UnsupportedDecoderInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderInputException)

Example 9 with DecodingException

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

the class FieldDecoder method decodeTimeRange.

protected SweAbstractDataComponent decodeTimeRange(JsonNode node) throws DecodingException {
    SweTimeRange swe = new SweTimeRange();
    if (node.hasNonNull(JSONConstants.VALUE)) {
        String start = node.path(JSONConstants.VALUE).path(0).textValue();
        String end = node.path(JSONConstants.VALUE).path(1).textValue();
        swe.setValue(new RangeValue<DateTime>(parseDateTime(start), parseDateTime(end)));
    }
    return swe.setUom(node.path(JSONConstants.UOM).textValue());
}
Also used : SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) DateTime(org.joda.time.DateTime)

Example 10 with DecodingException

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

the class JSONValidator method validateAndThrow.

public void validateAndThrow(JsonNode instance, String schema) throws DecodingException {
    ProcessingReport report = JSONValidator.getInstance().validate(instance, schema);
    if (!report.isSuccess()) {
        String message = encode(report, instance);
        LOG.info("Invalid JSON instance:\n{}", message);
        throw new JSONDecodingException(message);
    }
}
Also used : ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) JSONDecodingException(org.n52.svalbard.decode.json.JSONDecodingException)

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