Search in sources :

Example 1 with ObservationStream

use of org.n52.shetland.ogc.om.ObservationStream in project arctic-sea by 52North.

the class UVFEncoder method encodeToUvf.

private File encodeToUvf(ObservationStream observationStream, File tempDir, MediaType contentType) throws IOException, EncodingException {
    List<OmObservation> mergeObservations = mergeTotoList(observationStream);
    String ending = getLineEnding(contentType);
    String filename = getFilename(mergeObservations);
    File uvfFile = new File(tempDir, filename);
    try (Writer fw = new OutputStreamWriter(new FileOutputStream(uvfFile), "UTF-8")) {
        for (OmObservation o : mergeObservations) {
            if (o.isSetValue() && !checkForSingleObservationValue(o.getValue()) && !checkForMultiObservationValue(o.getValue())) {
                String errorMessage = String.format("The resulting values are not of numeric type " + "which is only supported by this encoder '%s'.", this.getClass().getName());
                LOGGER.error(errorMessage);
                throw new EncodingException(errorMessage);
            }
            /*
                 * HEADER: Metadata
                 */
            writeFunktionInterpretation(fw, o, ending);
            writeIndex(fw, ending);
            writeMessGroesse(fw, o, ending);
            writeMessEinheit(fw, o, ending);
            writeMessStellennummer(fw, o, ending);
            writeMessStellenname(fw, o, ending);
            /*
                 * HEADER: Lines 1 - 4
                 */
            writeLine1(fw, ending);
            TimePeriod temporalBBox = getTemporalBBoxFromObservations(mergeObservations);
            writeLine2(fw, o, temporalBBox, ending);
            writeLine3(fw, o, ending);
            writeLine4(fw, temporalBBox, ending);
            /*
                 * Observation Data
                 */
            writeObservationValue(fw, o, ending);
        }
    }
    return uvfFile;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) FileOutputStream(java.io.FileOutputStream) OmObservation(org.n52.shetland.ogc.om.OmObservation) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 2 with ObservationStream

use of org.n52.shetland.ogc.om.ObservationStream in project arctic-sea by 52North.

the class AbstractObservationResponseEncoder method encodeResponse.

@Override
protected void encodeResponse(ObjectNode json, T t) throws EncodingException {
    ArrayNode obs = json.putArray(JSONConstants.OBSERVATIONS);
    try {
        ObservationStream observationCollection = t.getObservationCollection();
        encodeObservationStream(observationCollection, obs);
    } catch (OwsExceptionReport ex) {
        throw new EncodingException(ex);
    }
}
Also used : ObservationStream(org.n52.shetland.ogc.om.ObservationStream) EncodingException(org.n52.svalbard.encode.exception.EncodingException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 3 with ObservationStream

use of org.n52.shetland.ogc.om.ObservationStream 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 4 with ObservationStream

use of org.n52.shetland.ogc.om.ObservationStream 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 5 with ObservationStream

use of org.n52.shetland.ogc.om.ObservationStream 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();
        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)

Aggregations

EncodingException (org.n52.svalbard.encode.exception.EncodingException)9 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)8 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)7 OmObservation (org.n52.shetland.ogc.om.OmObservation)7 XmlObject (org.apache.xmlbeans.XmlObject)3 DateTime (org.joda.time.DateTime)3 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)2 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)2 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)2 StreamingValue (org.n52.shetland.ogc.om.StreamingValue)2 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 NoSuchElementException (java.util.NoSuchElementException)1