Search in sources :

Example 36 with Value

use of org.n52.shetland.ogc.om.values.Value 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 37 with Value

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

the class ObservationEncoder method encodeReferenceValue.

private JsonNode encodeReferenceValue(ReferenceValue value) {
    ReferenceType ref = value.getValue();
    ObjectNode node = nodeFactory().objectNode();
    node.put(JSONConstants.HREF, ref.getHref());
    if (ref.isSetRole()) {
        node.put(JSONConstants.ROLE, ref.getRole());
    }
    if (ref.isSetTitle()) {
        node.put(JSONConstants.TITLE, ref.getTitle());
    }
    return node;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ReferenceType(org.n52.shetland.ogc.gml.ReferenceType)

Example 38 with Value

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

the class ObservationEncoder method encodeQualityValue.

private JsonNode encodeQualityValue(Value<?> value) {
    QuantityValue quantityValue = (QuantityValue) value;
    ObjectNode node = nodeFactory().objectNode();
    node.put(JSONConstants.UOM, quantityValue.getUnit());
    node.put(JSONConstants.VALUE, quantityValue.getValue());
    return node;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue)

Example 39 with Value

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

the class ObservationEncoder method encodeComplexValue.

private JsonNode encodeComplexValue(Value<?> value) throws EncodingException {
    ArrayNode result = nodeFactory().arrayNode();
    ComplexValue complexValue = (ComplexValue) value;
    SweAbstractDataRecord sweDataRecord = complexValue.getValue();
    for (SweField field : sweDataRecord.getFields()) {
        result.add(encodeObjectToJson(field));
    }
    return result;
}
Also used : ComplexValue(org.n52.shetland.ogc.om.values.ComplexValue) SweAbstractDataRecord(org.n52.shetland.ogc.swe.SweAbstractDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 40 with Value

use of org.n52.shetland.ogc.om.values.Value 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)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)28 Test (org.junit.Test)27 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)20 IoParameters (org.n52.io.request.IoParameters)19 SweField (org.n52.shetland.ogc.swe.SweField)16 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)13 QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)13 RequestSimpleParameterSet (org.n52.io.request.RequestSimpleParameterSet)12 List (java.util.List)9 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)9 AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)7 CategoryValue (org.n52.shetland.ogc.om.values.CategoryValue)7 CountValue (org.n52.shetland.ogc.om.values.CountValue)7 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)7 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)7 DecodingException (org.n52.svalbard.decode.exception.DecodingException)7 DateTime (org.joda.time.DateTime)6 ModelAndView (org.springframework.web.servlet.ModelAndView)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 ArrayList (java.util.ArrayList)5