use of org.n52.shetland.ogc.om.OmObservation 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.OmObservation in project arctic-sea by 52North.
the class ObservationDecoder method decodeJSON.
protected OmObservation decodeJSON(JsonNode node) throws DecodingException {
if (node.isObject()) {
OmObservation o = new OmObservation();
o.setIdentifier(parseIdentifier(node));
o.setValidTime(parseValidTime(node));
o.setResultTime(parseResultTime(node));
o.setValue(parseValue(node));
o.setParameter(parseParameter(node));
o.setObservationConstellation(parseObservationConstellation(node));
return o;
} else {
return null;
}
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class SosDecoderv20 method parseInsertObservation.
private OwsServiceRequest parseInsertObservation(final InsertObservationDocument insertObservationDoc) throws DecodingException {
// set namespace for default XML type (e.g. xs:string, xs:integer,
// xs:boolean, ...)
// Fix for problem with XmlBeans: namespace is not set in child elements
// when defined in root of request (SOAP)
final XmlCursor cursor = insertObservationDoc.newCursor();
if (cursor.toFirstChild() && cursor.namespaceForPrefix(W3CConstants.NS_XS_PREFIX) == null) {
cursor.prefixForNamespace(W3CConstants.NS_XS);
}
cursor.dispose();
final InsertObservationRequest insertObservationRequest = new InsertObservationRequest();
final InsertObservationType insertObservationType = insertObservationDoc.getInsertObservation();
insertObservationRequest.setService(insertObservationType.getService());
insertObservationRequest.setVersion(insertObservationType.getVersion());
if (insertObservationDoc.getInsertObservation().getOfferingArray() != null) {
insertObservationRequest.setOfferings(Arrays.asList(insertObservationType.getOfferingArray()));
}
insertObservationRequest.setExtensions(parseExtensibleRequest(insertObservationType));
if (insertObservationType.getObservationArray() != null) {
final int length = insertObservationType.getObservationArray().length;
final Map<String, Time> phenomenonTimes = new HashMap<>(length);
final Map<String, TimeInstant> resultTimes = new HashMap<>(length);
final Map<String, AbstractFeature> features = new HashMap<>(length);
CompositeException exceptions = new CompositeException();
for (final Observation observation : insertObservationType.getObservationArray()) {
final Object decodedObject = decodeXmlElement(observation.getOMObservation());
if (decodedObject instanceof OmObservation) {
final OmObservation sosObservation = (OmObservation) decodedObject;
checkAndAddPhenomenonTime(sosObservation.getPhenomenonTime(), phenomenonTimes);
checkAndAddResultTime(sosObservation.getResultTime(), resultTimes);
checkAndAddFeatures(sosObservation.getObservationConstellation().getFeatureOfInterest(), features);
insertObservationRequest.addObservation(sosObservation);
} else {
exceptions.add(new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested observation type (%s) is not supported by this server!", observation.getOMObservation().getDomNode().getNodeName()));
}
}
checkReferencedElements(insertObservationRequest.getObservations(), phenomenonTimes, resultTimes, features);
try {
exceptions.throwIfNotEmpty();
} catch (CompositeException ex) {
throw new DecodingException(ex, Sos2Constants.InsertObservationParams.observation);
}
} else {
// TODO MissingMandatoryParameterException?
throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The request does not contain an observation");
}
return insertObservationRequest;
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class OmDecoderv20 method getResult.
private ObservationValue<?> getResult(OMObservationType omObservation) throws DecodingException {
XmlObject xbResult = omObservation.getResult();
if (xbResult.schemaType() == XmlAnyTypeImpl.type) {
// Template observation for InsertResultTemplate operation
if (!xbResult.getDomNode().hasChildNodes()) {
return new SingleObservationValue<>(new NilTemplateValue());
} else {
try {
xbResult = XmlObject.Factory.parse(xbResult.xmlText().trim());
} catch (XmlException e) {
LOGGER.error("Error while parsing NamedValueValue", e);
}
}
}
if (xbResult.schemaType() == XmlBoolean.type) {
// TruthObservation
XmlBoolean xbBoolean = (XmlBoolean) xbResult;
BooleanValue booleanValue = new BooleanValue(xbBoolean.getBooleanValue());
return new SingleObservationValue<>(booleanValue);
} else if (xbResult.schemaType() == XmlInteger.type) {
// CountObservation
XmlInteger xbInteger = (XmlInteger) xbResult;
CountValue countValue = new CountValue(Integer.parseInt(xbInteger.getBigIntegerValue().toString()));
return new SingleObservationValue<>(countValue);
} else if (xbResult.schemaType() == XmlString.type) {
// TextObservation
XmlString xbString = (XmlString) xbResult;
TextValue stringValue = new TextValue(xbString.getStringValue());
return new SingleObservationValue<>(stringValue);
} else {
// result elements with other encoding like SWE_ARRAY_OBSERVATION
Object decodedObject = decodeXmlObject(xbResult);
if (decodedObject instanceof ObservationValue) {
return (ObservationValue<?>) decodedObject;
} else if (decodedObject instanceof GmlMeasureType) {
GmlMeasureType measureType = (GmlMeasureType) decodedObject;
QuantityValue quantitiyValue = new QuantityValue(measureType.getValue(), measureType.getUnit());
return new SingleObservationValue<>(quantitiyValue);
} else if (decodedObject instanceof ReferenceType) {
if (omObservation.isSetType() && omObservation.getType().isSetHref() && omObservation.getType().getHref().equals(OmConstants.OBS_TYPE_REFERENCE_OBSERVATION)) {
return new SingleObservationValue<>(new ReferenceValue((ReferenceType) decodedObject));
}
return new SingleObservationValue<>(new CategoryValue(((ReferenceType) decodedObject).getHref()));
} else if (decodedObject instanceof Geometry) {
return new SingleObservationValue<>(new GeometryValue((Geometry) decodedObject));
} else if (decodedObject instanceof AbstractGeometry) {
SingleObservationValue<Geometry> result = new SingleObservationValue<>();
result.setValue(new GeometryValue(((AbstractGeometry) decodedObject).getGeometry()));
return result;
} else if (decodedObject instanceof SweDataArray) {
return new SingleObservationValue<>(new SweDataArrayValue((SweDataArray) decodedObject));
} else if (decodedObject instanceof SweDataRecord) {
return new SingleObservationValue<>(new ComplexValue((SweDataRecord) decodedObject));
}
throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested result type '{}' is not supported by this service!", decodedObject.getClass().getSimpleName());
}
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class OmDecoderv20 method getPhenomenonTime.
private Time getPhenomenonTime(OMObservationType omObservation) throws DecodingException {
TimeObjectPropertyType phenomenonTime = omObservation.getPhenomenonTime();
if (phenomenonTime.isSetHref() && phenomenonTime.getHref().startsWith("#")) {
TimeInstant timeInstant = new TimeInstant();
timeInstant.setGmlId(phenomenonTime.getHref());
return timeInstant;
} else if (phenomenonTime.isSetNilReason() && phenomenonTime.getNilReason() instanceof String && ((String) phenomenonTime.getNilReason()).equals(IndeterminateValue.TEMPLATE.getValue())) {
return new TimeInstant(IndeterminateValue.TEMPLATE);
} else if (phenomenonTime.isSetAbstractTimeObject()) {
Object decodedObject = decodeXmlObject(phenomenonTime.getAbstractTimeObject());
if (decodedObject instanceof Time) {
return (Time) decodedObject;
}
// FIXME else
}
throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested phenomenonTime type is not supported by this service!");
}
Aggregations