Search in sources :

Example 66 with EncodingException

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

the class InspireXmlEncoder method encodeObject.

private XmlObject encodeObject(InspireObject objectToEncode, EncodingContext ctx) throws EncodingException {
    try {
        checkIfSupported(objectToEncode);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
        new InspireXmlStreamWriter(context, out, objectToEncode).write();
        String s = out.toString("UTF8");
        return XmlObject.Factory.parse(s);
    } catch (XMLStreamException | DateTimeFormatException | XmlException | UnsupportedEncodingException ex) {
        throw new EncodingException("Error encoding Inspire extended capabilities!", ex);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlException(org.apache.xmlbeans.XmlException) InspireXmlStreamWriter(org.n52.svalbard.write.InspireXmlStreamWriter) DateTimeFormatException(org.n52.shetland.util.DateTimeFormatException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Supplier(java.util.function.Supplier) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 67 with EncodingException

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

the class DeleteObservationEncoder method create.

@Override
protected XmlObject create(DeleteObservationResponse dor) throws EncodingException {
    if (dor == null) {
        throw new UnsupportedEncoderInputException(this, DeleteObservationResponse.class);
    }
    String observationId = dor.getObservationId();
    DeleteObservationResponseDocument xbDeleteObsDoc = DeleteObservationResponseDocument.Factory.newInstance(getXmlOptions());
    DeleteObservationResponseType xbDeleteObservationResponse = xbDeleteObsDoc.addNewDeleteObservationResponse();
    xbDeleteObservationResponse.setDeletedObservation(observationId);
    return xbDeleteObsDoc;
}
Also used : DeleteObservationResponseType(net.opengis.sosdo.x10.DeleteObservationResponseType) DeleteObservationResponseDocument(net.opengis.sosdo.x10.DeleteObservationResponseDocument) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 68 with EncodingException

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

the class SamplingEncoderv100 method createFeature.

private XmlObject createFeature(AbstractFeature absFeature) throws EncodingException {
    if (absFeature instanceof AbstractSamplingFeature) {
        AbstractSamplingFeature sampFeat = (AbstractSamplingFeature) absFeature;
        if (sampFeat.getFeatureType().equals(SfConstants.FT_SAMPLINGPOINT) || sampFeat.getFeatureType().equals(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT) || sampFeat.getGeometry() instanceof Point) {
            SamplingPointDocument xbSamplingPointDoc = SamplingPointDocument.Factory.newInstance(getXmlOptions());
            SamplingPointType xbSamplingPoint = xbSamplingPointDoc.addNewSamplingPoint();
            addValuesToFeature(xbSamplingPoint, sampFeat);
            XmlObject xbGeomety = getEncodedGeometry(sampFeat.getGeometry(), absFeature.getGmlId());
            xbSamplingPoint.addNewPosition().addNewPoint().set(xbGeomety);
            sampFeat.wasEncoded();
            return xbSamplingPointDoc;
        } else if (sampFeat.getFeatureType().equals(SfConstants.FT_SAMPLINGCURVE) || sampFeat.getFeatureType().equals(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_CURVE) || sampFeat.getGeometry() instanceof LineString) {
            SamplingCurveDocument xbSamplingCurveDoc = SamplingCurveDocument.Factory.newInstance(getXmlOptions());
            SamplingCurveType xbSamplingCurve = xbSamplingCurveDoc.addNewSamplingCurve();
            addValuesToFeature(xbSamplingCurve, sampFeat);
            XmlObject xbGeomety = getEncodedGeometry(sampFeat.getGeometry(), absFeature.getGmlId());
            xbSamplingCurve.addNewShape().addNewCurve().set(xbGeomety);
            sampFeat.wasEncoded();
            return xbSamplingCurveDoc;
        } else if (sampFeat.getFeatureType().equals(SfConstants.FT_SAMPLINGSURFACE) || sampFeat.getFeatureType().equals(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_SURFACE) || sampFeat.getGeometry() instanceof Polygon) {
            SamplingSurfaceDocument xbSamplingSurfaceDoc = SamplingSurfaceDocument.Factory.newInstance(getXmlOptions());
            SamplingSurfaceType xbSamplingSurface = xbSamplingSurfaceDoc.addNewSamplingSurface();
            addValuesToFeature(xbSamplingSurface, sampFeat);
            XmlObject xbGeomety = getEncodedGeometry(sampFeat.getGeometry(), absFeature.getGmlId());
            xbSamplingSurface.addNewShape().addNewSurface().set(xbGeomety);
            sampFeat.wasEncoded();
            return xbSamplingSurfaceDoc;
        }
    } else if (absFeature instanceof FeatureCollection) {
        createFeatureCollection((FeatureCollection) absFeature);
    }
    throw new UnsupportedEncoderInputException(this, absFeature);
}
Also used : SamplingSurfaceType(net.opengis.sampling.x10.SamplingSurfaceType) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) Point(org.locationtech.jts.geom.Point) SamplingCurveDocument(net.opengis.sampling.x10.SamplingCurveDocument) SamplingCurveType(net.opengis.sampling.x10.SamplingCurveType) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) SamplingPointDocument(net.opengis.sampling.x10.SamplingPointDocument) LineString(org.locationtech.jts.geom.LineString) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) SamplingPointType(net.opengis.sampling.x10.SamplingPointType) XmlObject(org.apache.xmlbeans.XmlObject) SamplingSurfaceDocument(net.opengis.sampling.x10.SamplingSurfaceDocument) Polygon(org.locationtech.jts.geom.Polygon)

Example 69 with EncodingException

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

the class SamplingEncoderv100 method addValuesToFeature.

private void addValuesToFeature(SamplingFeatureType xbSamplingFeature, AbstractSamplingFeature sampFeat) throws EncodingException {
    xbSamplingFeature.setId(sampFeat.getGmlId());
    if (sampFeat.isSetIdentifier()) {
        sampFeat.getIdentifierCodeWithAuthority().setCodeSpace("uniquID");
        xbSamplingFeature.addNewName().set(encodeObjectToXml(GmlConstants.NS_GML, sampFeat.getIdentifierCodeWithAuthority()));
    }
    if (sampFeat.isSetName()) {
        for (CodeType sosName : sampFeat.getName()) {
            xbSamplingFeature.addNewName().set(encodeObjectToXml(GmlConstants.NS_GML, sosName));
        }
    }
    // TODO: CHECK
    if (sampFeat.getSampledFeatures() != null && !sampFeat.getSampledFeatures().isEmpty()) {
        for (AbstractFeature sampledFeature : sampFeat.getSampledFeatures()) {
            FeaturePropertyType sp = xbSamplingFeature.addNewSampledFeature();
            sp.setHref(sampledFeature.getIdentifier());
            if (sampFeat.isSetName() && sampFeat.getFirstName().isSetValue()) {
                sp.setTitle(sampFeat.getFirstName().getValue());
            }
        // xbSamplingFeature.addNewSampledFeature().set(createFeature(sampledFeature));
        }
    } else {
        xbSamplingFeature.addNewSampledFeature().setHref(GmlConstants.NIL_UNKNOWN);
    }
    // set metadataProperty
    setMetaDataProperty(xbSamplingFeature, sampFeat);
}
Also used : CodeType(org.n52.shetland.ogc.gml.CodeType) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) SamplingFeaturePropertyType(net.opengis.sampling.x10.SamplingFeaturePropertyType) FeaturePropertyType(net.opengis.gml.FeaturePropertyType)

Example 70 with EncodingException

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

the class SamplingEncoderv20 method addSampledFeatures.

protected void addSampledFeatures(SFSamplingFeatureType sfsft, AbstractSamplingFeature sampFeat) throws EncodingException {
    if (sampFeat.isSetSampledFeatures()) {
        for (AbstractFeature sampledFeature : sampFeat.getSampledFeatures()) {
            XmlObject encodeObjectToXml = encodeObjectToXml(GmlConstants.NS_GML_32, sampledFeature, new EncodingContext().with(XmlBeansEncodingFlags.REFERENCED));
            sfsft.addNewSampledFeature().set(encodeObjectToXml);
        }
    } else {
        sfsft.addNewSampledFeature().setHref(OGCConstants.UNKNOWN);
    }
}
Also used : AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) XmlObject(org.apache.xmlbeans.XmlObject)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)124 Test (org.junit.Test)93 EncodingException (org.n52.svalbard.encode.exception.EncodingException)60 SweField (org.n52.shetland.ogc.swe.SweField)29 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)29 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)22 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)21 XmlException (org.apache.xmlbeans.XmlException)20 DateTime (org.joda.time.DateTime)19 OmObservation (org.n52.shetland.ogc.om.OmObservation)19 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)17 Time (org.n52.shetland.ogc.gml.time.Time)15 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)15 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)13 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)13 AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)12 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)12 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)12 SystemType (net.opengis.sensorML.x101.SystemType)11 DataRecordType (net.opengis.swe.x101.DataRecordType)11