Search in sources :

Example 1 with ObservationEncoder

use of org.n52.svalbard.encode.ObservationEncoder in project SOS by 52North.

the class AbstractObservationDao method checkEncoderForMergeObservationValues.

/**
 * Check if the {@link ObservationEncoder} demands for merging of
 * observations with the same timeseries.
 *
 * @param responseFormat
 *            Response format
 *
 * @return <code>true</code>, if the {@link ObservationEncoder} demands for
 *         merging of observations with the same timeseries.
 */
public boolean checkEncoderForMergeObservationValues(String responseFormat) {
    XmlEncoderKey key = new XmlEncoderKey(responseFormat, OmObservation.class);
    Encoder<XmlObject, OmObservation> encoder = getEncoder(key);
    if (encoder != null && encoder instanceof ObservationEncoder) {
        return ((ObservationEncoder<?, OmObservation>) encoder).shouldObservationsWithSameXBeMerged();
    }
    return false;
}
Also used : ObservationEncoder(org.n52.svalbard.encode.ObservationEncoder) XmlEncoderKey(org.n52.svalbard.encode.XmlEncoderKey) OmObservation(org.n52.shetland.ogc.om.OmObservation) XmlObject(org.apache.xmlbeans.XmlObject)

Example 2 with ObservationEncoder

use of org.n52.svalbard.encode.ObservationEncoder in project SOS by 52North.

the class AbstractSosOperationHandler method getResponseFormatsForObservationType.

protected Set<String> getResponseFormatsForObservationType(String observationType, String service, String version) {
    Set<String> responseFormats = Sets.newHashSet();
    for (Encoder<?, ?> e : getEncoderRepository().getEncoders()) {
        if (e instanceof ObservationEncoder) {
            final ObservationEncoder<?, ?> oe = (ObservationEncoder<?, ?>) e;
            Map<String, Set<SupportedType>> supportedResponseFormatObservationTypes = oe.getSupportedResponseFormatObservationTypes();
            if (supportedResponseFormatObservationTypes != null && !supportedResponseFormatObservationTypes.isEmpty()) {
                for (final Entry<String, Set<SupportedType>> entry : supportedResponseFormatObservationTypes.entrySet()) {
                    for (SupportedType st : supportedResponseFormatObservationTypes.get(entry.getKey())) {
                        if (st instanceof ObservationType && observationType.equals(((ObservationType) st).getValue())) {
                            responseFormats.add(entry.getKey());
                        }
                    }
                }
            }
        }
    }
    return responseFormats;
}
Also used : ObservationEncoder(org.n52.svalbard.encode.ObservationEncoder) Set(java.util.Set) ObservationType(org.n52.shetland.ogc.om.ObservationType) SupportedType(org.n52.shetland.ogc.SupportedType)

Example 3 with ObservationEncoder

use of org.n52.svalbard.encode.ObservationEncoder 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();
    if (response.hasExtensions()) {
        createExtension(xbResponse, response.getExtensions());
    }
    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 4 with ObservationEncoder

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

the class GetObservationResponseEncoder method createResponse.

@Override
protected XmlObject createResponse(ObservationEncoder<XmlObject, OmObservation> encoder, GetObservationResponse response) throws EncodingException {
    try {
        GetObservationResponseDocument doc = GetObservationResponseDocument.Factory.newInstance(getXmlOptions());
        GetObservationResponseType xbResponse = doc.addNewGetObservationResponse();
        if (response.hasExtensions()) {
            createExtension(xbResponse, response.getExtensions());
        }
        ObservationStream observationCollection = response.getObservationCollection();
        while (observationCollection.hasNext()) {
            xbResponse.addNewObservationData().addNewOMObservation().set(encoder.encode(observationCollection.next()));
        }
        // in a single observation the gml:ids must be unique
        XmlHelper.makeGmlIdsUnique(doc.getDomNode());
        return doc;
    } catch (OwsExceptionReport ex) {
        throw new EncodingException(ex);
    }
}
Also used : ObservationStream(org.n52.shetland.ogc.om.ObservationStream) EncodingException(org.n52.svalbard.encode.exception.EncodingException) GetObservationResponseType(net.opengis.sos.x20.GetObservationResponseType) GetObservationResponseDocument(net.opengis.sos.x20.GetObservationResponseDocument) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 5 with ObservationEncoder

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

EncodingException (org.n52.svalbard.encode.exception.EncodingException)4 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)3 OmObservation (org.n52.shetland.ogc.om.OmObservation)3 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)3 ObservationEncoder (org.n52.svalbard.encode.ObservationEncoder)3 Set (java.util.Set)2 XmlObject (org.apache.xmlbeans.XmlObject)2 SupportedType (org.n52.shetland.ogc.SupportedType)2 ObservationType (org.n52.shetland.ogc.om.ObservationType)2 HashMap (java.util.HashMap)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 GetObservationByIdResponseDocument (net.opengis.sos.x20.GetObservationByIdResponseDocument)1 GetObservationByIdResponseType (net.opengis.sos.x20.GetObservationByIdResponseType)1 GetObservationResponseDocument (net.opengis.sos.x20.GetObservationResponseDocument)1 GetObservationResponseType (net.opengis.sos.x20.GetObservationResponseType)1 XmlOptions (org.apache.xmlbeans.XmlOptions)1 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)1 GetObservationResponse (org.n52.shetland.ogc.sos.response.GetObservationResponse)1 EncodingContext (org.n52.svalbard.encode.EncodingContext)1 XmlEncoderKey (org.n52.svalbard.encode.XmlEncoderKey)1