Search in sources :

Example 1 with AbstractObservationResponse

use of org.n52.shetland.ogc.sos.response.AbstractObservationResponse in project SOS by 52North.

the class AbstractNetcdfEncoder method getBestFitContentType.

private MediaType getBestFitContentType(AbstractObservationResponse aor) {
    MediaType responseFormatContentType = null;
    MediaType contentType = null;
    if (aor.isSetResponseFormat()) {
        try {
            responseFormatContentType = MediaType.parse(aor.getResponseFormat());
        } catch (Exception e) {
        // nothing to do
        }
    }
    if (aor.isSetContentType()) {
        contentType = aor.getContentType();
    }
    if (responseFormatContentType != null && contentType != null) {
        if (responseFormatContentType.isCompatible(contentType)) {
            return responseFormatContentType;
        } else {
            if (getContentType().isCompatible(responseFormatContentType.withoutParameters())) {
                return responseFormatContentType;
            } else if (getContentType().isCompatible(contentType.withoutParameters())) {
                return responseFormatContentType;
            }
        }
    } else if (responseFormatContentType == null && contentType != null && getContentType().isCompatible(contentType.withoutParameters())) {
        return contentType;
    } else if (responseFormatContentType != null && contentType == null && getContentType().isCompatible(responseFormatContentType.withoutParameters())) {
        return responseFormatContentType;
    }
    return null;
}
Also used : MediaType(org.n52.janmayen.http.MediaType) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) IOException(java.io.IOException) InvalidRangeException(ucar.ma2.InvalidRangeException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 2 with AbstractObservationResponse

use of org.n52.shetland.ogc.sos.response.AbstractObservationResponse in project SOS by 52North.

the class InspireObservationResponseConverter method getKeyTypes.

private static Set<RequestResponseModifierKey> getKeyTypes() {
    Set<String> services = Sets.newHashSet(SosConstants.SOS);
    Set<String> versions = Sets.newHashSet(Sos1Constants.SERVICEVERSION, Sos2Constants.SERVICEVERSION);
    Map<AbstractObservationRequest, AbstractObservationResponse> requestResponseMap = Maps.newHashMap();
    requestResponseMap.put(new GetObservationRequest(), new GetObservationResponse());
    requestResponseMap.put(new GetObservationByIdRequest(), new GetObservationByIdResponse());
    Set<RequestResponseModifierKey> keys = Sets.newHashSet();
    for (String service : services) {
        for (String version : versions) {
            for (Entry<AbstractObservationRequest, AbstractObservationResponse> entry : requestResponseMap.entrySet()) {
                keys.add(new RequestResponseModifierKey(service, version, entry.getKey()));
                keys.add(new RequestResponseModifierKey(service, version, entry.getKey(), requestResponseMap.get(entry.getKey())));
            }
        }
    }
    return keys;
}
Also used : AbstractObservationRequest(org.n52.shetland.ogc.sos.request.AbstractObservationRequest) GetObservationRequest(org.n52.shetland.ogc.sos.request.GetObservationRequest) RequestResponseModifierKey(org.n52.iceland.convert.RequestResponseModifierKey) GetObservationResponse(org.n52.shetland.ogc.sos.response.GetObservationResponse) AbstractObservationResponse(org.n52.shetland.ogc.sos.response.AbstractObservationResponse) GetObservationByIdResponse(org.n52.shetland.ogc.sos.response.GetObservationByIdResponse) GetObservationByIdRequest(org.n52.shetland.ogc.sos.request.GetObservationByIdRequest)

Example 3 with AbstractObservationResponse

use of org.n52.shetland.ogc.sos.response.AbstractObservationResponse in project SOS by 52North.

the class SplitMergeObservations method mergeObservations.

private OwsServiceResponse mergeObservations(AbstractObservationRequest request, AbstractObservationResponse response) throws OwsExceptionReport {
    boolean checkForMergeObservationsInResponse = checkForMergeObservationsInResponse(request);
    boolean checkEncoderForMergeObservations = checkEncoderForMergeObservations(response);
    ObservationMergeIndicator indicator = ObservationMergeIndicator.sameObservationConstellation().setResultTime(includeResultTimeForMerging);
    if (checkForMergeObservationsInResponse || checkEncoderForMergeObservations) {
        ObservationStream observationStream = response.getObservationCollection().merge(indicator);
        List<OmObservation> processed = new LinkedList<>();
        while (observationStream.hasNext()) {
            OmObservation observation = observationStream.next();
            if (observation.getValue() instanceof AbstractStreaming) {
                ObservationStream valueStream = ((AbstractStreaming) observation.getValue()).merge(indicator);
                while (valueStream.hasNext()) {
                    processed.add(valueStream.next());
                }
            } else {
                processed.add(observation);
            }
        }
        response.setObservationCollection(ObservationStream.of(processed));
    }
    return response;
}
Also used : ObservationStream(org.n52.shetland.ogc.om.ObservationStream) OmObservation(org.n52.shetland.ogc.om.OmObservation) AbstractStreaming(org.n52.shetland.ogc.sos.response.AbstractStreaming) ObservationMergeIndicator(org.n52.shetland.ogc.om.ObservationMergeIndicator) LinkedList(java.util.LinkedList)

Example 4 with AbstractObservationResponse

use of org.n52.shetland.ogc.sos.response.AbstractObservationResponse in project arctic-sea by 52North.

the class UVFEncoder method encodeGetObsResponse.

private BinaryAttachmentResponse encodeGetObsResponse(AbstractObservationResponse aor) throws EncodingException {
    File tempDir = Files.createTempDir();
    BinaryAttachmentResponse response = null;
    File uvfFile = null;
    try {
        uvfFile = encodeToUvf(aor.getObservationCollection(), tempDir, identifyContentType(aor));
        response = new BinaryAttachmentResponse(Files.toByteArray(uvfFile), getContentType(), String.format(uvfFile.getName(), makeDateSafe(new DateTime(DateTimeZone.UTC))));
    } catch (IOException e) {
        throw new EncodingException("Couldn't create UVF file", e);
    } finally {
        if (uvfFile != null && !uvfFile.delete()) {
            LOGGER.warn("Temporal file '{}' was not deleted!", uvfFile.getName());
        }
        if (!tempDir.delete()) {
            LOGGER.warn("Temporal directory '{}' was not deleted!", tempDir.getName());
        }
    }
    return response;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) BinaryAttachmentResponse(org.n52.shetland.ogc.sos.response.BinaryAttachmentResponse) IOException(java.io.IOException) File(java.io.File) DateTime(org.joda.time.DateTime)

Example 5 with AbstractObservationResponse

use of org.n52.shetland.ogc.sos.response.AbstractObservationResponse in project arctic-sea by 52North.

the class OmEncoderv100 method createObservationCollection.

private XmlObject createObservationCollection(AbstractObservationResponse response) throws EncodingException {
    ObservationStream sosObservationCollectionIterable = response.getObservationCollection();
    String resultModel = response.getResultModel();
    ObservationCollectionDocument xbObservationCollectionDoc = ObservationCollectionDocument.Factory.newInstance(getXmlOptions());
    ObservationCollectionType xbObservationCollection = xbObservationCollectionDoc.addNewObservationCollection();
    xbObservationCollection.setId(SosConstants.OBS_COL_ID_PREFIX + new DateTime().getMillis());
    if (response.hasExtensions()) {
        createMetadataProperty(xbObservationCollection, response.getExtensions());
    }
    if (sosObservationCollectionIterable != null) {
        List<OmObservation> sosObservationCollection = new LinkedList<>();
        try {
            sosObservationCollectionIterable.forEachRemaining(sosObservationCollection::add);
            ReferencedEnvelope sosEnvelope = getEnvelope(sosObservationCollection);
            if (sosEnvelope.isSetEnvelope()) {
                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) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) ObservationCollectionDocument(net.opengis.om.x10.ObservationCollectionDocument) XmlObject(org.apache.xmlbeans.XmlObject) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Aggregations

OmObservation (org.n52.shetland.ogc.om.OmObservation)5 LinkedList (java.util.LinkedList)4 AbstractObservationResponse (org.n52.shetland.ogc.sos.response.AbstractObservationResponse)4 EncodingException (org.n52.svalbard.encode.exception.EncodingException)3 IOException (java.io.IOException)2 List (java.util.List)2 DateTime (org.joda.time.DateTime)2 RequestResponseModifierKey (org.n52.iceland.convert.RequestResponseModifierKey)2 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)2 StreamingValue (org.n52.shetland.ogc.om.StreamingValue)2 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1