Search in sources :

Example 71 with SweField

use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldTime.

@Test
public void should_encode_Datarecord_with_fieldTime() throws EncodingException {
    final String field1Name = "test-name";
    final DateTime field1Value = new DateTime(System.currentTimeMillis());
    final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweTime().setValue(field1Value))));
    assertThat(encode, is(instanceOf(DataRecordType.class)));
    final DataRecordType xbDataRecord = (DataRecordType) encode;
    final DataComponentPropertyType field1 = xbDataRecord.getFieldArray(0);
    assertThat(xbDataRecord.getFieldArray().length, is(1));
    assertThat(field1.isSetTime(), is(TRUE));
    assertThat(field1.getName(), is(field1Name));
    final DateTime xbTime = new DateTime(((XmlCalendar) field1.getTime().getValue()).getTimeInMillis(), DateTimeZone.UTC);
    assertThat(xbTime.toDateTime(field1Value.getZone()), is(field1Value));
}
Also used : SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) DataRecordType(net.opengis.swe.x101.DataRecordType) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) XmlObject(org.apache.xmlbeans.XmlObject) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 72 with SweField

use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_encode_simpleDatarecord_with_fieldQuantity.

@Test
public void should_encode_simpleDatarecord_with_fieldQuantity() throws EncodingException {
    final String name = "field-1";
    final double value = 42.5;
    final XmlObject encode = sweCommonEncoderv101.encode(new SweSimpleDataRecord().addField(new SweField(name, new SweQuantity().setValue(value))));
    assertThat(encode, instanceOf(SimpleDataRecordType.class));
    final SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) encode;
    final AnyScalarPropertyType field1 = xbSimpleDataRecord.getFieldArray(0);
    assertThat(xbSimpleDataRecord.getFieldArray().length, is(1));
    assertThat(field1.getName(), is(name));
    assertThat(field1.isSetQuantity(), is(TRUE));
    assertThat(field1.getQuantity().getValue(), is(value));
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweSimpleDataRecord(org.n52.shetland.ogc.swe.SweSimpleDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) AnyScalarPropertyType(net.opengis.swe.x101.AnyScalarPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) Test(org.junit.Test)

Example 73 with SweField

use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_encode_simpleDataRecordWithFields.

@Test
public void should_encode_simpleDataRecordWithFields() throws EncodingException {
    final String field0Value = "field-0-value";
    final String field0Name = "field-0";
    final String field1Name = "field-1";
    final Boolean field1Value = Boolean.TRUE;
    final XmlObject encode = sweCommonEncoderv101.encode(new SweSimpleDataRecord().addField(new SweField(field0Name, new SweText().setValue(field0Value))).addField(new SweField(field1Name, new SweBoolean().setValue(field1Value))));
    assertThat(encode, instanceOf(SimpleDataRecordType.class));
    final SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) encode;
    final AnyScalarPropertyType field0 = xbSimpleDataRecord.getFieldArray(0);
    final AnyScalarPropertyType field1 = xbSimpleDataRecord.getFieldArray(1);
    assertThat(xbSimpleDataRecord.getFieldArray().length, is(2));
    assertThat(field0.isSetText(), is(TRUE));
    assertThat(field0.getName(), is(field0Name));
    assertThat(field0.getText().getValue(), is(field0Value));
    assertThat(field1.isSetBoolean(), is(TRUE));
    assertThat(field1.getName(), is(field1Name));
    assertThat(field1.getBoolean().getValue(), is(field1Value));
}
Also used : SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweSimpleDataRecord(org.n52.shetland.ogc.swe.SweSimpleDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) AnyScalarPropertyType(net.opengis.swe.x101.AnyScalarPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) Test(org.junit.Test)

Example 74 with SweField

use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.

the class SweCommonEncoderv101 method createField.

private DataComponentPropertyType createField(SweField sweField) throws EncodingException {
    SweAbstractDataComponent sosElement = sweField.getElement();
    DataComponentPropertyType xbField = DataComponentPropertyType.Factory.newInstance(getXmlOptions());
    if (sweField.isSetName()) {
        xbField.setName(sweField.getName().getValue());
    }
    if (sosElement instanceof SweBoolean) {
        xbField.addNewBoolean().set(createSimpleType((SweBoolean) sosElement));
    } else if (sosElement instanceof SweCategory) {
        xbField.addNewCategory().set(createSimpleType((SweCategory) sosElement));
    } else if (sosElement instanceof SweCount) {
        xbField.addNewCount().set(createSimpleType((SweCount) sosElement));
    } else if (sosElement instanceof SweCountRange) {
        xbField.addNewCount().set(createSimpleType((SweCountRange) sosElement));
    } else if (sosElement instanceof SweQuantity) {
        xbField.addNewQuantity().set(createSimpleType((SweQuantity) sosElement));
    } else if (sosElement instanceof SweQuantityRange) {
        xbField.addNewQuantity().set(createSimpleType((SweQuantityRange) sosElement));
    } else if (sosElement instanceof SweText) {
        xbField.addNewText().set(createSimpleType((SweText) sosElement));
    } else if (sosElement instanceof SweTimeRange) {
        xbField.addNewTimeRange().set(createSimpleType((SweTimeRange) sosElement));
    } else if (sosElement instanceof SweTime) {
        xbField.addNewTime().set(createSimpleType((SweTime) sosElement));
    } else if (sosElement instanceof SweEnvelope) {
        EnvelopeType xbEnvelope = (EnvelopeType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_ENVELOPE_SWE_101, EnvelopeType.type);
        xbEnvelope.set(createEnvelope((SweEnvelope) sosElement));
    } else if (sosElement instanceof SweDataRecord) {
        DataRecordType xbEnvelope = (DataRecordType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataRecordType.type);
        xbEnvelope.set(createDataRecord((SweDataRecord) sosElement));
    } else if (sosElement instanceof SweDataArray) {
        DataArrayType xbEnvelope = (DataArrayType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataArrayType.type);
        xbEnvelope.set(createDataArray((SweDataArray) sosElement).getDataArray1());
    } else {
        throw new EncodingException("The element type '%s' of the received '%s' is not supported by this encoder '%s'.", new Object[] { sosElement != null ? sosElement.getClass().getName() : null, sweField.getClass().getName(), getClass().getName() });
    }
    return xbField;
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) DataRecordType(net.opengis.swe.x101.DataRecordType) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) EnvelopeType(net.opengis.swe.x101.EnvelopeType) EncodingException(org.n52.svalbard.encode.exception.EncodingException) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) SweCountRange(org.n52.shetland.ogc.swe.simpleType.SweCountRange) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) DataArrayType(net.opengis.swe.x101.DataArrayType)

Example 75 with SweField

use of org.n52.shetland.ogc.swe.SweField 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

SweField (org.n52.shetland.ogc.swe.SweField)59 Test (org.junit.Test)42 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)34 XmlObject (org.apache.xmlbeans.XmlObject)20 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)19 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)19 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)12 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)12 AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)11 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)11 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)11 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)10 SweSimpleDataRecord (org.n52.shetland.ogc.swe.SweSimpleDataRecord)10 DataComponentPropertyType (net.opengis.swe.x101.DataComponentPropertyType)9 DataRecordType (net.opengis.swe.x101.DataRecordType)9 SweCategory (org.n52.shetland.ogc.swe.simpleType.SweCategory)9 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)9 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)8 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)7 DateTime (org.joda.time.DateTime)4