use of net.opengis.om.x10.ObservationCollectionDocument 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;
}
Aggregations