Search in sources :

Example 6 with SweAbstractDataComponent

use of org.n52.shetland.ogc.swe.SweAbstractDataComponent in project arctic-sea by 52North.

the class FieldDecoder method decodeQuantityRange.

protected SweAbstractDataComponent decodeQuantityRange(JsonNode node) {
    SweQuantityRange swe = new SweQuantityRange();
    if (node.hasNonNull(JSONConstants.VALUE)) {
        BigDecimal start = BigDecimal.valueOf(node.path(JSONConstants.VALUE).path(0).doubleValue());
        BigDecimal end = BigDecimal.valueOf(node.path(JSONConstants.VALUE).path(1).doubleValue());
        swe.setValue(new RangeValue<BigDecimal>(start, end));
    }
    return swe.setUom(node.path(JSONConstants.UOM).textValue());
}
Also used : SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) BigDecimal(java.math.BigDecimal)

Example 7 with SweAbstractDataComponent

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

use of org.n52.shetland.ogc.swe.SweAbstractDataComponent in project arctic-sea by 52North.

the class GetResultTemplateResponseEncoder method encodeResultStructure.

private void encodeResultStructure(GetResultTemplateResponse t, ObjectNode json) throws EncodingException {
    ObjectNode jrs = json.putObject(JSONConstants.RESULT_STRUCTURE);
    SweAbstractDataComponent structure;
    SosResultStructure rs = t.getResultStructure();
    if (rs.isDecoded()) {
        structure = t.getResultStructure().get().get();
    } else {
        try {
            XmlNamespaceDecoderKey key = new XmlNamespaceDecoderKey(SweConstants.NS_SWE_20, SweAbstractDataComponent.class);
            Decoder<SweAbstractDataComponent, XmlObject> decoder = this.decoderRepository.getDecoder(key);
            if (decoder == null) {
                throw new NoDecoderForKeyException(key);
            }
            structure = decoder.decode(XmlObject.Factory.parse(rs.getXml().get()));
        } catch (XmlException | DecodingException ex) {
            throw new EncodingException(ex);
        }
    }
    if (structure instanceof SweDataRecord) {
        encodeSweDataRecord(structure, jrs);
    } else {
        LOG.warn("Unsupported structure: {}", structure == null ? null : structure.getClass());
    }
}
Also used : NoDecoderForKeyException(org.n52.svalbard.decode.exception.NoDecoderForKeyException) XmlNamespaceDecoderKey(org.n52.svalbard.decode.XmlNamespaceDecoderKey) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) EncodingException(org.n52.svalbard.encode.exception.EncodingException) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) XmlException(org.apache.xmlbeans.XmlException) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) SosResultStructure(org.n52.shetland.ogc.sos.SosResultStructure)

Example 9 with SweAbstractDataComponent

use of org.n52.shetland.ogc.swe.SweAbstractDataComponent in project arctic-sea by 52North.

the class ObservationEncoder method getFieldForValue.

private SweField getFieldForValue(String phenomenon, Value<?> value) throws EncodingException {
    final SweAbstractDataComponent def;
    if (value instanceof BooleanValue) {
        def = new SweBoolean();
    } else if (value instanceof CategoryValue) {
        SweCategory sweCategory = new SweCategory();
        CategoryValue categoryValue = (CategoryValue) value;
        sweCategory.setCodeSpace(categoryValue.getUnit());
        def = sweCategory;
    } else if (value instanceof CountValue) {
        def = new SweCount();
    } else if (value instanceof QuantityValue) {
        SweQuantity sweQuantity = new SweQuantity();
        QuantityValue quantityValue = (QuantityValue) value;
        sweQuantity.setUom(quantityValue.getUnit());
        def = sweQuantity;
    } else if (value instanceof TextValue) {
        def = new SweText();
    } else if (value instanceof NilTemplateValue) {
        def = new SweText();
    } else if (value instanceof BooleanValue) {
        def = new SweBoolean();
    } else if (value instanceof GeometryValue) {
        def = new SweText();
    } else {
        throw new UnsupportedEncoderInputException(this, value);
    }
    def.setDefinition(phenomenon);
    return new SweField(phenomenon, def);
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) CountValue(org.n52.shetland.ogc.om.values.CountValue) SweField(org.n52.shetland.ogc.swe.SweField) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) TextValue(org.n52.shetland.ogc.om.values.TextValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) NilTemplateValue(org.n52.shetland.ogc.om.values.NilTemplateValue)

Example 10 with SweAbstractDataComponent

use of org.n52.shetland.ogc.swe.SweAbstractDataComponent in project arctic-sea by 52North.

the class SweCommonDecoderV20 method parseAbstractDataComponent.

private SweAbstractDataComponent parseAbstractDataComponent(AbstractDataComponentType abstractDataComponent) throws DecodingException {
    SweAbstractDataComponent sosAbstractDataComponent = null;
    if (abstractDataComponent instanceof BooleanType) {
        sosAbstractDataComponent = parseBoolean((BooleanType) abstractDataComponent);
    } else if (abstractDataComponent instanceof CategoryType) {
        sosAbstractDataComponent = parseCategory((CategoryType) abstractDataComponent);
    } else if (abstractDataComponent instanceof CountRangeType) {
        sosAbstractDataComponent = parseCountRange((CountRangeType) abstractDataComponent);
    } else if (abstractDataComponent instanceof CountType) {
        sosAbstractDataComponent = parseCount((CountType) abstractDataComponent);
    } else if (abstractDataComponent instanceof QuantityType) {
        sosAbstractDataComponent = parseQuantity((QuantityType) abstractDataComponent);
    } else if (abstractDataComponent instanceof QuantityRangeType) {
        sosAbstractDataComponent = parseQuantityRange((QuantityRangeType) abstractDataComponent);
    } else if (abstractDataComponent instanceof TextType) {
        sosAbstractDataComponent = parseText((TextType) abstractDataComponent);
    } else if (abstractDataComponent instanceof TimeType) {
        sosAbstractDataComponent = parseTime((TimeType) abstractDataComponent);
    } else if (abstractDataComponent instanceof TimeRangeType) {
        sosAbstractDataComponent = parseTimeRange((TimeRangeType) abstractDataComponent);
    } else if (abstractDataComponent instanceof VectorType) {
        sosAbstractDataComponent = parseVector((VectorType) abstractDataComponent);
    } else if (abstractDataComponent instanceof DataRecordType) {
        SweDataRecord sosDataRecord = parseDataRecord((DataRecordType) abstractDataComponent);
        DataRecordDocument dataRecordDoc = DataRecordDocument.Factory.newInstance(getXmlOptions());
        dataRecordDoc.setDataRecord((DataRecordType) abstractDataComponent);
        sosDataRecord.setXml(dataRecordDoc.xmlText(getXmlOptions()));
        sosAbstractDataComponent = sosDataRecord;
    } else if (abstractDataComponent instanceof DataArrayType) {
        SweDataArray sosDataArray = parseDataArray((DataArrayType) abstractDataComponent);
        DataArrayDocument dataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
        dataArrayDoc.setDataArray1((DataArrayType) abstractDataComponent);
        sosDataArray.setXml(dataArrayDoc.xmlText(getXmlOptions()));
        sosAbstractDataComponent = sosDataArray;
    } else {
        throw new UnsupportedDecoderXmlInputException(this, abstractDataComponent);
    }
    if (sosAbstractDataComponent != null) {
        if (abstractDataComponent.isSetDefinition()) {
            sosAbstractDataComponent.setDefinition(abstractDataComponent.getDefinition());
        }
        if (abstractDataComponent.isSetDescription()) {
            sosAbstractDataComponent.setDescription(abstractDataComponent.getDescription());
        }
        if (abstractDataComponent.isSetIdentifier()) {
            sosAbstractDataComponent.setIdentifier(abstractDataComponent.getIdentifier());
        }
        if (abstractDataComponent.isSetLabel()) {
            sosAbstractDataComponent.setLabel(abstractDataComponent.getLabel());
        }
    }
    return sosAbstractDataComponent;
}
Also used : DataRecordType(net.opengis.swe.x20.DataRecordType) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) BooleanType(net.opengis.swe.x20.BooleanType) CategoryType(net.opengis.swe.x20.CategoryType) CountType(net.opengis.swe.x20.CountType) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) DataRecordDocument(net.opengis.swe.x20.DataRecordDocument) TextType(net.opengis.swe.x20.TextType) TimeType(net.opengis.swe.x20.TimeType) TimeRangeType(net.opengis.swe.x20.TimeRangeType) CountRangeType(net.opengis.swe.x20.CountRangeType) QuantityType(net.opengis.swe.x20.QuantityType) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) VectorType(net.opengis.swe.x20.VectorType) UnsupportedDecoderXmlInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderXmlInputException) QuantityRangeType(net.opengis.swe.x20.QuantityRangeType) DataArrayType(net.opengis.swe.x20.DataArrayType) DataArrayDocument(net.opengis.swe.x20.DataArrayDocument)

Aggregations

SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)24 XmlObject (org.apache.xmlbeans.XmlObject)11 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)8 SweField (org.n52.shetland.ogc.swe.SweField)7 ArrayList (java.util.ArrayList)4 DecodingException (org.n52.svalbard.decode.exception.DecodingException)4 EncodingException (org.n52.svalbard.encode.exception.EncodingException)4 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)3 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)3 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 CapabilityListType (net.opengis.sensorml.x20.CapabilityListType)2 Capability (net.opengis.sensorml.x20.CapabilityListType.Capability)2 CharacteristicListType (net.opengis.sensorml.x20.CharacteristicListType)2 Characteristic (net.opengis.sensorml.x20.CharacteristicListType.Characteristic)2 Capabilities (net.opengis.sensorml.x20.DescribedObjectType.Capabilities)2 DataRecordType (net.opengis.swe.x20.DataRecordType)2 DescribedObject (org.n52.shetland.ogc.sensorML.v20.DescribedObject)2 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)2 SweEnvelope (org.n52.shetland.ogc.swe.SweEnvelope)2