use of org.n52.shetland.ogc.sos.response.GetObservationResponse in project arctic-sea by 52North.
the class AqdGetObservationResponseEncoder method create.
@Override
protected XmlObject create(GetObservationResponse response) throws EncodingException {
try {
FeatureCollection featureCollection = createFeatureCollection(response);
// TODO get FLOW from response
EReportingHeader eReportingHeader = getEReportingHeader(getReportObligationType(response));
featureCollection.addMember(eReportingHeader);
TimePeriod timePeriod = new TimePeriod();
TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
int counter = 1;
while (response.getObservationCollection().hasNext()) {
OmObservation observation = response.getObservationCollection().next();
processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
}
if (!timePeriod.isEmpty()) {
eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
}
EncodingContext ctx = EncodingContext.empty().with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT);
return encodeGml(ctx, featureCollection);
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
}
use of org.n52.shetland.ogc.sos.response.GetObservationResponse in project arctic-sea by 52North.
the class AqdGetObservationResponseEncoder method addToFeatureCollectionAndGetTimePeriod.
private TimePeriod addToFeatureCollectionAndGetTimePeriod(FeatureCollection featureCollection, GetObservationResponse response, EReportingHeader eReportingHeader) throws OwsExceptionReport {
TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
TimePeriod timePeriod = new TimePeriod();
int counter = 1;
while (response.getObservationCollection().hasNext()) {
OmObservation observation = response.getObservationCollection().next();
processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
}
return timePeriod;
}
use of org.n52.shetland.ogc.sos.response.GetObservationResponse in project arctic-sea by 52North.
the class AqdGetObservationResponseEncoder method create.
@Override
protected void create(GetObservationResponse response, OutputStream outputStream, EncodingContext ctx) throws EncodingException {
FeatureCollection featureCollection = createFeatureCollection(response);
EReportingHeader eReportingHeader;
TimePeriod timePeriod;
try {
eReportingHeader = getEReportingHeader(getReportObligationType(response));
featureCollection.addMember(eReportingHeader);
timePeriod = addToFeatureCollectionAndGetTimePeriod(featureCollection, response, eReportingHeader);
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
if (!timePeriod.isEmpty()) {
eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
}
try {
EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions).with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT);
new AqdGetObservationResponseXmlStreamWriter(context, outputStream, featureCollection).write();
} catch (XMLStreamException xmlse) {
throw new EncodingException("Error while writing element to stream!", xmlse);
}
}
use of org.n52.shetland.ogc.sos.response.GetObservationResponse in project arctic-sea by 52North.
the class GetObservationResponseXmlStreamWriter method writeGetObservationResponseDoc.
private void writeGetObservationResponseDoc() throws XMLStreamException, EncodingException {
start(Sos2StreamingConstants.GET_OBSERVATION_RESPONSE);
namespace(W3CConstants.NS_XLINK_PREFIX, W3CConstants.NS_XLINK);
namespace(SosConstants.NS_SOS_PREFIX, Sos2Constants.NS_SOS_20);
GetObservationResponse response = getElement();
// get observation encoder
ObservationEncoder<XmlObject, OmObservation> encoder = findObservationEncoder(response.getResponseFormat());
// write schemaLocation
schemaLocation(getSchemaLocation(encoder));
EncodingContext ctx = getContext().with(XmlEncoderFlags.ENCODE_NAMESPACE, response.getResponseFormat()).with(XmlBeansEncodingFlags.DOCUMENT).with(StreamingEncoderFlags.EMBEDDED).without(XmlBeansEncodingFlags.PROPERTY_TYPE).without(XmlBeansEncodingFlags.TYPE);
try {
ObservationStream stream = response.getObservationCollection();
if (encoder.shouldObservationsWithSameXBeMerged()) {
stream = stream.merge();
}
while (stream.hasNext()) {
OmObservation o = stream.next();
if (o.getValue() instanceof ObservationStream) {
ObservationStream value = (ObservationStream) o.getValue();
if (encoder.supportsResultStreamingForMergedValues()) {
writeObservationData(ctx, o, encoder);
} else {
while (value.hasNext()) {
writeObservationData(ctx, value.next(), encoder);
}
}
} else {
writeObservationData(ctx, o, encoder);
}
}
} catch (OwsExceptionReport owse) {
throw new EncodingException(owse);
}
end(Sos2StreamingConstants.GET_OBSERVATION_RESPONSE);
}
use of org.n52.shetland.ogc.sos.response.GetObservationResponse in project arctic-sea by 52North.
the class AbstractWmlEncoderv20 method createWmlGetObservationResponse.
/**
* Encodes a SOS GetObservationResponse to a single WaterML 2.0 observation
* or to a WaterML 1.0 ObservationCollection
*
* @param getObservationResonse
* SOS GetObservationResponse
* @return Encoded response
* @throws EncodingException
* If an error occurs
*/
protected XmlObject createWmlGetObservationResponse(GetObservationResponse getObservationResonse) throws EncodingException {
// TODO: set schemaLocation if final
Map<CodeWithAuthority, String> gmlID4sfIdentifier = Maps.newHashMap();
int sfIdCounter = 1;
try {
if (getObservationResonse.getObservationCollection() != null && !getObservationResonse.getObservationCollection().hasNext()) {
ObservationStream observations = getObservationResonse.getObservationCollection();
OmObservation observation = observations.next();
if (!observations.hasNext()) {
OMObservationDocument omObservationDoc = OMObservationDocument.Factory.newInstance(getXmlOptions());
omObservationDoc.setOMObservation(encodeObservation(observation, gmlID4sfIdentifier, sfIdCounter));
sfIdCounter++;
return omObservationDoc;
} else {
CollectionDocument xmlCollectionDoc = CollectionDocument.Factory.newInstance(getXmlOptions());
CollectionType wmlCollection = xmlCollectionDoc.addNewCollection();
wmlCollection.addNewObservationMember().setOMObservation(encodeObservation(observation, gmlID4sfIdentifier, sfIdCounter));
sfIdCounter++;
while (observations.hasNext()) {
wmlCollection.addNewObservationMember().setOMObservation(encodeObservation(observations.next(), gmlID4sfIdentifier, sfIdCounter));
sfIdCounter++;
}
return xmlCollectionDoc;
}
} else {
// TODO: HydrologieProfile-Exception
throw new EncodingException("Combination does not exists!");
}
} catch (NoSuchElementException | OwsExceptionReport e) {
throw new EncodingException(e);
}
}
Aggregations