Search in sources :

Example 26 with UnsupportedEncoderInputException

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

the class GmlEncoderv321 method createAbstractGeometry.

private AbstractGeometryType createAbstractGeometry(AbstractGeometry element, EncodingContext ctx) throws EncodingException {
    XmlObject xbGeometry = createPosition(element.getGeometry(), ctx);
    AbstractGeometryType abstractGeometryType = null;
    if (xbGeometry instanceof AbstractGeometryType) {
        abstractGeometryType = (AbstractGeometryType) xbGeometry;
    } else if (xbGeometry instanceof GeometryPropertyType) {
        abstractGeometryType = ((GeometryPropertyType) xbGeometry).getAbstractGeometry();
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    if (element.isSetIdentifier()) {
        abstractGeometryType.setIdentifier(createCodeWithAuthorityType(element.getIdentifierCodeWithAuthority()));
    }
    if (element.isSetName()) {
        for (org.n52.shetland.ogc.gml.CodeType codeType : element.getName()) {
            abstractGeometryType.addNewName().set(createCodeType(codeType));
        }
    }
    if (element.isSetDescription()) {
        abstractGeometryType.addNewDescription().setStringValue(element.getDescription());
    }
    return abstractGeometryType;
}
Also used : AbstractGeometryType(net.opengis.gml.x32.AbstractGeometryType) XmlObject(org.apache.xmlbeans.XmlObject) GeometryPropertyType(net.opengis.gml.x32.GeometryPropertyType) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 27 with UnsupportedEncoderInputException

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

the class SweCommonEncoderv101 method createDataArray.

private DataArrayDocument createDataArray(SweDataArray sosDataArray) throws EncodingException {
    if (sosDataArray != null) {
        if (sosDataArray.isSetElementTyp()) {
            DataArrayDocument xbDataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
            DataArrayType xbDataArray = xbDataArrayDoc.addNewDataArray1();
            // set element count
            if (sosDataArray.isSetElementCount()) {
                xbDataArray.addNewElementCount().addNewCount().set(createCount(sosDataArray.getElementCount()));
            }
            if (sosDataArray.isSetElementTyp()) {
                DataComponentPropertyType xbElementType = xbDataArray.addNewElementType();
                xbElementType.setName("Components");
                // FIXME use visitor pattern
                if (sosDataArray.getElementType() instanceof SweBoolean) {
                    xbElementType.addNewBoolean().set(createSimpleType((SweBoolean) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweCategory) {
                    xbElementType.addNewCategory().set(createSimpleType((SweCategory) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweCount) {
                    xbElementType.addNewCount().set(createSimpleType((SweCount) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweQuantity) {
                    xbElementType.addNewQuantity().set(createSimpleType((SweQuantity) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweText) {
                    xbElementType.addNewText().set(createSimpleType((SweText) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweTimeRange) {
                    xbElementType.addNewTimeRange().set(createSimpleType((SweTimeRange) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweTime) {
                    xbElementType.addNewTime().set(createSimpleType((SweTime) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweEnvelope) {
                    xbElementType.addNewAbstractDataRecord().set(createEnvelope((SweEnvelope) sosDataArray.getElementType()));
                    xbElementType.getAbstractDataRecord().substitute(SweConstants.QN_ENVELOPE_SWE_101, EnvelopeType.type);
                } else if (sosDataArray.getElementType() instanceof SweDataRecord) {
                    xbElementType.addNewAbstractDataRecord().set(createDataRecord((SweDataRecord) sosDataArray.getElementType()));
                    xbElementType.getAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataRecordType.type);
                } else if (sosDataArray.getElementType() instanceof SweDataArray) {
                    xbElementType.addNewAbstractDataArray1().set(createDataArray((SweDataArray) sosDataArray.getElementType()).getDataArray1());
                    xbElementType.getAbstractDataArray1().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataArrayType.type);
                } else {
                    throw new UnsupportedEncoderInputException(this, sosDataArray.getElementType());
                }
            }
            if (sosDataArray.isSetEncoding()) {
                BlockEncodingPropertyType xbEncoding = xbDataArray.addNewEncoding();
                xbEncoding.set(createBlockEncoding(sosDataArray.getEncoding()));
            // xbDataArray.getEncoding().substitute(
            // new QName(SWEConstants.NS_SWE_101,
            // SWEConstants.EN_TEXT_ENCODING,
            // SWEConstants.NS_SWE_PREFIX), TextBlock.type);
            }
            // }
            if (sosDataArray.isSetValues()) {
                xbDataArray.addNewValues().set(createValues(sosDataArray.getValues(), sosDataArray.getEncoding()));
            }
            return xbDataArrayDoc;
        } else if (sosDataArray.isSetXml()) {
            try {
                XmlObject xmlObject = XmlObject.Factory.parse(sosDataArray.getXml().trim());
                if (xmlObject instanceof DataArrayDocument) {
                    return (DataArrayDocument) xmlObject;
                } else {
                    DataArrayDocument xbDataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
                    xbDataArrayDoc.setDataArray1(DataArrayType.Factory.parse(sosDataArray.getXml().trim()));
                    return xbDataArrayDoc;
                }
            } catch (XmlException e) {
                throw new EncodingException("Error while encoding SweDataArray!", e);
            }
        }
    }
    return null;
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) BlockEncodingPropertyType(net.opengis.swe.x101.BlockEncodingPropertyType) EncodingException(org.n52.svalbard.encode.exception.EncodingException) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) XmlException(org.apache.xmlbeans.XmlException) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) DataArrayDocument(net.opengis.swe.x101.DataArrayDocument) DataArrayType(net.opengis.swe.x101.DataArrayType)

Example 28 with UnsupportedEncoderInputException

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

the class WmlTDREncoderv20 method createMeasurementDomainRange.

/**
 * Create a XML MeasurementTimeseriesDomainRange object from SOS observation
 * for om:result
 *
 * @param sosObservation
 *            SOS observation
 * @return XML MeasurementTimeseriesDomainRange object for om:result
 * @throws EncodingException
 *             If an error occurs
 */
private XmlObject createMeasurementDomainRange(OmObservation sosObservation) throws EncodingException {
    if (!sosObservation.getObservationConstellation().isSetObservationType() || (sosObservation.getObservationConstellation().isSetObservationType() && isInvalidObservationType(sosObservation.getObservationConstellation().getObservationType()))) {
        throw new UnsupportedEncoderInputException(this, sosObservation.getObservationConstellation().isSetObservationType());
    }
    MeasurementTimeseriesDomainRangeDocument xbMearuementTimeseriesDomainRangeDoc = MeasurementTimeseriesDomainRangeDocument.Factory.newInstance();
    MeasurementTimeseriesCoverageType xbMeasurementTimeseriesDomainRange = xbMearuementTimeseriesDomainRangeDoc.addNewMeasurementTimeseriesDomainRange();
    xbMeasurementTimeseriesDomainRange.setId(TIMESERIES_ID_PREFIX + sosObservation.getObservationID());
    // set time position list
    xbMeasurementTimeseriesDomainRange.addNewDomainSet().set(getTimePositionList(sosObservation));
    // initialize unit
    AbstractPhenomenon observableProperty = sosObservation.getObservationConstellation().getObservableProperty();
    String unit = null;
    // create quantity list from values
    QuantityListDocument quantityListDoc = QuantityListDocument.Factory.newInstance();
    MeasureOrNilReasonListType quantityList = quantityListDoc.addNewQuantityList();
    if (sosObservation.getValue() instanceof MultiObservationValues) {
        MultiObservationValues<?> observationValue = (MultiObservationValues<?>) sosObservation.getValue();
        TVPValue tvpValue = (TVPValue) observationValue.getValue();
        List<TimeValuePair> timeValuePairs = tvpValue.getValue();
        if (Strings.isNullOrEmpty(unit) && CollectionHelper.isNotEmpty(timeValuePairs) && timeValuePairs.get(0).getValue().isSetUnit()) {
            unit = timeValuePairs.get(0).getValue().getUnit();
        }
        quantityList.setListValue(getValueList(timeValuePairs));
    }
    if (Strings.isNullOrEmpty(unit)) {
        unit = OGCConstants.UNKNOWN;
    }
    quantityList.setUom(unit);
    // set unit to SosObservableProperty if not set.
    if (observableProperty instanceof OmObservableProperty && !((OmObservableProperty) observableProperty).isSetUnit()) {
        ((OmObservableProperty) observableProperty).setUnit(unit);
    }
    // set up range set
    xbMeasurementTimeseriesDomainRange.addNewRangeSet().set(quantityListDoc);
    // set up rangeType
    xbMeasurementTimeseriesDomainRange.addNewRangeType().set(createDataRecord(sosObservation));
    // set om:Result
    return xbMearuementTimeseriesDomainRangeDoc;
}
Also used : TVPValue(org.n52.shetland.ogc.om.values.TVPValue) MeasureOrNilReasonListType(net.opengis.gml.x32.MeasureOrNilReasonListType) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) MeasurementTimeseriesDomainRangeDocument(net.opengis.watermlDr.x20.MeasurementTimeseriesDomainRangeDocument) AbstractPhenomenon(org.n52.shetland.ogc.om.AbstractPhenomenon) QuantityListDocument(net.opengis.gml.x32.QuantityListDocument) MeasurementTimeseriesCoverageType(net.opengis.watermlDr.x20.MeasurementTimeseriesCoverageType) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Example 29 with UnsupportedEncoderInputException

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

the class SamplingEncoderv20 method createFeature.

protected XmlObject createFeature(final AbstractFeature absFeature) throws EncodingException {
    if (absFeature instanceof AbstractSamplingFeature) {
        final AbstractSamplingFeature sampFeat = (AbstractSamplingFeature) absFeature;
        final SFSpatialSamplingFeatureDocument xbSampFeatDoc = SFSpatialSamplingFeatureDocument.Factory.newInstance(getXmlOptions());
        if (sampFeat.isSetXml()) {
            try {
                final XmlObject feature = XmlObject.Factory.parse(sampFeat.getXml(), getXmlOptions());
                if (XmlHelper.getNamespace(feature).equals(SfConstants.NS_SAMS)) {
                    XmlHelper.updateGmlIDs(feature.getDomNode().getFirstChild(), absFeature.getGmlId(), null);
                    if (feature instanceof SFSpatialSamplingFeatureType) {
                        xbSampFeatDoc.setSFSpatialSamplingFeature((SFSpatialSamplingFeatureType) feature);
                        encodeShape(xbSampFeatDoc.getSFSpatialSamplingFeature().getShape(), sampFeat);
                        addNameDescription(xbSampFeatDoc.getSFSpatialSamplingFeature(), sampFeat);
                        return xbSampFeatDoc;
                    }
                    encodeShape(((SFSpatialSamplingFeatureDocument) feature).getSFSpatialSamplingFeature().getShape(), sampFeat);
                    addNameDescription(((SFSpatialSamplingFeatureDocument) feature).getSFSpatialSamplingFeature(), sampFeat);
                    sampFeat.wasEncoded();
                    return feature;
                } else {
                    return encodeObjectToXml(XmlHelper.getNamespace(feature), absFeature);
                }
            } catch (final XmlException xmle) {
                throw new EncodingException("Error while encoding GetFeatureOfInterest response, invalid samplingFeature description!", xmle);
            }
        }
        final SFSpatialSamplingFeatureType xbSampFeature = xbSampFeatDoc.addNewSFSpatialSamplingFeature();
        // TODO: CHECK for all fields set gml:id
        addId(xbSampFeature, sampFeat);
        addIdentifier(xbSampFeature, sampFeat);
        // set type
        addFeatureType(xbSampFeature, sampFeat);
        // set type
        addNameDescription(xbSampFeature, sampFeat);
        setMetaDataProperty(xbSampFeature, sampFeat);
        // set sampledFeatures
        // TODO: CHECK
        addSampledFeatures(xbSampFeature, sampFeat);
        addParameter(xbSampFeature, sampFeat);
        // set position
        encodeShape(xbSampFeature.addNewShape(), sampFeat);
        sampFeat.wasEncoded();
        return xbSampFeatDoc;
    }
    throw new UnsupportedEncoderInputException(this, absFeature);
}
Also used : SFSpatialSamplingFeatureDocument(net.opengis.samplingSpatial.x20.SFSpatialSamplingFeatureDocument) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) SFSpatialSamplingFeatureType(net.opengis.samplingSpatial.x20.SFSpatialSamplingFeatureType) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 30 with UnsupportedEncoderInputException

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

the class SensorMLEncoderv101 method encode.

@Override
public XmlObject encode(final Object response, final EncodingContext additionalValues) throws EncodingException {
    XmlObject encodedObject = null;
    if (response instanceof AbstractSensorML) {
        encodedObject = createSensorDescription((AbstractSensorML) response);
    // }
    // FIXME workaround? if of type UnknowProcedureType try to parse the
    // description string, UNIT is missing "NOT_DEFINED"?!
    // else if (response instanceof SosProcedureDescriptionUnknownType)
    // {
    // final String procDescXMLString = ((SosProcedureDescription)
    // response).getXml();
    // final AbstractSensorML sensorDesc = new AbstractSensorML();
    // sensorDesc.setXml(procDescXMLString);
    // encodedObject = createSensorDescriptionFromString(sensorDesc);
    } else {
        throw new UnsupportedEncoderInputException(this, response);
    }
    // check if all gml:id are unique
    XmlHelper.makeGmlIdsUnique(encodedObject.getDomNode());
    XmlHelper.validateDocument(encodedObject, EncodingException::new);
    return encodedObject;
}
Also used : AbstractSensorML(org.n52.shetland.ogc.sensorML.AbstractSensorML) EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlObject(org.apache.xmlbeans.XmlObject) 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