use of org.n52.svalbard.encode.exception.EncodingException 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.svalbard.encode.exception.EncodingException 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.svalbard.encode.exception.EncodingException 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.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class GetResultTemplateResponseEncoder method createResultStructure.
private ResultStructure createResultStructure(SosResultStructure resultStructure) throws EncodingException {
// TODO move encoding to SWECommonEncoder
final DataRecordDocument dataRecordDoc;
if (resultStructure.isEncoded()) {
try {
dataRecordDoc = DataRecordDocument.Factory.parse(resultStructure.getXml().get());
} catch (XmlException ex) {
throw unsupportedResultStructure(ex);
}
} else {
XmlObject xml = encodeSwe(EncodingContext.of(XmlBeansEncodingFlags.DOCUMENT), resultStructure.get().get());
if (xml instanceof DataRecordDocument) {
dataRecordDoc = (DataRecordDocument) xml;
} else {
throw unsupportedResultStructure();
}
}
ResultStructure xbResultStructure = ResultStructure.Factory.newInstance(getXmlOptions());
xbResultStructure.addNewAbstractDataComponent().set(dataRecordDoc.getDataRecord());
XmlHelper.substituteElement(xbResultStructure.getAbstractDataComponent(), dataRecordDoc.getDataRecord());
return xbResultStructure;
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class GmlEncoderv311 method createTimePeriodType.
/**
* Creates a XML TimePeriod from the SOS time object.
*
* @param timePeriod
* SOS time object
* @param timePeriodType
* the xml time period (may be {@code null})
* @return XML TimePeriod
*
* @throws EncodingException
* if an error occurs.
*/
private TimePeriodType createTimePeriodType(TimePeriod timePeriod, TimePeriodType timePeriodType) throws EncodingException {
try {
TimePeriodType tpt;
if (timePeriodType == null) {
tpt = TimePeriodType.Factory.newInstance(getXmlOptions());
} else {
tpt = timePeriodType;
}
if (timePeriod.getGmlId() != null && !timePeriod.getGmlId().isEmpty()) {
tpt.setId(timePeriod.getGmlId());
}
tpt.setBeginPosition(createTimePositionType(timePeriod.getStartTimePosition()));
tpt.setEndPosition(createTimePositionType(timePeriod.getEndTimePosition()));
return tpt;
} catch (XmlRuntimeException | XmlValueDisconnectedException x) {
throw new EncodingException("Error while creating TimePeriod!", x);
}
}
Aggregations