Search in sources :

Example 1 with Characteristics

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

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

the class SensorMLEncoderv101 method createCharacteristics.

/**
 * Creates the characteristics section of the SensorML description.
 *
 * @param smlCharacteristics
 *            SOS characteristics list
 *
 * @return XML Characteristics array
 *
 * @throws EncodingException
 *             If an error occurs
 */
private Characteristics[] createCharacteristics(final List<SmlCharacteristics> smlCharacteristics) throws EncodingException {
    final List<Characteristics> characteristicsList = Lists.newArrayListWithExpectedSize(smlCharacteristics.size());
    for (final SmlCharacteristics sosSMLCharacteristics : smlCharacteristics) {
        final Characteristics xbCharacteristics = Characteristics.Factory.newInstance(getXmlOptions());
        if (sosSMLCharacteristics.isSetName()) {
            xbCharacteristics.setName(sosSMLCharacteristics.getName());
        }
        if (sosSMLCharacteristics.isSetAbstractDataRecord()) {
            if (sosSMLCharacteristics.getDataRecord() instanceof SweSimpleDataRecord) {
                final SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) xbCharacteristics.addNewAbstractDataRecord().substitute(SweConstants.QN_SIMPLEDATARECORD_SWE_101, SimpleDataRecordType.type);
                if (sosSMLCharacteristics.isSetTypeDefinition()) {
                    xbSimpleDataRecord.setDefinition(sosSMLCharacteristics.getTypeDefinition());
                }
                if (sosSMLCharacteristics.getDataRecord().isSetFields()) {
                    for (final SweField field : sosSMLCharacteristics.getDataRecord().getFields()) {
                        final AnyScalarPropertyType xbField = xbSimpleDataRecord.addNewField();
                        xbField.setName(field.getName().getValue());
                        addSweSimpleTypeToField(xbField, field.getElement());
                    }
                }
            } else if (sosSMLCharacteristics.getDataRecord() instanceof SweDataRecord) {
                throw unsupportedCharacteristicsType(SweAggregateType.DataRecord);
            } else {
                throw unsupportedCharacteristicsType(sosSMLCharacteristics.getDataRecord().getClass().getName());
            }
        } else if (sosSMLCharacteristics.isSetHref()) {
            if (sosSMLCharacteristics.isSetName()) {
                xbCharacteristics.setName(sosSMLCharacteristics.getName());
            }
            xbCharacteristics.setHref(sosSMLCharacteristics.getHref());
            if (sosSMLCharacteristics.isSetTitle()) {
                xbCharacteristics.setTitle(sosSMLCharacteristics.getTitle());
            }
        }
        characteristicsList.add(xbCharacteristics);
    }
    return characteristicsList.toArray(new Characteristics[characteristicsList.size()]);
}
Also used : SmlCharacteristics(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristics) SweSimpleDataRecord(org.n52.shetland.ogc.swe.SweSimpleDataRecord) Characteristics(net.opengis.sensorML.x101.CharacteristicsDocument.Characteristics) SmlCharacteristics(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristics) SweField(org.n52.shetland.ogc.swe.SweField) AnyScalarPropertyType(net.opengis.swe.x101.AnyScalarPropertyType) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType)

Aggregations

Capabilities (net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities)1 Characteristics (net.opengis.sensorML.x101.CharacteristicsDocument.Characteristics)1 ContactList (net.opengis.sensorML.x101.ContactListDocument.ContactList)1 AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)1 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 XmlObject (org.apache.xmlbeans.XmlObject)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 SmlContactList (org.n52.shetland.ogc.sensorML.SmlContactList)1 SmlCapabilities (org.n52.shetland.ogc.sensorML.elements.SmlCapabilities)1 SmlCharacteristics (org.n52.shetland.ogc.sensorML.elements.SmlCharacteristics)1 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)1 SweField (org.n52.shetland.ogc.swe.SweField)1 SweSimpleDataRecord (org.n52.shetland.ogc.swe.SweSimpleDataRecord)1 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)1