Search in sources :

Example 1 with Count

use of net.opengis.swe.x101.CountDocument.Count in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_encode_count_with_quality_Quantity.

@Test
public void should_encode_count_with_quality_Quantity() throws EncodingException {
    final double qualityQuantityValue = 42.0;
    final SweCount sosCount = (SweCount) new SweCount().setQuality(Lists.newArrayList((SweQuality) new SweQuantity().setValue(qualityQuantityValue)));
    final XmlObject encode = sweCommonEncoderv101.encode(sosCount);
    assertThat(encode, instanceOf(Count.class));
    final Count xbCount = (Count) encode;
    assertThat(xbCount.getQualityArray(), is(not(nullValue())));
    assertThat(xbCount.getQualityArray().length, is(1));
    assertThat(xbCount.getQualityArray(0).isSetQuantity(), is(true));
    assertThat(xbCount.getQualityArray(0).getQuantity().getValue(), is(qualityQuantityValue));
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) XmlObject(org.apache.xmlbeans.XmlObject) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) Count(net.opengis.swe.x101.CountDocument.Count) Test(org.junit.Test)

Example 2 with Count

use of net.opengis.swe.x101.CountDocument.Count in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_encode_count_with_quality_Category.

@Test
public void should_encode_count_with_quality_Category() throws EncodingException {
    final String qualityCategoryValue = "quality-category-value";
    final SweCount sosCount = (SweCount) new SweCount().setQuality(Lists.newArrayList((SweQuality) new SweCategory().setValue(qualityCategoryValue)));
    final XmlObject encode = sweCommonEncoderv101.encode(sosCount);
    assertThat(encode, instanceOf(Count.class));
    final Count xbCount = (Count) encode;
    assertThat(xbCount.getQualityArray(), is(not(nullValue())));
    assertThat(xbCount.getQualityArray().length, is(1));
    assertThat(xbCount.getQualityArray(0).isSetCategory(), is(true));
    assertThat(xbCount.getQualityArray(0).getCategory().getValue(), is(qualityCategoryValue));
}
Also used : SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) XmlObject(org.apache.xmlbeans.XmlObject) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) Count(net.opengis.swe.x101.CountDocument.Count) Test(org.junit.Test)

Example 3 with Count

use of net.opengis.swe.x101.CountDocument.Count in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_encode_count_with_quality_QuantityRange.

@Test
public void should_encode_count_with_quality_QuantityRange() throws EncodingException {
    final RangeValue<BigDecimal> qualityQuantityRangeValue = new RangeValue<>(BigDecimal.valueOf(1.0), BigDecimal.valueOf(2.0));
    final SweCount sosCount = (SweCount) new SweCount().setQuality(Lists.newArrayList((SweQuality) new SweQuantityRange().setValue(qualityQuantityRangeValue)));
    final XmlObject encode = sweCommonEncoderv101.encode(sosCount);
    assertThat(encode, instanceOf(Count.class));
    final Count xbCount = (Count) encode;
    assertThat(xbCount.getQualityArray(), is(not(nullValue())));
    assertThat(xbCount.getQualityArray().length, is(1));
    assertThat(xbCount.getQualityArray(0).isSetQuantityRange(), is(true));
    assertThat(BigDecimal.valueOf((Double) xbCount.getQualityArray(0).getQuantityRange().getValue().get(0)), is(qualityQuantityRangeValue.getRangeStart()));
    assertThat(BigDecimal.valueOf((Double) xbCount.getQualityArray(0).getQuantityRange().getValue().get(1)), is(qualityQuantityRangeValue.getRangeEnd()));
}
Also used : SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) XmlObject(org.apache.xmlbeans.XmlObject) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) Count(net.opengis.swe.x101.CountDocument.Count) BigDecimal(java.math.BigDecimal) RangeValue(org.n52.shetland.ogc.swe.RangeValue) Test(org.junit.Test)

Example 4 with Count

use of net.opengis.swe.x101.CountDocument.Count in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_encode_count_with_quality_text.

@Test
public void should_encode_count_with_quality_text() throws EncodingException {
    final String qualityTextValue = "quality-text-value";
    final SweCount sosCount = (SweCount) new SweCount().setQuality(Lists.newArrayList((SweQuality) new SweText().setValue(qualityTextValue)));
    final XmlObject encode = sweCommonEncoderv101.encode(sosCount);
    assertThat(encode, instanceOf(Count.class));
    final Count xbCount = (Count) encode;
    assertThat(xbCount.getQualityArray(), is(not(nullValue())));
    assertThat(xbCount.getQualityArray().length, is(1));
    assertThat(xbCount.getQualityArray(0).isSetText(), is(true));
    assertThat(xbCount.getQualityArray(0).getText().getValue(), is(qualityTextValue));
}
Also used : SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) XmlObject(org.apache.xmlbeans.XmlObject) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) Count(net.opengis.swe.x101.CountDocument.Count) Test(org.junit.Test)

Example 5 with Count

use of net.opengis.swe.x101.CountDocument.Count in project arctic-sea by 52North.

the class SweCommonEncoderv101 method createDataArray.

private DataArrayDocument createDataArray(SweDataArray sosDataArray) throws EncodingException {
    if (sosDataArray != null) {
        if (sosDataArray.isSetElementTyp()) {
            DataArrayDocument xbDataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
            DataArrayType xbDataArray = xbDataArrayDoc.addNewDataArray1();
            // set element count
            if (sosDataArray.isSetElementCount()) {
                xbDataArray.addNewElementCount().addNewCount().set(createCount(sosDataArray.getElementCount()));
            }
            if (sosDataArray.isSetElementTyp()) {
                DataComponentPropertyType xbElementType = xbDataArray.addNewElementType();
                xbElementType.setName("Components");
                // FIXME use visitor pattern
                if (sosDataArray.getElementType() instanceof SweBoolean) {
                    xbElementType.addNewBoolean().set(createSimpleType((SweBoolean) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweCategory) {
                    xbElementType.addNewCategory().set(createSimpleType((SweCategory) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweCount) {
                    xbElementType.addNewCount().set(createSimpleType((SweCount) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweQuantity) {
                    xbElementType.addNewQuantity().set(createSimpleType((SweQuantity) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweText) {
                    xbElementType.addNewText().set(createSimpleType((SweText) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweTimeRange) {
                    xbElementType.addNewTimeRange().set(createSimpleType((SweTimeRange) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweTime) {
                    xbElementType.addNewTime().set(createSimpleType((SweTime) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweEnvelope) {
                    xbElementType.addNewAbstractDataRecord().set(createEnvelope((SweEnvelope) sosDataArray.getElementType()));
                    xbElementType.getAbstractDataRecord().substitute(SweConstants.QN_ENVELOPE_SWE_101, EnvelopeType.type);
                } else if (sosDataArray.getElementType() instanceof SweDataRecord) {
                    xbElementType.addNewAbstractDataRecord().set(createDataRecord((SweDataRecord) sosDataArray.getElementType()));
                    xbElementType.getAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataRecordType.type);
                } else if (sosDataArray.getElementType() instanceof SweDataArray) {
                    xbElementType.addNewAbstractDataArray1().set(createDataArray((SweDataArray) sosDataArray.getElementType()).getDataArray1());
                    xbElementType.getAbstractDataArray1().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataArrayType.type);
                } else {
                    throw new UnsupportedEncoderInputException(this, sosDataArray.getElementType());
                }
            }
            if (sosDataArray.isSetEncoding()) {
                BlockEncodingPropertyType xbEncoding = xbDataArray.addNewEncoding();
                xbEncoding.set(createBlockEncoding(sosDataArray.getEncoding()));
            // xbDataArray.getEncoding().substitute(
            // new QName(SWEConstants.NS_SWE_101,
            // SWEConstants.EN_TEXT_ENCODING,
            // SWEConstants.NS_SWE_PREFIX), TextBlock.type);
            }
            // }
            if (sosDataArray.isSetValues()) {
                xbDataArray.addNewValues().set(createValues(sosDataArray.getValues(), sosDataArray.getEncoding()));
            }
            return xbDataArrayDoc;
        } else if (sosDataArray.isSetXml()) {
            try {
                XmlObject xmlObject = XmlObject.Factory.parse(sosDataArray.getXml().trim());
                if (xmlObject instanceof DataArrayDocument) {
                    return (DataArrayDocument) xmlObject;
                } else {
                    DataArrayDocument xbDataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
                    xbDataArrayDoc.setDataArray1(DataArrayType.Factory.parse(sosDataArray.getXml().trim()));
                    return xbDataArrayDoc;
                }
            } catch (XmlException e) {
                throw new EncodingException("Error while encoding SweDataArray!", e);
            }
        }
    }
    return null;
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) BlockEncodingPropertyType(net.opengis.swe.x101.BlockEncodingPropertyType) EncodingException(org.n52.svalbard.encode.exception.EncodingException) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) 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) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) XmlException(org.apache.xmlbeans.XmlException) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) DataArrayDocument(net.opengis.swe.x101.DataArrayDocument) DataArrayType(net.opengis.swe.x101.DataArrayType)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)5 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)5 Count (net.opengis.swe.x101.CountDocument.Count)4 Test (org.junit.Test)4 SweCategory (org.n52.shetland.ogc.swe.simpleType.SweCategory)2 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)2 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)2 BigDecimal (java.math.BigDecimal)1 BlockEncodingPropertyType (net.opengis.swe.x101.BlockEncodingPropertyType)1 DataArrayDocument (net.opengis.swe.x101.DataArrayDocument)1 DataArrayType (net.opengis.swe.x101.DataArrayType)1 DataComponentPropertyType (net.opengis.swe.x101.DataComponentPropertyType)1 XmlException (org.apache.xmlbeans.XmlException)1 RangeValue (org.n52.shetland.ogc.swe.RangeValue)1 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)1 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)1 SweEnvelope (org.n52.shetland.ogc.swe.SweEnvelope)1 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)1 SweQuantityRange (org.n52.shetland.ogc.swe.simpleType.SweQuantityRange)1 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)1