Search in sources :

Example 1 with AbstractProcessType

use of net.opengis.sensorML.x101.AbstractProcessType 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 2 with AbstractProcessType

use of net.opengis.sensorML.x101.AbstractProcessType in project arctic-sea by 52North.

the class SensorMLDecoderV101 method addSensorMLWrapperForXmlDescription.

private String addSensorMLWrapperForXmlDescription(final AbstractProcessType xbProcessType) {
    final SensorMLDocument xbSensorMLDoc = SensorMLDocument.Factory.newInstance(getXmlOptions());
    final net.opengis.sensorML.x101.SensorMLDocument.SensorML xbSensorML = xbSensorMLDoc.addNewSensorML();
    xbSensorML.setVersion(SensorMLConstants.VERSION_V101);
    final Member member = xbSensorML.addNewMember();
    final AbstractProcessType xbAbstractProcessType = (AbstractProcessType) member.addNewProcess().substitute(getQnameForType(xbProcessType.schemaType()), xbProcessType.schemaType());
    xbAbstractProcessType.set(xbProcessType);
    return xbSensorMLDoc.xmlText(getXmlOptions());
}
Also used : AbstractProcessType(net.opengis.sensorML.x101.AbstractProcessType) SensorMLDocument(net.opengis.sensorML.x101.SensorMLDocument) Member(net.opengis.sensorML.x101.SensorMLDocument.SensorML.Member)

Example 3 with AbstractProcessType

use of net.opengis.sensorML.x101.AbstractProcessType in project arctic-sea by 52North.

the class SensorMLDecoderV101 method parseSensorML.

@SuppressFBWarnings("BC_VACUOUS_INSTANCEOF")
private SensorML parseSensorML(final SensorMLDocument xbSensorML) throws DecodingException {
    final SensorML sensorML = new SensorML();
    // get member process
    for (final Member xbMember : xbSensorML.getSensorML().getMemberArray()) {
        if (xbMember.getProcess() != null) {
            if (xbMember.getProcess() instanceof AbstractProcessType) {
                final AbstractProcessType xbAbstractProcess = xbMember.getProcess();
                AbstractProcess abstractProcess = null;
                if (xbAbstractProcess.schemaType() == SystemType.type) {
                    abstractProcess = parseSystem((SystemType) xbAbstractProcess);
                } else if (xbAbstractProcess.schemaType() == ProcessModelType.type) {
                    abstractProcess = parseProcessModel((ProcessModelType) xbAbstractProcess);
                } else if (xbAbstractProcess.schemaType() == ComponentType.type) {
                    abstractProcess = parseComponent((ComponentType) xbAbstractProcess);
                } else {
                    throw unsupportedMemberProcess(xbMember);
                }
                sensorML.addMember(abstractProcess);
            } else {
                throw unsupportedMemberProcess(xbMember);
            }
        } else {
            throw new DecodingException(XmlHelper.getLocalName(xbMember), "The process of a member of the SensorML Document is null (%s)!", xbMember.getProcess());
        }
    }
    sensorML.setXml(xbSensorML.xmlText(getXmlOptions()));
    return sensorML;
}
Also used : AbstractProcessType(net.opengis.sensorML.x101.AbstractProcessType) AbstractComponentType(net.opengis.sensorML.x101.AbstractComponentType) AbstractDerivableComponentType(net.opengis.sensorML.x101.AbstractDerivableComponentType) ComponentType(net.opengis.sensorML.x101.ComponentType) AbstractProcess(org.n52.shetland.ogc.sensorML.AbstractProcess) SystemType(net.opengis.sensorML.x101.SystemType) DecodingException(org.n52.svalbard.decode.exception.DecodingException) SensorML(org.n52.shetland.ogc.sensorML.SensorML) AbstractSensorML(org.n52.shetland.ogc.sensorML.AbstractSensorML) Member(net.opengis.sensorML.x101.SensorMLDocument.SensorML.Member) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 4 with AbstractProcessType

use of net.opengis.sensorML.x101.AbstractProcessType 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

AbstractProcessType (net.opengis.sensorML.x101.AbstractProcessType)3 Member (net.opengis.sensorML.x101.SensorMLDocument.SensorML.Member)3 SensorMLDocument (net.opengis.sensorML.x101.SensorMLDocument)2 XmlObject (org.apache.xmlbeans.XmlObject)2 AbstractProcess (org.n52.shetland.ogc.sensorML.AbstractProcess)2 AbstractSensorML (org.n52.shetland.ogc.sensorML.AbstractSensorML)2 SensorML (org.n52.shetland.ogc.sensorML.SensorML)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 AbstractComponentType (net.opengis.sensorML.x101.AbstractComponentType)1 AbstractDerivableComponentType (net.opengis.sensorML.x101.AbstractDerivableComponentType)1 Capabilities (net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities)1 ComponentType (net.opengis.sensorML.x101.ComponentType)1 Components (net.opengis.sensorML.x101.ComponentsDocument.Components)1 ComponentList (net.opengis.sensorML.x101.ComponentsDocument.Components.ComponentList)1 Component (net.opengis.sensorML.x101.ComponentsDocument.Components.ComponentList.Component)1 ContactList (net.opengis.sensorML.x101.ContactListDocument.ContactList)1 SystemType (net.opengis.sensorML.x101.SystemType)1 SchemaType (org.apache.xmlbeans.SchemaType)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 XmlException (org.apache.xmlbeans.XmlException)1