Search in sources :

Example 6 with Encoder

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

the class AbstractAqdResponseEncoder method getEncoder.

/**
 * Get the {@link Encoder} for the {@link OwsServiceResponse} and the
 * requested contentType
 *
 * @param asr
 *            {@link OwsServiceResponse} to get {@link Encoder} for
 * @return {@link Encoder} for the {@link OwsServiceResponse}
 */
protected Encoder<Object, OwsServiceResponse> getEncoder(OwsServiceResponse asr) {
    OperationResponseEncoderKey key = new OperationResponseEncoderKey(new OwsOperationKey(asr), getContentType());
    Encoder<Object, OwsServiceResponse> encoder = getEncoder(key);
    if (encoder == null) {
        throw new RuntimeException(new NoEncoderForKeyException(key));
    }
    return encoder;
}
Also used : NoEncoderForKeyException(org.n52.svalbard.encode.exception.NoEncoderForKeyException) XmlObject(org.apache.xmlbeans.XmlObject) OwsOperationKey(org.n52.shetland.ogc.ows.service.OwsOperationKey) OwsServiceResponse(org.n52.shetland.ogc.ows.service.OwsServiceResponse)

Example 7 with Encoder

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

the class OmEncoderv100 method createObservationCollection.

private XmlObject createObservationCollection(ObservationStream sosObservationCollectionIterable, String resultModel) throws EncodingException {
    ObservationCollectionDocument xbObservationCollectionDoc = ObservationCollectionDocument.Factory.newInstance(getXmlOptions());
    ObservationCollectionType xbObservationCollection = xbObservationCollectionDoc.addNewObservationCollection();
    xbObservationCollection.setId(SosConstants.OBS_COL_ID_PREFIX + new DateTime().getMillis());
    if (sosObservationCollectionIterable != null) {
        List<OmObservation> sosObservationCollection = new LinkedList<>();
        try {
            sosObservationCollectionIterable.forEachRemaining(sosObservationCollection::add);
            ReferencedEnvelope sosEnvelope = getEnvelope(sosObservationCollection);
            Encoder<XmlObject, ReferencedEnvelope> envEncoder = getEncoder(GmlConstants.NS_GML, sosEnvelope);
            xbObservationCollection.addNewBoundedBy().addNewEnvelope().set(envEncoder.encode(sosEnvelope));
            for (OmObservation sosObservation : sosObservationCollection) {
                String observationType = checkObservationType(sosObservation);
                if (Strings.isNullOrEmpty(resultModel) || (!Strings.isNullOrEmpty(resultModel) && observationType.equals(resultModel))) {
                    if (sosObservation.getValue() instanceof StreamingValue) {
                        StreamingValue<?> streamingValue = (StreamingValue<?>) sosObservation.getValue();
                        while (streamingValue.hasNext()) {
                            xbObservationCollection.addNewMember().set(createObservation(streamingValue.next(), null));
                        }
                    } else {
                        xbObservationCollection.addNewMember().set(createObservation(sosObservation, null));
                    }
                } else {
                    throw new EncodingException("The requested resultModel '%s' is invalid for the resulting observations!", OMHelper.getEncodedResultModelFor(resultModel));
                }
            }
        } catch (OwsExceptionReport owse) {
            throw new EncodingException(owse);
        }
    } else {
        ObservationPropertyType xbObservation = xbObservationCollection.addNewMember();
        xbObservation.setHref(GmlConstants.NIL_INAPPLICABLE);
    }
    XmlHelper.makeGmlIdsUnique(xbObservationCollectionDoc.getDomNode());
    N52XmlHelper.setSchemaLocationsToDocument(xbObservationCollectionDoc, Sets.newHashSet(N52XmlHelper.getSchemaLocationForSOS100(), N52XmlHelper.getSchemaLocationForOM100(), N52XmlHelper.getSchemaLocationForSA100()));
    return xbObservationCollectionDoc;
}
Also used : StreamingValue(org.n52.shetland.ogc.om.StreamingValue) EncodingException(org.n52.svalbard.encode.exception.EncodingException) ObservationPropertyType(net.opengis.om.x10.ObservationPropertyType) OmObservation(org.n52.shetland.ogc.om.OmObservation) ObservationCollectionType(net.opengis.om.x10.ObservationCollectionType) XmlString(org.apache.xmlbeans.XmlString) DateTime(org.joda.time.DateTime) LinkedList(java.util.LinkedList) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) ObservationCollectionDocument(net.opengis.om.x10.ObservationCollectionDocument) XmlObject(org.apache.xmlbeans.XmlObject) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 8 with Encoder

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

the class GmlEncoderv311 method createFeature.

private XmlObject createFeature(AbstractFeature sosAbstractFeature) throws EncodingException {
    if (sosAbstractFeature instanceof SamplingFeature) {
        SamplingFeature sampFeat = (SamplingFeature) sosAbstractFeature;
        if (sosAbstractFeature.isSetGmlID()) {
            FeaturePropertyType featureProperty = FeaturePropertyType.Factory.newInstance(getXmlOptions());
            featureProperty.setHref("#" + sosAbstractFeature.getGmlId());
            return featureProperty;
        } else {
            if (!sampFeat.isSetGeometry()) {
                FeaturePropertyType featureProperty = FeaturePropertyType.Factory.newInstance(getXmlOptions());
                featureProperty.setHref(sosAbstractFeature.getIdentifierCodeWithAuthority().getValue());
                if (sampFeat.isSetName()) {
                    featureProperty.setTitle(sampFeat.getFirstName().getValue());
                }
                return featureProperty;
            }
            StringBuilder builder = new StringBuilder();
            builder.append("sf_");
            builder.append(JavaHelper.generateID(sosAbstractFeature.getIdentifierCodeWithAuthority().getValue()));
            sosAbstractFeature.setGmlId(builder.toString());
            Encoder<XmlObject, SamplingFeature> encoder = getEncoder(SfConstants.NS_SA, sampFeat);
            return encoder.encode(sampFeat);
        }
    } else if (sosAbstractFeature instanceof FeatureCollection) {
        return createFeatureCollection((FeatureCollection) sosAbstractFeature);
    }
    throw new UnsupportedEncoderInputException(this, sosAbstractFeature);
}
Also used : FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) XmlObject(org.apache.xmlbeans.XmlObject) FeaturePropertyType(net.opengis.gml.FeaturePropertyType) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 9 with Encoder

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

the class GetObservationByIdResponseEncoder method createResponse.

@Override
protected XmlObject createResponse(ObservationEncoder<XmlObject, OmObservation> encoder, GetObservationByIdResponse response) throws EncodingException {
    GetObservationByIdResponseDocument doc = GetObservationByIdResponseDocument.Factory.newInstance(getXmlOptions());
    GetObservationByIdResponseType xbResponse = doc.addNewGetObservationByIdResponse();
    ObservationStream observations = getObservationsAndCheckForStreaming(response, encoder);
    HashMap<CodeWithAuthority, String> gmlID4sfIdentifier = new HashMap<>();
    try {
        while (observations.hasNext()) {
            OmObservation observation = observations.next();
            EncodingContext codingContext = EncodingContext.empty();
            CodeWithAuthority foiId = observation.getObservationConstellation().getFeatureOfInterest().getIdentifierCodeWithAuthority();
            if (gmlID4sfIdentifier.containsKey(foiId)) {
                codingContext = codingContext.with(XmlBeansEncodingFlags.EXIST_FOI_IN_DOC, true);
            } else {
                gmlID4sfIdentifier.put(foiId, GML_ID);
                codingContext = codingContext.with(XmlBeansEncodingFlags.EXIST_FOI_IN_DOC, false);
            }
            codingContext = codingContext.with(XmlBeansEncodingFlags.GMLID, gmlID4sfIdentifier.get(foiId));
            xbResponse.addNewObservation().addNewOMObservation().set(encoder.encode(observation, codingContext));
        }
    } catch (OwsExceptionReport ex) {
        throw new EncodingException(ex);
    }
    XmlHelper.makeGmlIdsUnique(xbResponse.getDomNode());
    return doc;
}
Also used : ObservationStream(org.n52.shetland.ogc.om.ObservationStream) HashMap(java.util.HashMap) EncodingException(org.n52.svalbard.encode.exception.EncodingException) OmObservation(org.n52.shetland.ogc.om.OmObservation) GetObservationByIdResponseDocument(net.opengis.sos.x20.GetObservationByIdResponseDocument) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) GetObservationByIdResponseType(net.opengis.sos.x20.GetObservationByIdResponseType)

Example 10 with Encoder

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

the class GetObservationResponseEncoder method createResponse.

@Override
protected void createResponse(ObservationEncoder<XmlObject, OmObservation> encoder, GetObservationResponse response, OutputStream outputStream, EncodingContext ctx) throws EncodingException {
    try {
        EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions).with(StreamingEncoderFlags.ENCODER, this);
        new GetObservationResponseXmlStreamWriter(context, outputStream, response).write();
    } catch (XMLStreamException xmlse) {
        throw new EncodingException(xmlse);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlOptions(org.apache.xmlbeans.XmlOptions) GetObservationResponseXmlStreamWriter(org.n52.svalbard.write.GetObservationResponseXmlStreamWriter)

Aggregations

Test (org.junit.Test)28 XmlObject (org.apache.xmlbeans.XmlObject)19 EncodingException (org.n52.svalbard.encode.exception.EncodingException)17 XmlOptions (org.apache.xmlbeans.XmlOptions)7 InsertResultTemplateRequest (org.n52.shetland.ogc.sos.request.InsertResultTemplateRequest)7 InsertSensorRequest (org.n52.shetland.ogc.sos.request.InsertSensorRequest)7 Before (org.junit.Before)6 OmObservation (org.n52.shetland.ogc.om.OmObservation)5 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)5 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)5 OwsOperationKey (org.n52.shetland.ogc.ows.service.OwsOperationKey)5 InsertObservationRequest (org.n52.shetland.ogc.sos.request.InsertObservationRequest)5 NoEncoderForKeyException (org.n52.svalbard.encode.exception.NoEncoderForKeyException)5 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)4 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)4 OwsServiceResponse (org.n52.shetland.ogc.ows.service.OwsServiceResponse)4 InsertResultRequest (org.n52.shetland.ogc.sos.request.InsertResultRequest)4 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)4 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)4 CodeType (org.n52.shetland.ogc.gml.CodeType)3