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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations