Search in sources :

Example 21 with SensorML

use of org.n52.shetland.ogc.sensorML.SensorML 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 22 with SensorML

use of org.n52.shetland.ogc.sensorML.SensorML 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 23 with SensorML

use of org.n52.shetland.ogc.sensorML.SensorML 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)

Example 24 with SensorML

use of org.n52.shetland.ogc.sensorML.SensorML in project arctic-sea by 52North.

the class SensorMLEncoderv101 method createPosition.

/**
 * Creates the position section of the SensorML description.
 *
 * @param position
 *            SOS position
 *
 * @return XML Position element
 *
 * @throws EncodingException
 *             if an error occurs
 */
private Position createPosition(final SmlPosition position) throws EncodingException {
    Position xbPosition = Position.Factory.newInstance(getXmlOptions());
    if (position.isSetName()) {
        xbPosition.setName(position.getName().getValue());
    } else {
        xbPosition.setName("position");
    }
    PositionType xbSwePosition = xbPosition.addNewPosition();
    xbSwePosition.setFixed(position.isFixed());
    xbSwePosition.setReferenceFrame(position.getReferenceFrame());
    final VectorType xbVector = xbSwePosition.addNewLocation().addNewVector();
    for (SweCoordinate<?> coordinate : position.getPosition()) {
        if (coordinate.getValue().getValue() != null && (!coordinate.getValue().isSetValue() || !coordinate.getValue().getValue().equals(Double.NaN))) {
            // FIXME: SWE Common NS
            xbVector.addNewCoordinate().set(encodeObjectToXml(SweConstants.NS_SWE_101, coordinate));
        }
    }
    return xbPosition;
}
Also used : PositionType(net.opengis.swe.x101.PositionType) SmlPosition(org.n52.shetland.ogc.sensorML.elements.SmlPosition) Position(net.opengis.sensorML.x101.PositionDocument.Position) VectorType(net.opengis.swe.x101.VectorType)

Example 25 with SensorML

use of org.n52.shetland.ogc.sensorML.SensorML in project arctic-sea by 52North.

the class SensorMLEncoderv101 method createComponents.

/**
 * Creates the components section of the SensorML description.
 *
 * @param sosComponents
 *            SOS SWE representation.
 *
 * @return encoded sml:components
 *
 * @throws EncodingException
 *             if the encoding fails
 */
private Components createComponents(List<SmlComponent> sosComponents) throws EncodingException {
    Components components = Components.Factory.newInstance(getXmlOptions());
    ComponentList componentList = components.addNewComponentList();
    for (SmlComponent sosSMLComponent : sosComponents) {
        Component component = componentList.addNewComponent();
        if (sosSMLComponent.getName() != null) {
            component.setName(sosSMLComponent.getName());
        }
        if (sosSMLComponent.getHref() != null) {
            component.setHref(sosSMLComponent.getHref());
            if (sosSMLComponent.getTitle() != null) {
                component.setTitle(sosSMLComponent.getTitle());
            }
        } else if (sosSMLComponent.getProcess() != null) {
            XmlObject xmlObject = null;
            if (sosSMLComponent.getProcess().isSetXml()) {
                try {
                    xmlObject = XmlObject.Factory.parse(sosSMLComponent.getProcess().getXml());
                } catch (XmlException xmle) {
                    throw new EncodingException("Error while encoding SensorML child procedure description " + "from stored SensorML encoded sensor description with XMLBeans", xmle);
                }
            } else {
                if (sosSMLComponent.getProcess() instanceof SensorML) {
                    xmlObject = createSensorDescriptionFromObject(((SensorML) sosSMLComponent.getProcess()).getMembers().iterator().next());
                } else if (sosSMLComponent.getProcess() instanceof AbstractProcess) {
                    xmlObject = createSensorDescriptionFromObject(sosSMLComponent.getProcess());
                }
            }
            if (xmlObject != null) {
                AbstractProcessType xbProcess = null;
                if (xmlObject instanceof SensorMLDocument) {
                    final SensorMLDocument smlDoc = (SensorMLDocument) xmlObject;
                    for (final Member member : smlDoc.getSensorML().getMemberArray()) {
                        xbProcess = member.getProcess();
                        break;
                    }
                } else if (xmlObject instanceof AbstractProcessType) {
                    xbProcess = (AbstractProcessType) xmlObject;
                }
                if (xbProcess == null) {
                    throw new EncodingException("The sensor type is not supported by this SOS");
                }
                // TODO add feature/parentProcs/childProcs to component - is
                // this already done?
                SchemaType schemaType = xbProcess.schemaType();
                component.addNewProcess().substitute(getQnameForType(schemaType), schemaType).set(xbProcess);
            }
        }
    }
    return components;
}
Also used : AbstractProcessType(net.opengis.sensorML.x101.AbstractProcessType) EncodingException(org.n52.svalbard.encode.exception.EncodingException) AbstractProcess(org.n52.shetland.ogc.sensorML.AbstractProcess) ComponentList(net.opengis.sensorML.x101.ComponentsDocument.Components.ComponentList) SensorML(org.n52.shetland.ogc.sensorML.SensorML) AbstractSensorML(org.n52.shetland.ogc.sensorML.AbstractSensorML) SchemaType(org.apache.xmlbeans.SchemaType) Components(net.opengis.sensorML.x101.ComponentsDocument.Components) SensorMLDocument(net.opengis.sensorML.x101.SensorMLDocument) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) SmlComponent(org.n52.shetland.ogc.sensorML.elements.SmlComponent) Component(net.opengis.sensorML.x101.ComponentsDocument.Components.ComponentList.Component) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) Member(net.opengis.sensorML.x101.SensorMLDocument.SensorML.Member) SmlComponent(org.n52.shetland.ogc.sensorML.elements.SmlComponent)

Aggregations

SensorML (org.n52.shetland.ogc.sensorML.SensorML)13 XmlObject (org.apache.xmlbeans.XmlObject)12 SystemType (net.opengis.sensorML.x101.SystemType)10 Test (org.junit.Test)9 System (org.n52.shetland.ogc.sensorML.System)9 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)7 SensorMLDocument (net.opengis.sensorML.x101.SensorMLDocument)5 DecodingException (org.n52.svalbard.decode.exception.DecodingException)5 SmlIo (org.n52.shetland.ogc.sensorML.elements.SmlIo)4 ResponsibleParty (net.opengis.sensorML.x101.ResponsiblePartyDocument.ResponsibleParty)3 SmlPerson (org.n52.shetland.ogc.sensorML.SmlPerson)3 ArrayList (java.util.ArrayList)2 AbstractProcessType (net.opengis.sensorML.x101.AbstractProcessType)2 ComponentType (net.opengis.sensorML.x101.ComponentType)2 Component (net.opengis.sensorML.x101.ComponentsDocument.Components.ComponentList.Component)2 ContactList (net.opengis.sensorML.x101.ContactListDocument.ContactList)2 Member (net.opengis.sensorML.x101.ContactListDocument.ContactList.Member)2 IdentifierList (net.opengis.sensorML.x101.IdentificationDocument.Identification.IdentifierList)2 Identifier (net.opengis.sensorML.x101.IdentificationDocument.Identification.IdentifierList.Identifier)2 Person (net.opengis.sensorML.x101.PersonDocument.Person)2