Search in sources :

Example 1 with SweCategory

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

the class FieldDecoderTest method testCategory.

@Test
public void testCategory() throws DecodingException {
    ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.CATEGORY_TYPE).put(JSONConstants.CODESPACE, CODESPACE);
    SweField field = checkCommon(json, false);
    assertThat(field.getElement(), is(instanceOf(SweCategory.class)));
    SweCategory swe = (SweCategory) field.getElement();
    errors.checkThat(swe.getValue(), is(nullValue()));
    errors.checkThat(swe.getCodeSpace(), is(CODESPACE));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweField(org.n52.shetland.ogc.swe.SweField) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) Test(org.junit.Test)

Example 2 with SweCategory

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

the class FieldEncoder method encodeSweCategoryField.

private ObjectNode encodeSweCategoryField(SweField field) {
    ObjectNode jfield = createField(field);
    jfield.put(JSONConstants.TYPE, JSONConstants.CATEGORY_TYPE);
    SweCategory sweCategory = (SweCategory) field.getElement();
    jfield.put(JSONConstants.CODESPACE, sweCategory.getCodeSpace());
    if (sweCategory.isSetValue()) {
        jfield.put(JSONConstants.VALUE, sweCategory.getValue());
    }
    return jfield;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory)

Example 3 with SweCategory

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

the class ObservationEncoder method getFieldForValue.

private SweField getFieldForValue(String phenomenon, Value<?> value) throws EncodingException {
    final SweAbstractDataComponent def;
    if (value instanceof BooleanValue) {
        def = new SweBoolean();
    } else if (value instanceof CategoryValue) {
        SweCategory sweCategory = new SweCategory();
        CategoryValue categoryValue = (CategoryValue) value;
        sweCategory.setCodeSpace(categoryValue.getUnit());
        def = sweCategory;
    } else if (value instanceof CountValue) {
        def = new SweCount();
    } else if (value instanceof QuantityValue) {
        SweQuantity sweQuantity = new SweQuantity();
        QuantityValue quantityValue = (QuantityValue) value;
        sweQuantity.setUom(quantityValue.getUnit());
        def = sweQuantity;
    } else if (value instanceof TextValue) {
        def = new SweText();
    } else if (value instanceof NilTemplateValue) {
        def = new SweText();
    } else if (value instanceof BooleanValue) {
        def = new SweBoolean();
    } else if (value instanceof GeometryValue) {
        def = new SweText();
    } else {
        throw new UnsupportedEncoderInputException(this, value);
    }
    def.setDefinition(phenomenon);
    return new SweField(phenomenon, def);
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) CountValue(org.n52.shetland.ogc.om.values.CountValue) SweField(org.n52.shetland.ogc.swe.SweField) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) TextValue(org.n52.shetland.ogc.om.values.TextValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) NilTemplateValue(org.n52.shetland.ogc.om.values.NilTemplateValue)

Example 4 with SweCategory

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

the class SweCommonEncoderv101 method createQuality.

private QualityPropertyType[] createQuality(Collection<SweQuality> quality) {
    if (!quality.isEmpty()) {
        ArrayList<QualityPropertyType> xbQualities = Lists.newArrayListWithCapacity(quality.size());
        for (SweQuality sweQuality : quality) {
            QualityPropertyType xbQuality = QualityPropertyType.Factory.newInstance();
            if (sweQuality instanceof SweText) {
                xbQuality.addNewText().set(createText((SweText) sweQuality));
            } else if (sweQuality instanceof SweCategory) {
                xbQuality.addNewCategory().set(createCategory((SweCategory) sweQuality));
            } else if (sweQuality instanceof SweQuantity) {
                xbQuality.addNewQuantity().set(createQuantity((SweQuantity) sweQuality));
            } else if (sweQuality instanceof SweQuantityRange) {
                xbQuality.addNewQuantityRange().set(createQuantityRange((SweQuantityRange) sweQuality));
            }
            xbQualities.add(xbQuality);
        }
        return xbQualities.toArray(new QualityPropertyType[xbQualities.size()]);
    }
    return new QualityPropertyType[] { QualityPropertyType.Factory.newInstance() };
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweQuality(org.n52.shetland.ogc.swe.simpleType.SweQuality) QualityPropertyType(net.opengis.swe.x101.QualityPropertyType) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory)

Example 5 with SweCategory

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

the class SweCommonEncoderv101 method createFieldForSimpleDataRecord.

private AnyScalarPropertyType createFieldForSimpleDataRecord(SweField sweField) throws EncodingException {
    SweAbstractDataComponent sosElement = sweField.getElement();
    AnyScalarPropertyType xbField = AnyScalarPropertyType.Factory.newInstance(getXmlOptions());
    if (sweField.isSetName()) {
        xbField.setName(sweField.getName().getValue());
    }
    AbstractDataComponentType xbDCD;
    if (sosElement instanceof SweBoolean) {
        xbDCD = xbField.addNewBoolean();
        xbDCD.set(createSimpleType((SweBoolean) sosElement));
    } else if (sosElement instanceof SweCategory) {
        xbDCD = xbField.addNewCategory();
        xbDCD.set(createSimpleType((SweCategory) sosElement));
    } else if (sosElement instanceof SweCount) {
        xbDCD = xbField.addNewCount();
        xbDCD.set(createSimpleType((SweCount) sosElement));
    } else if (sosElement instanceof SweQuantity) {
        xbDCD = xbField.addNewQuantity();
        xbDCD.set(createSimpleType((SweQuantity) sosElement));
    } else if (sosElement instanceof SweText) {
        xbDCD = xbField.addNewText();
        xbDCD.set(createSimpleType((SweText) sosElement));
    } else if (sosElement instanceof SweTime) {
        xbDCD = xbField.addNewTime();
        xbDCD.set(createSimpleType((SweTime) sosElement));
    } 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) AbstractDataComponentType(net.opengis.swe.x101.AbstractDataComponentType) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) AnyScalarPropertyType(net.opengis.swe.x101.AnyScalarPropertyType) EncodingException(org.n52.svalbard.encode.exception.EncodingException) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) XmlObject(org.apache.xmlbeans.XmlObject) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean)

Aggregations

SweCategory (org.n52.shetland.ogc.swe.simpleType.SweCategory)18 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)10 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)9 XmlObject (org.apache.xmlbeans.XmlObject)8 Test (org.junit.Test)8 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)8 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)7 SweField (org.n52.shetland.ogc.swe.SweField)6 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)5 NotYetSupportedEncodingException (org.n52.svalbard.encode.exception.NotYetSupportedEncodingException)5 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)4 SweQuantityRange (org.n52.shetland.ogc.swe.simpleType.SweQuantityRange)4 EncodingException (org.n52.svalbard.encode.exception.EncodingException)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 DataComponentPropertyType (net.opengis.swe.x101.DataComponentPropertyType)3 DataRecordType (net.opengis.swe.x101.DataRecordType)3 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)3 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)3 BigDecimal (java.math.BigDecimal)2 AbstractDataComponentType (net.opengis.swe.x101.AbstractDataComponentType)2