Search in sources :

Example 1 with SweDataArrayValue

use of org.n52.shetland.ogc.om.values.SweDataArrayValue in project arctic-sea by 52North.

the class SweHelper method createSosSweDataArray.

/**
 * Create {@link SweDataArray} from {@link AbstractObservationValue}
 *
 * @param observationValue
 *            The {@link AbstractObservationValue} to create
 *            {@link SweDataArray} from
 *
 * @return Created {@link SweDataArray}
 *
 * @throws EncodingException
 *             If the service does not support the {@link SweDataArray}
 *             creation from {@link AbstractObservationValue}
 */
public SweDataArray createSosSweDataArray(AbstractObservationValue<?> observationValue) throws EncodingException {
    String observablePropertyIdentifier = observationValue.getObservableProperty();
    SweDataArrayValue dataArrayValue = new SweDataArrayValue();
    SweDataArray dataArray = new SweDataArray();
    dataArray.setEncoding(createTextEncoding(observationValue));
    dataArrayValue.setValue(dataArray);
    if (observationValue instanceof SingleObservationValue) {
        SingleObservationValue<?> singleValue = (SingleObservationValue<?>) observationValue;
        if (singleValue.getValue() instanceof SweDataArrayValue) {
            return (SweDataArray) singleValue.getValue().getValue();
        } else {
            dataArray.setElementType(createElementType(singleValue, observablePropertyIdentifier));
            dataArrayValue.addBlock(createBlock(dataArray.getElementType(), observationValue.getPhenomenonTime(), observablePropertyIdentifier, singleValue.getValue()));
        }
    } else if (observationValue instanceof MultiObservationValues) {
        MultiObservationValues<?> multiValue = (MultiObservationValues<?>) observationValue;
        if (multiValue.getValue() instanceof SweDataArrayValue) {
            return ((SweDataArrayValue) multiValue.getValue()).getValue();
        } else if (multiValue.getValue() instanceof TVPValue) {
            TVPValue tvpValues = (TVPValue) multiValue.getValue();
            for (TimeValuePair timeValuePair : tvpValues.getValue()) {
                if (timeValuePair != null && timeValuePair.getValue() != null && timeValuePair.getValue().isSetValue()) {
                    if (!dataArray.isSetElementTyp()) {
                        dataArray.setElementType(createElementType(timeValuePair, observablePropertyIdentifier));
                    }
                    List<String> newBlock = createBlock(dataArray.getElementType(), timeValuePair.getTime(), observablePropertyIdentifier, timeValuePair.getValue());
                    dataArrayValue.addBlock(newBlock);
                }
            }
        }
    }
    return dataArray;
}
Also used : SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) TVPValue(org.n52.shetland.ogc.om.values.TVPValue) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) SweDataArrayValue(org.n52.shetland.ogc.om.values.SweDataArrayValue) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Example 2 with SweDataArrayValue

use of org.n52.shetland.ogc.om.values.SweDataArrayValue in project arctic-sea by 52North.

the class SweHelper method createSosSweDataArray.

/**
 * Create {@link SweDataArray} from {@link OmObservation}
 *
 * @param sosObservation
 *            The {@link OmObservation} to create {@link SweDataArray} from
 *
 * @return Created {@link SweDataArray}
 *
 * @throws EncodingException
 *             If the service does not support the {@link SweDataArray}
 *             creation from value of {@link OmObservation}
 */
public SweDataArray createSosSweDataArray(OmObservation sosObservation) throws EncodingException {
    String observablePropertyIdentifier = sosObservation.getObservationConstellation().getObservableProperty().getIdentifier();
    SweDataArrayValue dataArrayValue = new SweDataArrayValue();
    SweDataArray dataArray = new SweDataArray();
    dataArray.setEncoding(createTextEncoding(sosObservation));
    dataArrayValue.setValue(dataArray);
    if (sosObservation.getValue() instanceof SingleObservationValue) {
        SingleObservationValue<?> singleValue = (SingleObservationValue<?>) sosObservation.getValue();
        if (singleValue.getValue() instanceof SweDataArrayValue) {
            return (SweDataArray) singleValue.getValue().getValue();
        } else {
            dataArray.setElementType(createElementType(singleValue, observablePropertyIdentifier));
            dataArrayValue.addBlock(createBlock(dataArray.getElementType(), sosObservation.getPhenomenonTime(), observablePropertyIdentifier, singleValue.getValue()));
        }
    } else if (sosObservation.getValue() instanceof MultiObservationValues) {
        MultiObservationValues<?> multiValue = (MultiObservationValues<?>) sosObservation.getValue();
        if (multiValue.getValue() instanceof SweDataArrayValue) {
            return ((SweDataArrayValue) multiValue.getValue()).getValue();
        } else if (multiValue.getValue() instanceof TVPValue) {
            TVPValue tvpValues = (TVPValue) multiValue.getValue();
            for (TimeValuePair timeValuePair : tvpValues.getValue()) {
                if (timeValuePair != null && timeValuePair.getValue() != null && timeValuePair.getValue().isSetValue()) {
                    if (!dataArray.isSetElementTyp()) {
                        dataArray.setElementType(createElementType(timeValuePair, observablePropertyIdentifier));
                    }
                    List<String> newBlock = createBlock(dataArray.getElementType(), timeValuePair.getTime(), observablePropertyIdentifier, timeValuePair.getValue());
                    dataArrayValue.addBlock(newBlock);
                }
            }
        }
    }
    return dataArray;
}
Also used : SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) TVPValue(org.n52.shetland.ogc.om.values.TVPValue) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) SweDataArrayValue(org.n52.shetland.ogc.om.values.SweDataArrayValue) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Example 3 with SweDataArrayValue

use of org.n52.shetland.ogc.om.values.SweDataArrayValue in project arctic-sea by 52North.

the class ObservationEncoder method encodeSweDataArrayValue.

private JsonNode encodeSweDataArrayValue(Value<?> value) throws EncodingException {
    SweDataArrayValue sweDataArrayValue = (SweDataArrayValue) value;
    ObjectNode result = nodeFactory().objectNode();
    ArrayNode jfields = result.putArray(JSONConstants.FIELDS);
    ArrayNode jvalues = result.putArray(JSONConstants.VALUES);
    List<SweField> fields = ((SweDataRecord) sweDataArrayValue.getValue().getElementType()).getFields();
    List<List<String>> values = sweDataArrayValue.getValue().getValues();
    TokenConverter[] conv = new TokenConverter[fields.size()];
    int i = 0;
    for (SweField field : fields) {
        try {
            conv[i++] = TokenConverter.forField(field);
        } catch (IllegalArgumentException e) {
            throw new UnsupportedEncoderInputException(this, field);
        }
        jfields.add(encodeObjectToJson(field));
    }
    for (List<String> block : values) {
        ArrayNode jblock = jvalues.addArray();
        i = 0;
        for (String token : block) {
            jblock.add(conv[i++].convert(token));
        }
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweDataArrayValue(org.n52.shetland.ogc.om.values.SweDataArrayValue) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) SweField(org.n52.shetland.ogc.swe.SweField) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) List(java.util.List) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 4 with SweDataArrayValue

use of org.n52.shetland.ogc.om.values.SweDataArrayValue in project arctic-sea by 52North.

the class OmDecoderv20 method getResult.

private ObservationValue<?> getResult(OMObservationType omObservation) throws DecodingException {
    XmlObject xbResult = omObservation.getResult();
    if (xbResult.schemaType() == XmlAnyTypeImpl.type) {
        // Template observation for InsertResultTemplate operation
        if (!xbResult.getDomNode().hasChildNodes()) {
            return new SingleObservationValue<>(new NilTemplateValue());
        } else {
            try {
                xbResult = XmlObject.Factory.parse(xbResult.xmlText().trim());
            } catch (XmlException e) {
                LOGGER.error("Error while parsing NamedValueValue", e);
            }
        }
    }
    if (xbResult.schemaType() == XmlBoolean.type) {
        // TruthObservation
        XmlBoolean xbBoolean = (XmlBoolean) xbResult;
        BooleanValue booleanValue = new BooleanValue(xbBoolean.getBooleanValue());
        return new SingleObservationValue<>(booleanValue);
    } else if (xbResult.schemaType() == XmlInteger.type) {
        // CountObservation
        XmlInteger xbInteger = (XmlInteger) xbResult;
        CountValue countValue = new CountValue(Integer.parseInt(xbInteger.getBigIntegerValue().toString()));
        return new SingleObservationValue<>(countValue);
    } else if (xbResult.schemaType() == XmlString.type) {
        // TextObservation
        XmlString xbString = (XmlString) xbResult;
        TextValue stringValue = new TextValue(xbString.getStringValue());
        return new SingleObservationValue<>(stringValue);
    } else {
        // result elements with other encoding like SWE_ARRAY_OBSERVATION
        Object decodedObject = decodeXmlObject(xbResult);
        if (decodedObject instanceof ObservationValue) {
            return (ObservationValue<?>) decodedObject;
        } else if (decodedObject instanceof GmlMeasureType) {
            GmlMeasureType measureType = (GmlMeasureType) decodedObject;
            QuantityValue quantitiyValue = new QuantityValue(measureType.getValue(), measureType.getUnit());
            return new SingleObservationValue<>(quantitiyValue);
        } else if (decodedObject instanceof ReferenceType) {
            if (omObservation.isSetType() && omObservation.getType().isSetHref() && omObservation.getType().getHref().equals(OmConstants.OBS_TYPE_REFERENCE_OBSERVATION)) {
                return new SingleObservationValue<>(new ReferenceValue((ReferenceType) decodedObject));
            }
            return new SingleObservationValue<>(new CategoryValue(((ReferenceType) decodedObject).getHref()));
        } else if (decodedObject instanceof Geometry) {
            return new SingleObservationValue<>(new GeometryValue((Geometry) decodedObject));
        } else if (decodedObject instanceof AbstractGeometry) {
            SingleObservationValue<Geometry> result = new SingleObservationValue<>();
            result.setValue(new GeometryValue(((AbstractGeometry) decodedObject).getGeometry()));
            return result;
        } else if (decodedObject instanceof SweDataArray) {
            return new SingleObservationValue<>(new SweDataArrayValue((SweDataArray) decodedObject));
        } else if (decodedObject instanceof SweDataRecord) {
            return new SingleObservationValue<>(new ComplexValue((SweDataRecord) decodedObject));
        }
        throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested result type '{}' is not supported by this service!", decodedObject.getClass().getSimpleName());
    }
}
Also used : AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) XmlBoolean(org.apache.xmlbeans.XmlBoolean) ReferenceValue(org.n52.shetland.ogc.om.values.ReferenceValue) XmlInteger(org.apache.xmlbeans.XmlInteger) DecodingException(org.n52.svalbard.decode.exception.DecodingException) ReferenceType(org.n52.shetland.ogc.gml.ReferenceType) SweDataArrayValue(org.n52.shetland.ogc.om.values.SweDataArrayValue) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) CountValue(org.n52.shetland.ogc.om.values.CountValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) ComplexValue(org.n52.shetland.ogc.om.values.ComplexValue) XmlString(org.apache.xmlbeans.XmlString) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) Geometry(org.locationtech.jts.geom.Geometry) AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) XmlException(org.apache.xmlbeans.XmlException) TextValue(org.n52.shetland.ogc.om.values.TextValue) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue) XmlObject(org.apache.xmlbeans.XmlObject) XmlObject(org.apache.xmlbeans.XmlObject) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) ObservationValue(org.n52.shetland.ogc.om.ObservationValue) NilTemplateValue(org.n52.shetland.ogc.om.values.NilTemplateValue) GmlMeasureType(org.n52.shetland.ogc.gml.GmlMeasureType)

Aggregations

SweDataArrayValue (org.n52.shetland.ogc.om.values.SweDataArrayValue)4 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)3 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)3 MultiObservationValues (org.n52.shetland.ogc.om.MultiObservationValues)2 TimeValuePair (org.n52.shetland.ogc.om.TimeValuePair)2 TVPValue (org.n52.shetland.ogc.om.values.TVPValue)2 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 List (java.util.List)1 XmlBoolean (org.apache.xmlbeans.XmlBoolean)1 XmlException (org.apache.xmlbeans.XmlException)1 XmlInteger (org.apache.xmlbeans.XmlInteger)1 XmlObject (org.apache.xmlbeans.XmlObject)1 XmlString (org.apache.xmlbeans.XmlString)1 Geometry (org.locationtech.jts.geom.Geometry)1 AbstractGeometry (org.n52.shetland.ogc.gml.AbstractGeometry)1 GmlMeasureType (org.n52.shetland.ogc.gml.GmlMeasureType)1 ReferenceType (org.n52.shetland.ogc.gml.ReferenceType)1 ObservationValue (org.n52.shetland.ogc.om.ObservationValue)1