Search in sources :

Example 1 with Capability

use of net.opengis.sensorml.x20.CapabilityListType.Capability 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 2 with Capability

use of net.opengis.sensorml.x20.CapabilityListType.Capability 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 3 with Capability

use of net.opengis.sensorml.x20.CapabilityListType.Capability in project arctic-sea by 52North.

the class SensorMLEncoderv20 method addDescribedObjectValues.

private void addDescribedObjectValues(DescribedObjectType dot, DescribedObject describedObject) throws EncodingException {
    if (!describedObject.isSetGmlID()) {
        describedObject.setGmlId("do_" + JavaHelper.generateID(describedObject.toString()));
    }
    if (dot.getId() == null || dot.getId().isEmpty()) {
        dot.setId(describedObject.getGmlId());
    }
    // update/set gml:identifier
    if (describedObject.isSetIdentifier()) {
        describedObject.getIdentifierCodeWithAuthority().setCodeSpace(OGCConstants.UNIQUE_ID);
        XmlObject encodeObjectToXml = encodeObjectToXmlGml32(describedObject.getIdentifierCodeWithAuthority());
        if (encodeObjectToXml != null) {
            if (dot.isSetIdentifier()) {
                dot.getIdentifier().set(encodeObjectToXml);
            } else {
                dot.addNewIdentifier().set(encodeObjectToXml);
            }
        }
    }
    // set capabilities
    if (describedObject.isSetCapabilities()) {
        final Capabilities[] existing = dot.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 : describedObject.getCapabilities()) {
            // Update Discovery Profile
            if (!SensorMLConstants.ELEMENT_NAME_OBSERVED_BBOX.equals(sosCapability.getName())) {
                final Capabilities c = createCapability(sosCapability);
                // replace existing capability with the same name
                if (c != null) {
                    if (names.contains(c.getName())) {
                        removeCapability(dot, c);
                    }
                    dot.addNewCapabilities().set(c);
                }
            }
        }
    }
    // set description
    if (describedObject.isSetDescription() && !dot.isSetDescription()) {
        dot.addNewDescription().setStringValue(describedObject.getDescription());
    }
    // set names
    if (describedObject.isSetName() && CollectionHelper.isNullOrEmpty(dot.getNameArray())) {
        // TODO check if override existing names
        addNamesToAbstractProcess(dot, describedObject.getNames());
    }
    // set keywords
    if (describedObject.isSetKeywords()) {
        if (CollectionHelper.isNullOrEmpty(dot.getKeywordsArray())) {
            final List<String> keywords = describedObject.getKeywords();
            // final int length = dot.getKeywordsArray().length;
            // for (int i = 0; i < length; ++i) {
            // dot.removeKeywords(i);
            // }
            dot.addNewKeywords().addNewKeywordList().setKeywordArray(keywords.toArray(new String[keywords.size()]));
        // TODO else
        }
    }
    // set identification
    if (describedObject.isSetIdentifications()) {
        // TODO check for merging identifications if exists
        dot.setIdentificationArray(createIdentification(describedObject.getIdentifications()));
    }
    // set classification
    if (describedObject.isSetClassifications()) {
        dot.setClassificationArray(createClassification(describedObject.getClassifications()));
    }
    // set validTime
    if (describedObject.isSetValidTime() && CollectionHelper.isNullOrEmpty(dot.getValidTimeArray())) {
        for (Time time : describedObject.getValidTime()) {
            final XmlObject xbtime = encodeObjectToXmlGml32(time);
            if (time instanceof TimeInstant) {
                dot.addNewValidTime().addNewTimeInstant().set(xbtime);
            } else if (time instanceof TimePeriod) {
                dot.addNewValidTime().addNewTimePeriod().set(xbtime);
            }
        }
    // } else {
    // TODO remove or
    // remove existing validTime element
    // final XmlCursor newCursor = dot.getValidTime().newCursor();
    // newCursor.removeXml();
    // newCursor.dispose();
    }
    // set characteristics
    if (describedObject.isSetCharacteristics()) {
        dot.setCharacteristicsArray(createCharacteristics(describedObject.getCharacteristics()));
    }
    // CollectionHelper.isNotNullOrEmpty(dot.getContactsArray())) {
    if (describedObject.isSetContact()) {
        if (CollectionHelper.isNullOrEmpty(dot.getContactsArray())) {
            ContactListType cl = ContactListType.Factory.newInstance();
            for (SmlContact contact : describedObject.getContact()) {
                if (contact instanceof SmlResponsibleParty) {
                    if (contact.isSetHref()) {
                        XmlObject xml = encodeObjectToXml(GmdConstants.NS_GMD, (SmlResponsibleParty) contact, EncodingContext.of(XmlBeansEncodingFlags.PROPERTY_TYPE));
                        cl.addNewContact().set(xml);
                    } else {
                        XmlObject encodeObjectToXml = encodeObjectToXml(GmdConstants.NS_GMD, contact);
                        if (encodeObjectToXml != null) {
                            cl.addNewContact().addNewCIResponsibleParty().set(encodeObjectToXml);
                        }
                    }
                }
            }
            if (CollectionHelper.isNotNullOrEmpty(cl.getContactArray())) {
                dot.addNewContacts().setContactList(cl);
            }
        }
    }
    // set documentation
    if (describedObject.isSetDocumentation()) {
        if (CollectionHelper.isNullOrEmpty(dot.getDocumentationArray())) {
            dot.setDocumentationArray(createDocumentationArray(describedObject.getDocumentation()));
        }
    }
// set history
}
Also used : SmlResponsibleParty(org.n52.shetland.ogc.sensorML.SmlResponsibleParty) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) Time(org.n52.shetland.ogc.gml.time.Time) SmlContact(org.n52.shetland.ogc.sensorML.SmlContact) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) Capabilities(net.opengis.sensorml.x20.DescribedObjectType.Capabilities) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) XmlObject(org.apache.xmlbeans.XmlObject) ContactListType(net.opengis.sensorml.x20.ContactListType) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Aggregations

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