use of org.n52.shetland.ogc.om.ObservationStream in project arctic-sea by 52North.
the class UVFEncoder method encodeToUvf.
private File encodeToUvf(ObservationStream observationStream, File tempDir, MediaType contentType) throws IOException, EncodingException {
List<OmObservation> mergeObservations = mergeTotoList(observationStream);
String ending = getLineEnding(contentType);
String filename = getFilename(mergeObservations);
File uvfFile = new File(tempDir, filename);
try (Writer fw = new OutputStreamWriter(new FileOutputStream(uvfFile), "UTF-8")) {
for (OmObservation o : mergeObservations) {
if (o.isSetValue() && !checkForSingleObservationValue(o.getValue()) && !checkForMultiObservationValue(o.getValue())) {
String errorMessage = String.format("The resulting values are not of numeric type " + "which is only supported by this encoder '%s'.", this.getClass().getName());
LOGGER.error(errorMessage);
throw new EncodingException(errorMessage);
}
/*
* HEADER: Metadata
*/
writeFunktionInterpretation(fw, o, ending);
writeIndex(fw, ending);
writeMessGroesse(fw, o, ending);
writeMessEinheit(fw, o, ending);
writeMessStellennummer(fw, o, ending);
writeMessStellenname(fw, o, ending);
/*
* HEADER: Lines 1 - 4
*/
writeLine1(fw, ending);
TimePeriod temporalBBox = getTemporalBBoxFromObservations(mergeObservations);
writeLine2(fw, o, temporalBBox, ending);
writeLine3(fw, o, ending);
writeLine4(fw, temporalBBox, ending);
/*
* Observation Data
*/
writeObservationValue(fw, o, ending);
}
}
return uvfFile;
}
use of org.n52.shetland.ogc.om.ObservationStream in project arctic-sea by 52North.
the class AbstractObservationResponseEncoder method encodeResponse.
@Override
protected void encodeResponse(ObjectNode json, T t) throws EncodingException {
ArrayNode obs = json.putArray(JSONConstants.OBSERVATIONS);
try {
ObservationStream observationCollection = t.getObservationCollection();
encodeObservationStream(observationCollection, obs);
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
}
use of org.n52.shetland.ogc.om.ObservationStream 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;
}
use of org.n52.shetland.ogc.om.ObservationStream 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();
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.shetland.ogc.om.ObservationStream 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();
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);
}
}
Aggregations