use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class OmEncoderv100 method addValuesToObservation.
private List<OmObservableProperty> addValuesToObservation(ObservationType xbObs, OmObservation sosObservation, EncodingContext additionalValues) throws EncodingException {
xbObs.setId(OBSERVATION_ID_PREFIX + Long.toString(System.currentTimeMillis()));
if (!sosObservation.isSetObservationID()) {
sosObservation.setObservationID(xbObs.getId().replace(OBSERVATION_ID_PREFIX, ""));
}
String observationID = sosObservation.getObservationID();
// set samplingTime
Time samplingTime = sosObservation.getPhenomenonTime();
if (samplingTime.getGmlId() == null) {
samplingTime.setGmlId(OmConstants.PHENOMENON_TIME_NAME + "_" + observationID);
}
addSamplingTime(xbObs, samplingTime);
// set resultTime
addResultTime(xbObs, sosObservation);
// set procedure
xbObs.addNewProcedure().setHref(sosObservation.getObservationConstellation().getProcedure().getIdentifier());
// set observedProperty (phenomenon)
List<OmObservableProperty> phenComponents = null;
if (sosObservation.getObservationConstellation().getObservableProperty() instanceof OmObservableProperty) {
xbObs.addNewObservedProperty().setHref(sosObservation.getObservationConstellation().getObservableProperty().getIdentifier());
phenComponents = new ArrayList<>(1);
phenComponents.add((OmObservableProperty) sosObservation.getObservationConstellation().getObservableProperty());
} else if (sosObservation.getObservationConstellation().getObservableProperty() instanceof OmCompositePhenomenon) {
OmCompositePhenomenon compPhen = (OmCompositePhenomenon) sosObservation.getObservationConstellation().getObservableProperty();
xbObs.addNewObservedProperty().setHref(compPhen.getIdentifier());
phenComponents = compPhen.getPhenomenonComponents();
}
// set feature
addFeatureOfInterest(xbObs, sosObservation.getObservationConstellation().getFeatureOfInterest());
return phenComponents;
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class OmEncoderv100 method createOmObservation.
private XmlObject createOmObservation(OmObservation sosObservation, EncodingContext additionalValues) throws EncodingException {
ObservationDocument xbObservationDoc = ObservationDocument.Factory.newInstance(getXmlOptions());
ObservationType xbObs = xbObservationDoc.addNewObservation();
List<OmObservableProperty> phenComponents = addValuesToObservation(xbObs, sosObservation, additionalValues);
addResultToObservation(xbObs.addNewResult(), sosObservation, phenComponents);
return xbObservationDoc;
}
use of org.n52.shetland.ogc.om.OmObservation 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.OmObservation 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);
}
}
use of org.n52.shetland.ogc.om.OmObservation 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