Search in sources :

Example 1 with SweCount

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

the class FieldEncoder method encodeSweCountField.

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

Example 2 with SweCount

use of org.n52.shetland.ogc.swe.simpleType.SweCount 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 3 with SweCount

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

Example 4 with SweCount

use of org.n52.shetland.ogc.swe.simpleType.SweCount 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 5 with SweCount

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

the class OmEncoderv20Test method createComplexObservation.

protected OmObservation createComplexObservation() {
    DateTime now = new DateTime(DateTimeZone.UTC);
    TimeInstant resultTime = new TimeInstant(now);
    TimeInstant phenomenonTime = new TimeInstant(now);
    TimePeriod validTime = new TimePeriod(now.minusMinutes(5), now.plusMinutes(5));
    OmObservation observation = new OmObservation();
    OmObservationConstellation observationConstellation = new OmObservationConstellation();
    observationConstellation.setFeatureOfInterest(new SamplingFeature(new CodeWithAuthority("feature", CODE_SPACE)));
    OmCompositePhenomenon observableProperty = new OmCompositePhenomenon(PARENT_OBSERVABLE_PROPERTY);
    observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_1));
    observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_2));
    observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_3));
    observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_4));
    observationConstellation.setObservableProperty(observableProperty);
    observationConstellation.setObservationType(OmConstants.OBS_TYPE_COMPLEX_OBSERVATION);
    observationConstellation.addOffering(OFFERING);
    AbstractFeature procedure = new SosProcedureDescriptionUnknownType(PROCEDURE);
    // procedure.setIdentifier(new CodeWithAuthority(PROCEDURE, CODE_SPACE));
    observationConstellation.setProcedure(procedure);
    observation.setObservationConstellation(observationConstellation);
    observation.setParameter(null);
    observation.setResultTime(resultTime);
    observation.setTokenSeparator(TOKEN_SEPERATOR);
    observation.setTupleSeparator(TUPLE_SEPERATOR);
    observation.setValidTime(validTime);
    ComplexValue complexValue = new ComplexValue();
    SweDataRecord sweDataRecord = new SweDataRecord();
    SweQuantity sweQuantity = new SweQuantity();
    sweQuantity.setDefinition(CHILD_OBSERVABLE_PROPERTY_1);
    sweQuantity.setUom("unit");
    sweQuantity.setValue(42.0);
    sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_1_NAME, sweQuantity));
    SweBoolean sweBoolean = new SweBoolean();
    sweBoolean.setValue(Boolean.TRUE);
    sweBoolean.setDefinition(CHILD_OBSERVABLE_PROPERTY_2);
    sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_2_NAME, sweBoolean));
    SweCount sweCount = new SweCount();
    sweCount.setDefinition(CHILD_OBSERVABLE_PROPERTY_3);
    sweCount.setValue(42);
    sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_3_NAME, sweCount));
    SweText sweText = new SweText();
    sweText.setDefinition(CHILD_OBSERVABLE_PROPERTY_4);
    sweText.setValue("42");
    sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_4_NAME, sweText));
    SweCategory sweCategory = new SweCategory();
    sweCategory.setDefinition(CHILD_OBSERVABLE_PROPERTY_5);
    sweCategory.setCodeSpace(CODE_SPACE);
    sweCategory.setValue("52");
    sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_5_NAME, sweCategory));
    complexValue.setValue(sweDataRecord);
    observation.setValue(new SingleObservationValue<>(phenomenonTime, complexValue));
    return observation;
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) ComplexValue(org.n52.shetland.ogc.om.values.ComplexValue) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) OmCompositePhenomenon(org.n52.shetland.ogc.om.OmCompositePhenomenon) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) OmObservation(org.n52.shetland.ogc.om.OmObservation) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) DateTime(org.joda.time.DateTime) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) SosProcedureDescriptionUnknownType(org.n52.shetland.ogc.sos.SosProcedureDescriptionUnknownType) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty)

Aggregations

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