Search in sources :

Example 1 with SmlCapabilities

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

the class SensorMLDecoderV101 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 xbcaps : capabilitiesArray) {
        final SmlCapabilities caps = new SmlCapabilities();
        if (xbcaps.isSetName()) {
            caps.setName(xbcaps.getName());
        }
        if (xbcaps.isSetAbstractDataRecord()) {
            final Object o = decodeXmlElement(xbcaps.getAbstractDataRecord());
            if (o instanceof DataRecord) {
                final DataRecord record = (DataRecord) o;
                caps.setDataRecord(record).setName(xbcaps.getName());
            } else {
                throw new DecodingException(XmlHelper.getLocalName(xbcaps), "Error while parsing the capabilities of the SensorML (the " + "capabilities data record is not of type DataRecordPropertyType)!");
            }
        } else if (xbcaps.isSetHref()) {
            caps.setHref(xbcaps.getHref());
            if (xbcaps.isSetTitle()) {
                caps.setTitle(xbcaps.getTitle());
            }
        }
        if (caps.isSetName()) {
            abstractProcess.addCapabilities(caps);
        }
    }
}
Also used : SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) Capabilities(net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) DataRecord(org.n52.shetland.ogc.swe.DataRecord)

Example 2 with SmlCapabilities

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

the class SensorMLEncoderv101 method addAbstractProcessValues.

// TODO refactor/rename
private void addAbstractProcessValues(final AbstractProcessType abstractProcess, final AbstractProcess sosAbstractProcess) throws EncodingException {
    if (sosAbstractProcess.isSetGmlID()) {
        abstractProcess.setId(sosAbstractProcess.getGmlId());
    }
    if (sosAbstractProcess.isSetCapabilities()) {
        final Capabilities[] existing = abstractProcess.getCapabilitiesArray();
        final Set<String> names = Sets.newHashSetWithExpectedSize(existing.length);
        for (final Capabilities element : existing) {
            if (element.getName() != null) {
                names.add(element.getName());
            }
        }
        for (final SmlCapabilities sosCapability : sosAbstractProcess.getCapabilities()) {
            final Capabilities c = createCapability(sosCapability);
            // replace existing capability with the same name
            if (names.contains(c.getName())) {
                removeCapability(abstractProcess, c);
            }
            abstractProcess.addNewCapabilities().set(c);
        }
    }
    // set description
    if (sosAbstractProcess.isSetDescription() && !abstractProcess.isSetDescription()) {
        abstractProcess.addNewDescription().setStringValue(sosAbstractProcess.getDescription());
    }
    if (sosAbstractProcess.isSetName() && CollectionHelper.isNullOrEmpty(abstractProcess.getNameArray())) {
        // TODO check if override existing names
        addNamesToAbstractProcess(abstractProcess, sosAbstractProcess.getNames());
    }
    // set identification
    if (sosAbstractProcess.isSetIdentifications()) {
        abstractProcess.setIdentificationArray(createIdentification(sosAbstractProcess.getIdentifications()));
    }
    // set classification
    if (sosAbstractProcess.isSetClassifications()) {
        abstractProcess.setClassificationArray(createClassification(sosAbstractProcess.getClassifications()));
    }
    // set characteristics
    if (sosAbstractProcess.isSetCharacteristics()) {
        abstractProcess.setCharacteristicsArray(createCharacteristics(sosAbstractProcess.getCharacteristics()));
    }
    // set documentation
    if (sosAbstractProcess.isSetDocumentation() && CollectionHelper.isNullOrEmpty(abstractProcess.getDocumentationArray())) {
        abstractProcess.setDocumentationArray(createDocumentationArray(sosAbstractProcess.getDocumentation()));
    }
    // process
    if (sosAbstractProcess.isSetContact() && CollectionHelper.isNullOrEmpty(abstractProcess.getContactArray())) {
        ContactList contactList = createContactList(sosAbstractProcess.getContact());
        if (contactList != null && contactList.getMemberArray().length > 0) {
            abstractProcess.addNewContact().setContactList(contactList);
        }
    }
    // set keywords
    if (sosAbstractProcess.isSetKeywords()) {
        final List<String> keywords = sosAbstractProcess.getKeywords();
        final int length = abstractProcess.getKeywordsArray().length;
        for (int i = 0; i < length; ++i) {
            abstractProcess.removeKeywords(i);
        }
        abstractProcess.addNewKeywords().addNewKeywordList().setKeywordArray(keywords.toArray(new String[keywords.size()]));
    }
    if (sosAbstractProcess.isSetValidTime()) {
        if (abstractProcess.isSetValidTime()) {
            // remove existing validTime element
            final XmlCursor newCursor = abstractProcess.getValidTime().newCursor();
            newCursor.removeXml();
            newCursor.dispose();
        }
        final Time time = sosAbstractProcess.getMergedValidTime();
        final XmlObject xbtime = encodeObjectToXml(GmlConstants.NS_GML, time);
        if (time instanceof TimeInstant) {
            abstractProcess.addNewValidTime().addNewTimeInstant().set(xbtime);
        } else if (time instanceof TimePeriod) {
            abstractProcess.addNewValidTime().addNewTimePeriod().set(xbtime);
        }
    }
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) Time(org.n52.shetland.ogc.gml.time.Time) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) ContactList(net.opengis.sensorML.x101.ContactListDocument.ContactList) SmlContactList(org.n52.shetland.ogc.sensorML.SmlContactList) XmlCursor(org.apache.xmlbeans.XmlCursor) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) Capabilities(net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) XmlObject(org.apache.xmlbeans.XmlObject) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 3 with SmlCapabilities

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

the class SensorMLEncoderv101 method createCapability.

private Capabilities createCapability(final SmlCapabilities capabilities) throws EncodingException {
    final Capabilities xbCapabilities = Capabilities.Factory.newInstance(getXmlOptions());
    if (capabilities.isSetName()) {
        xbCapabilities.setName(capabilities.getName());
    }
    if (capabilities.isSetAbstractDataRecord() && capabilities.getDataRecord().isSetFields()) {
        final XmlObject encodedDataRecord = encodeObjectToXml(SweConstants.NS_SWE_101, capabilities.getDataRecord());
        final XmlObject substituteElement = XmlHelper.substituteElement(xbCapabilities.addNewAbstractDataRecord(), encodedDataRecord);
        substituteElement.set(encodedDataRecord);
    } else if (capabilities.isSetHref()) {
        xbCapabilities.setHref(capabilities.getHref());
        if (capabilities.isSetTitle()) {
            xbCapabilities.setTitle(capabilities.getTitle());
        }
    }
    return xbCapabilities;
}
Also used : Capabilities(net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) XmlObject(org.apache.xmlbeans.XmlObject)

Example 4 with SmlCapabilities

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

the class SensorMLEncoderv20 method createCapability.

private Capabilities createCapability(final SmlCapabilities capabilities) throws EncodingException {
    Capabilities xbCapabilities = null;
    if (capabilities.isSetAbstractDataComponents()) {
        xbCapabilities = Capabilities.Factory.newInstance(getXmlOptions());
        if (capabilities.isSetName()) {
            xbCapabilities.setName(capabilities.getName());
        }
        CapabilityListType capabilityList = xbCapabilities.addNewCapabilityList();
        if (capabilities.isSetCapabilities()) {
            for (SmlCapability capability : capabilities.getCapabilities()) {
                XmlObject encodeObjectToXml = encodeObjectToXmlSwe20(capability.getAbstractDataComponent());
                Capability c = capabilityList.addNewCapability();
                if (capability.isSetName()) {
                    c.setName(NcName.makeValid(capability.getName()));
                } else if (capability.getAbstractDataComponent().isSetName()) {
                    capability.setName(NcName.makeValid(capability.getAbstractDataComponent().getName().getValue()));
                } else {
                    capability.setName(NcName.makeValid(capability.getAbstractDataComponent().getDefinition()));
                }
                XmlObject substituteElement = XmlHelper.substituteElement(c.addNewAbstractDataComponent(), encodeObjectToXml);
                substituteElement.set(encodeObjectToXml);
            }
        } else if (capabilities.isSetAbstractDataComponents()) {
            for (SweAbstractDataComponent component : capabilities.getAbstractDataComponents()) {
                XmlObject encodeObjectToXml = encodeObjectToXmlSwe20(component);
                Capability capability = capabilityList.addNewCapability();
                if (component.isSetName()) {
                    capability.setName(NcName.makeValid(component.getName().getValue()));
                } else {
                    capability.setName(NcName.makeValid(component.getDefinition()));
                }
                XmlObject substituteElement = XmlHelper.substituteElement(capability.addNewAbstractDataComponent(), encodeObjectToXml);
                substituteElement.set(encodeObjectToXml);
            }
        }
    }
    return xbCapabilities;
}
Also used : 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) XmlObject(org.apache.xmlbeans.XmlObject) SmlCapability(org.n52.shetland.ogc.sensorML.elements.SmlCapability)

Example 5 with SmlCapabilities

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

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)6 SmlCapabilities (org.n52.shetland.ogc.sensorML.elements.SmlCapabilities)6 Capabilities (net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities)3 Capabilities (net.opengis.sensorml.x20.DescribedObjectType.Capabilities)3 CapabilityListType (net.opengis.sensorml.x20.CapabilityListType)2 Capability (net.opengis.sensorml.x20.CapabilityListType.Capability)2 Time (org.n52.shetland.ogc.gml.time.Time)2 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)2 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)2 SmlCapability (org.n52.shetland.ogc.sensorML.elements.SmlCapability)2 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)2 DecodingException (org.n52.svalbard.decode.exception.DecodingException)2 ContactList (net.opengis.sensorML.x101.ContactListDocument.ContactList)1 ContactListType (net.opengis.sensorml.x20.ContactListType)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 SmlContact (org.n52.shetland.ogc.sensorML.SmlContact)1 SmlContactList (org.n52.shetland.ogc.sensorML.SmlContactList)1 SmlResponsibleParty (org.n52.shetland.ogc.sensorML.SmlResponsibleParty)1 DescribedObject (org.n52.shetland.ogc.sensorML.v20.DescribedObject)1 DataRecord (org.n52.shetland.ogc.swe.DataRecord)1