Search in sources :

Example 1 with SweObservableProperty

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

the class SweCommonEncoderv101 method encode.

@Override
public XmlObject encode(Object element, EncodingContext context) throws EncodingException {
    XmlObject encodedObject = null;
    if (element instanceof SweAbstractSimpleType) {
        encodedObject = createSimpleType((SweAbstractSimpleType<?>) element, context);
    // }
    // if (element instanceof SweBoolean) {
    // encodedObject = createBoolean((SweBoolean) element);
    // } else if (element instanceof SweCategory) {
    // encodedObject = createCategory((SweCategory) element);
    // } else if (element instanceof SweCount) {
    // encodedObject = createCount((SweCount) element);
    // } else if (element instanceof SweObservableProperty) {
    // encodedObject = createObservableProperty((SweObservableProperty)
    // element);
    // } else if (element instanceof SweQuantity) {
    // encodedObject = createQuantity((SweQuantity) element);
    // } else if (element instanceof SweQuantityRange) {
    // encodedObject = createQuantityRange((SweQuantityRange) element);
    // } else if (element instanceof SweText) {
    // encodedObject = createText((SweText) element);
    // } else if (element instanceof SweTime) {
    // encodedObject = createTime((SweTime) element);
    // } else if (element instanceof SweTimeRange) {
    // encodedObject = createTimeRange((SweTimeRange) element);
    } else if (element instanceof SweCoordinate) {
        encodedObject = createCoordinate((SweCoordinate<?>) element);
    } else if (element instanceof SweDataArray) {
        encodedObject = createDataArray((SweDataArray) element);
    } else if (element instanceof SweDataRecord) {
        DataRecordType drt = createDataRecord((SweDataRecord) element);
        if (context.has(XmlBeansEncodingFlags.DOCUMENT)) {
            DataRecordDocument drd = DataRecordDocument.Factory.newInstance(getXmlOptions());
            drd.setDataRecord(drt);
            encodedObject = drd;
        } else {
            encodedObject = drt;
        }
    } else if (element instanceof SweEnvelope) {
        encodedObject = createEnvelope((SweEnvelope) element);
    } else if (element instanceof SweSimpleDataRecord) {
        encodedObject = createSimpleDataRecord((SweSimpleDataRecord) element);
    } else if (element instanceof TimePeriod) {
        encodedObject = createTimeGeometricPrimitivePropertyType((TimePeriod) element);
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    XmlHelper.validateDocument(encodedObject, EncodingException::new);
    return encodedObject;
}
Also used : DataRecordType(net.opengis.swe.x101.DataRecordType) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) SweSimpleDataRecord(org.n52.shetland.ogc.swe.SweSimpleDataRecord) SweAbstractSimpleType(org.n52.shetland.ogc.swe.simpleType.SweAbstractSimpleType) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) EncodingException(org.n52.svalbard.encode.exception.EncodingException) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) XmlObject(org.apache.xmlbeans.XmlObject) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) DataRecordDocument(net.opengis.swe.x101.DataRecordDocument) SweCoordinate(org.n52.shetland.ogc.swe.SweCoordinate) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 2 with SweObservableProperty

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

the class SweHelper method createBlock.

@SuppressFBWarnings("BC_VACUOUS_INSTANCEOF")
private List<String> createBlock(SweAbstractDataComponent elementType, Time phenomenonTime, String phenID, Value<?> value) {
    if (elementType instanceof SweDataRecord) {
        SweDataRecord elementTypeRecord = (SweDataRecord) elementType;
        List<String> block = new ArrayList<>(elementTypeRecord.getFields().size());
        if (!(value instanceof NilTemplateValue)) {
            elementTypeRecord.getFields().forEach(field -> {
                if (field.getElement() instanceof SweTime || field.getElement() instanceof SweTimeRange) {
                    block.add(DateTimeHelper.format(phenomenonTime));
                } else if (field.getElement() instanceof SweAbstractDataComponent && field.getElement().getDefinition().equals(phenID)) {
                    block.add(value.getValue().toString());
                } else if (field.getElement() instanceof SweObservableProperty) {
                    block.add(phenID);
                }
            });
        }
        return block;
    }
    String exceptionMsg = String.format("Type of ElementType is not supported: %s", elementType != null ? elementType.getClass().getName() : "null");
    LOGGER.debug(exceptionMsg);
    throw new IllegalArgumentException(exceptionMsg);
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) ArrayList(java.util.ArrayList) NilTemplateValue(org.n52.shetland.ogc.om.values.NilTemplateValue) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) SweObservableProperty(org.n52.shetland.ogc.swe.simpleType.SweObservableProperty) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with SweObservableProperty

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

the class FieldDecoderTest method testObservablePropertyWithValue.

@Test
public void testObservablePropertyWithValue() throws DecodingException {
    ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.OBSERVABLE_PROPERTY_TYPE).put(JSONConstants.VALUE, OBSERVED_PROPERTY_VALUE);
    SweField field = checkCommon(json, true);
    assertThat(field.getElement(), is(instanceOf(SweObservableProperty.class)));
    SweObservableProperty swe = (SweObservableProperty) field.getElement();
    errors.checkThat(swe.getValue(), is(OBSERVED_PROPERTY_VALUE));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweField(org.n52.shetland.ogc.swe.SweField) SweObservableProperty(org.n52.shetland.ogc.swe.simpleType.SweObservableProperty) Test(org.junit.Test)

Example 4 with SweObservableProperty

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

the class FieldDecoderTest method testObservableProperty.

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

Example 5 with SweObservableProperty

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

the class FieldEncoder method encodeSweObservableProperyField.

private ObjectNode encodeSweObservableProperyField(SweField field) {
    ObjectNode jfield = createField(field);
    jfield.put(JSONConstants.TYPE, JSONConstants.OBSERVABLE_PROPERTY_TYPE);
    SweObservableProperty sweObservableProperty = (SweObservableProperty) field.getElement();
    if (sweObservableProperty.isSetValue()) {
        jfield.put(JSONConstants.VALUE, sweObservableProperty.getValue());
    }
    return jfield;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweObservableProperty(org.n52.shetland.ogc.swe.simpleType.SweObservableProperty)

Aggregations

SweObservableProperty (org.n52.shetland.ogc.swe.simpleType.SweObservableProperty)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Test (org.junit.Test)2 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)2 SweField (org.n52.shetland.ogc.swe.SweField)2 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)2 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)2 NotYetSupportedEncodingException (org.n52.svalbard.encode.exception.NotYetSupportedEncodingException)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ArrayList (java.util.ArrayList)1 AbstractDataComponentType (net.opengis.swe.x101.AbstractDataComponentType)1 DataRecordDocument (net.opengis.swe.x101.DataRecordDocument)1 DataRecordType (net.opengis.swe.x101.DataRecordType)1 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)1 XmlObject (org.apache.xmlbeans.XmlObject)1 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)1 NilTemplateValue (org.n52.shetland.ogc.om.values.NilTemplateValue)1 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)1 SweCoordinate (org.n52.shetland.ogc.swe.SweCoordinate)1 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)1