Search in sources :

Example 31 with SweAbstractDataComponent

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

the class GetResultTemplateResponseEncoder method encodeSweDataRecord.

private void encodeSweDataRecord(SweAbstractDataComponent structure, ObjectNode node) throws EncodingException {
    SweDataRecord sweDataRecord = (SweDataRecord) structure;
    ArrayNode fields = node.putArray(JSONConstants.FIELDS);
    for (SweField field : sweDataRecord.getFields()) {
        fields.add(encodeObjectToJson(field));
    }
}
Also used : SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 32 with SweAbstractDataComponent

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

the class SensorMLDecoderV20 method parseCharacteristics.

/**
 * Parses the characteristics
 *
 * @param clpts
 *            XML characteristics
 * @return SOS characteristics
 *
 * @throws DecodingException
 *             * if an error occurs
 */
private List<SmlCharacteristics> parseCharacteristics(final CharacteristicListPropertyType[] clpts) throws DecodingException {
    final List<SmlCharacteristics> sosCharacteristicsList = new ArrayList<>(clpts.length);
    for (final CharacteristicListPropertyType clpt : clpts) {
        final SmlCharacteristics sosCharacteristics = new SmlCharacteristics();
        if (clpt.isSetCharacteristicList()) {
            CharacteristicListType clt = clpt.getCharacteristicList();
            if (CollectionHelper.isNotNullOrEmpty(clt.getCharacteristicArray())) {
                for (Characteristic c : clt.getCharacteristicArray()) {
                    final SmlCharacteristic characteristic = new SmlCharacteristic(c.getName());
                    if (c.isSetAbstractDataComponent()) {
                        final Object o = decodeXmlElement(c.getAbstractDataComponent());
                        if (o instanceof SweAbstractDataComponent) {
                            characteristic.setAbstractDataComponent((SweAbstractDataComponent) o);
                        } else {
                            throw new DecodingException(XmlHelper.getLocalName(clpt), "Error while parsing the characteristics of the SensorML " + "(the characteristics' data record is not of " + "type DataRecordPropertyType)!");
                        }
                    } else if (c.isSetHref()) {
                        characteristic.setHref(c.getHref());
                        if (c.isSetTitle()) {
                            characteristic.setTitle(c.getTitle());
                        }
                    }
                    sosCharacteristics.addCharacteristic(characteristic);
                }
            }
        }
        sosCharacteristicsList.add(sosCharacteristics);
    }
    return sosCharacteristicsList;
}
Also used : SmlCharacteristics(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristics) CharacteristicListPropertyType(net.opengis.sensorml.x20.CharacteristicListPropertyType) SmlCharacteristic(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristic) SmlCharacteristic(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristic) Characteristic(net.opengis.sensorml.x20.CharacteristicListType.Characteristic) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) ArrayList(java.util.ArrayList) CharacteristicListType(net.opengis.sensorml.x20.CharacteristicListType) DescribedObject(org.n52.shetland.ogc.sensorML.v20.DescribedObject) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException)

Example 33 with SweAbstractDataComponent

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

the class SensorMLDecoderV20 method parseCapabilities.

/**
 * Parses the capabilities, processing and removing special insertion
 * metadata
 *
 * @param abstractProcess
 *            The AbstractProcess to which capabilities and insertion
 *            metadata are added
 * @param capabilitiesArray
 *            XML capabilities
 *
 * @throws DecodingException
 *             * if an error occurs
 */
private void parseCapabilities(final AbstractProcess abstractProcess, final Capabilities[] capabilitiesArray) throws DecodingException {
    for (final Capabilities cs : capabilitiesArray) {
        final SmlCapabilities capabilities = new SmlCapabilities(cs.getName());
        if (cs.isSetCapabilityList()) {
            CapabilityListType cl = cs.getCapabilityList();
            if (CollectionHelper.isNotNullOrEmpty(cl.getCapabilityArray())) {
                for (Capability c : cl.getCapabilityArray()) {
                    final SmlCapability capability = new SmlCapability(c.getName());
                    if (c.isSetAbstractDataComponent()) {
                        final Object o = decodeXmlElement(c.getAbstractDataComponent());
                        if (o instanceof SweAbstractDataComponent) {
                            capability.setAbstractDataComponent((SweAbstractDataComponent) o);
                            capabilities.addCapability(capability);
                        } else {
                            throw new DecodingException(XmlHelper.getLocalName(cs), "Error while parsing the capabilities of " + "the SensorML (the capabilities data record " + "is not of type DataRecordPropertyType)!");
                        }
                    } else if (c.isSetHref()) {
                        capability.setHref(c.getHref());
                        if (c.isSetTitle()) {
                            capability.setTitle(c.getTitle());
                        }
                    }
                }
            }
        }
        abstractProcess.addCapabilities(capabilities);
    }
}
Also used : SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) CapabilityListType(net.opengis.sensorml.x20.CapabilityListType) SmlCapability(org.n52.shetland.ogc.sensorML.elements.SmlCapability) Capability(net.opengis.sensorml.x20.CapabilityListType.Capability) Capabilities(net.opengis.sensorml.x20.DescribedObjectType.Capabilities) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) DescribedObject(org.n52.shetland.ogc.sensorML.v20.DescribedObject) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) SmlCapability(org.n52.shetland.ogc.sensorML.elements.SmlCapability)

Example 34 with SweAbstractDataComponent

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

the class SweCommonEncoderv101 method createField.

private DataComponentPropertyType createField(SweField sweField) throws EncodingException {
    SweAbstractDataComponent sosElement = sweField.getElement();
    DataComponentPropertyType xbField = DataComponentPropertyType.Factory.newInstance(getXmlOptions());
    if (sweField.isSetName()) {
        xbField.setName(sweField.getName().getValue());
    }
    if (sosElement instanceof SweBoolean) {
        xbField.addNewBoolean().set(createSimpleType((SweBoolean) sosElement));
    } else if (sosElement instanceof SweCategory) {
        xbField.addNewCategory().set(createSimpleType((SweCategory) sosElement));
    } else if (sosElement instanceof SweCount) {
        xbField.addNewCount().set(createSimpleType((SweCount) sosElement));
    } else if (sosElement instanceof SweCountRange) {
        xbField.addNewCount().set(createSimpleType((SweCountRange) sosElement));
    } else if (sosElement instanceof SweQuantity) {
        xbField.addNewQuantity().set(createSimpleType((SweQuantity) sosElement));
    } else if (sosElement instanceof SweQuantityRange) {
        xbField.addNewQuantity().set(createSimpleType((SweQuantityRange) sosElement));
    } else if (sosElement instanceof SweText) {
        xbField.addNewText().set(createSimpleType((SweText) sosElement));
    } else if (sosElement instanceof SweTimeRange) {
        xbField.addNewTimeRange().set(createSimpleType((SweTimeRange) sosElement));
    } else if (sosElement instanceof SweTime) {
        xbField.addNewTime().set(createSimpleType((SweTime) sosElement));
    } else if (sosElement instanceof SweEnvelope) {
        EnvelopeType xbEnvelope = (EnvelopeType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_ENVELOPE_SWE_101, EnvelopeType.type);
        xbEnvelope.set(createEnvelope((SweEnvelope) sosElement));
    } else if (sosElement instanceof SweDataRecord) {
        DataRecordType xbEnvelope = (DataRecordType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataRecordType.type);
        xbEnvelope.set(createDataRecord((SweDataRecord) sosElement));
    } else if (sosElement instanceof SweDataArray) {
        DataArrayType xbEnvelope = (DataArrayType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataArrayType.type);
        xbEnvelope.set(createDataArray((SweDataArray) sosElement).getDataArray1());
    } else {
        throw new EncodingException("The element type '%s' of the received '%s' is not supported by this encoder '%s'.", new Object[] { sosElement != null ? sosElement.getClass().getName() : null, sweField.getClass().getName(), getClass().getName() });
    }
    return xbField;
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) DataRecordType(net.opengis.swe.x101.DataRecordType) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) EnvelopeType(net.opengis.swe.x101.EnvelopeType) EncodingException(org.n52.svalbard.encode.exception.EncodingException) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) SweCountRange(org.n52.shetland.ogc.swe.simpleType.SweCountRange) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) DataArrayType(net.opengis.swe.x101.DataArrayType)

Example 35 with SweAbstractDataComponent

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

the class SensorMLEncoderv101 method addSweSimpleTypeToField.

/**
 * Adds a SOS SWE simple type to a XML SWE field.
 *
 * @param xbField
 *            XML SWE field
 * @param sosSweData
 *            SOS field element content
 *
 * @throws EncodingException
 *             if an error occurs
 */
private void addSweSimpleTypeToField(AnyScalarPropertyType xbField, SweAbstractDataComponent sosSweData) throws EncodingException {
    Encoder<?, SweAbstractDataComponent> encoder = getEncoder(new XmlEncoderKey(SweConstants.NS_SWE_101, SweDataArray.class));
    if (encoder == null) {
        throw new EncodingException("The %s is not supported by this SOS for SWE fields!", sosSweData.getClass().getSimpleName());
    }
    XmlObject encoded = (XmlObject) encoder.encode(sosSweData);
    if (!(sosSweData instanceof SweAbstractSimpleType)) {
        throw new EncodingException("The SosSweAbstractDataComponent '%s' is not supported by this SOS SensorML encoder!", sosSweData);
    }
    SweAbstractSimpleType<?> sosSweSimpleType = (SweAbstractSimpleType<?>) sosSweData;
    sosSweSimpleType.accept(new ScalarSweDataComponentAdder(xbField)).orElseThrow(() -> new EncodingException("The SWE simpleType '%s' is not supported by this SOS SensorML encoder!", sosSweSimpleType.getDataComponentType().name())).set(encoded);
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) SweAbstractSimpleType(org.n52.shetland.ogc.swe.simpleType.SweAbstractSimpleType) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) XmlObject(org.apache.xmlbeans.XmlObject) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray)

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