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