Search in sources :

Example 1 with UnsupportedEncoderInputException

use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.

the class ExiEncoder method encode.

@Override
public EXIObject<XmlObject> encode(T response) throws EncodingException {
    Encoder<Object, T> encoder = getEncoder(response);
    Object encode = encoder.encode(response);
    if (encode != null && encode instanceof XmlObject) {
        return new EXIObject<XmlObject>((XmlObject) encode);
    } else {
        throw new UnsupportedEncoderInputException(encoder, response);
    }
}
Also used : EXIObject(org.n52.shetland.exi.EXIObject) EXIObject(org.n52.shetland.exi.EXIObject) XmlObject(org.apache.xmlbeans.XmlObject) XmlObject(org.apache.xmlbeans.XmlObject) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 2 with UnsupportedEncoderInputException

use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException 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 3 with UnsupportedEncoderInputException

use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException 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 UnsupportedEncoderInputException

use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.

the class AbstractOmEncoderv20 method encode.

@Override
public XmlObject encode(Object element, EncodingContext additionalValues) throws EncodingException {
    XmlObject encodedObject = null;
    if (element instanceof OmObservation) {
        encodedObject = encodeOmObservation((OmObservation) element, additionalValues);
    } else if (element instanceof NamedValue) {
        NamedValueType nvt = createNamedValue((NamedValue<?>) element);
        if (additionalValues.has(XmlBeansEncodingFlags.DOCUMENT)) {
            NamedValueDocument nvd = NamedValueDocument.Factory.newInstance();
            nvd.setNamedValue(nvt);
            encodedObject = nvd;
        } else if (additionalValues.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
            NamedValuePropertyType nvpt = NamedValuePropertyType.Factory.newInstance();
            nvpt.setNamedValue(nvt);
            encodedObject = nvpt;
        } else {
            encodedObject = nvt;
        }
    } else if (element instanceof AbstractFeature) {
        encodedObject = encodeFeatureOfInterest((AbstractFeature) element);
    } else if (element instanceof SosProcedureDescription) {
        encodedObject = encodeProcedureDescription((SosProcedureDescription<?>) element);
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    // XmlHelper.validateDocument(encodedObject));
    return encodedObject;
}
Also used : NamedValueDocument(net.opengis.om.x20.NamedValueDocument) NamedValueType(net.opengis.om.x20.NamedValueType) OmObservation(org.n52.shetland.ogc.om.OmObservation) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) XmlObject(org.apache.xmlbeans.XmlObject) NamedValue(org.n52.shetland.ogc.om.NamedValue) NamedValuePropertyType(net.opengis.om.x20.NamedValuePropertyType) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 5 with UnsupportedEncoderInputException

use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.

the class OmEncoderv100 method encode.

@Override
public XmlObject encode(Object element, EncodingContext additionalValues) throws EncodingException {
    XmlObject encodedObject = null;
    if (element instanceof OmObservation) {
        encodedObject = createObservation((OmObservation) element, additionalValues);
    } else if (element instanceof GetObservationResponse) {
        GetObservationResponse response = (GetObservationResponse) element;
        encodedObject = createObservationCollection(response.getObservationCollection(), response.getResultModel());
    } else if (element instanceof GetObservationByIdResponse) {
        GetObservationByIdResponse response = (GetObservationByIdResponse) element;
        encodedObject = createObservationCollection(response.getObservationCollection(), response.getResultModel());
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    XmlHelper.validateDocument(encodedObject, EncodingException::new);
    return encodedObject;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) OmObservation(org.n52.shetland.ogc.om.OmObservation) GetObservationResponse(org.n52.shetland.ogc.sos.response.GetObservationResponse) XmlObject(org.apache.xmlbeans.XmlObject) GetObservationByIdResponse(org.n52.shetland.ogc.sos.response.GetObservationByIdResponse) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Aggregations

UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)29 XmlObject (org.apache.xmlbeans.XmlObject)16 EncodingException (org.n52.svalbard.encode.exception.EncodingException)12 XmlException (org.apache.xmlbeans.XmlException)5 Geometry (org.locationtech.jts.geom.Geometry)3 LineString (org.locationtech.jts.geom.LineString)3 Point (org.locationtech.jts.geom.Point)3 Polygon (org.locationtech.jts.geom.Polygon)3 GeometryPropertyType (net.opengis.gml.x32.GeometryPropertyType)2 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)2 OmObservation (org.n52.shetland.ogc.om.OmObservation)2 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)2 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)2 CategoryValue (org.n52.shetland.ogc.om.values.CategoryValue)2 QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)2 AbstractSensorML (org.n52.shetland.ogc.sensorML.AbstractSensorML)2 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)2 SweField (org.n52.shetland.ogc.swe.SweField)2 EnvelopeOrGeometry (org.n52.shetland.util.EnvelopeOrGeometry)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1