use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.
the class InsertSensorRequestDecoder method parseProcedureDescription.
private SosProcedureDescription<?> parseProcedureDescription(JsonNode path, String pdf) throws DecodingException {
try {
final XmlObject xb = XmlObject.Factory.parse(path.textValue());
Decoder<?, XmlObject> decoder = getProcedureDescriptionDecoder(pdf, xb);
if (decoder == null) {
throw new DecodingException(JSONConstants.PROCEDURE_DESCRIPTION_FORMAT, "The requested %s is not supported!", JSONConstants.PROCEDURE_DESCRIPTION_FORMAT);
}
Object decode = decoder.decode(xb);
if (decode instanceof SosProcedureDescription<?>) {
return (SosProcedureDescription<?>) decode;
} else if (decode instanceof AbstractFeature) {
return new SosProcedureDescription<AbstractFeature>((AbstractFeature) decode);
} else {
throw new DecodingException("The decoded element {} is not of type {}!", decode.getClass().getName(), AbstractFeature.class.getName());
}
} catch (final XmlException xmle) {
throw new DecodingException("Error while parsing procedure description of InsertSensor request!", xmle);
}
}
use of org.n52.shetland.w3c.xlink.Type 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.w3c.xlink.Type 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.w3c.xlink.Type 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!");
}
use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.
the class SensorMLDecoderV101 method parseIoComponentPropertyType.
/**
* Parses the components
*
* @param xbIoCompPropType XML components
*
* @return SOS components
*
* @throws DecodingException if an error occurs
*/
@SuppressWarnings({ "rawtypes" })
private SmlIo parseIoComponentPropertyType(final IoComponentPropertyType xbIoCompPropType) throws DecodingException {
final SmlIo sosIo = new SmlIo();
sosIo.setIoName(xbIoCompPropType.getName());
XmlObject toDecode = null;
if (xbIoCompPropType.isSetHref()) {
sosIo.setHref(xbIoCompPropType.getHref());
if (xbIoCompPropType.isSetTitle()) {
sosIo.setTitle(xbIoCompPropType.getTitle());
}
return sosIo;
}
if (xbIoCompPropType.isSetBoolean()) {
toDecode = xbIoCompPropType.getBoolean();
} else if (xbIoCompPropType.isSetCategory()) {
toDecode = xbIoCompPropType.getCategory();
} else if (xbIoCompPropType.isSetCount()) {
toDecode = xbIoCompPropType.getCount();
} else if (xbIoCompPropType.isSetCountRange()) {
toDecode = xbIoCompPropType.getCountRange();
} else if (xbIoCompPropType.isSetObservableProperty()) {
toDecode = xbIoCompPropType.getObservableProperty();
} else if (xbIoCompPropType.isSetQuantity()) {
toDecode = xbIoCompPropType.getQuantity();
} else if (xbIoCompPropType.isSetQuantityRange()) {
toDecode = xbIoCompPropType.getQuantityRange();
} else if (xbIoCompPropType.isSetText()) {
toDecode = xbIoCompPropType.getText();
} else if (xbIoCompPropType.isSetTime()) {
toDecode = xbIoCompPropType.getTime();
} else if (xbIoCompPropType.isSetTimeRange()) {
toDecode = xbIoCompPropType.getTimeRange();
} else if (xbIoCompPropType.isSetAbstractDataArray1()) {
toDecode = xbIoCompPropType.getAbstractDataArray1();
} else if (xbIoCompPropType.isSetAbstractDataRecord()) {
toDecode = xbIoCompPropType.getAbstractDataRecord();
} else {
throw new DecodingException(XmlHelper.getLocalName(xbIoCompPropType), "An 'IoComponentProperty' is not supported");
}
final Object decodedObject = decodeXmlElement(toDecode);
if (decodedObject instanceof SweAbstractDataComponent) {
sosIo.setIoValue((SweAbstractDataComponent) decodedObject);
} else {
throw new DecodingException(XmlHelper.getLocalName(xbIoCompPropType), "The 'IoComponentProperty' with type '%s' as value for '%s' is not supported.", XmlHelper.getLocalName(toDecode), XmlHelper.getLocalName(xbIoCompPropType));
}
return sosIo;
}
Aggregations