use of org.n52.shetland.ogc.swe.SweDataArray in project arctic-sea by 52North.
the class SweHelper method createSosSweDataArray.
/**
* Create {@link SweDataArray} from {@link AbstractObservationValue}
*
* @param observationValue
* The {@link AbstractObservationValue} to create
* {@link SweDataArray} from
*
* @return Created {@link SweDataArray}
*
* @throws EncodingException
* If the service does not support the {@link SweDataArray}
* creation from {@link AbstractObservationValue}
*/
public SweDataArray createSosSweDataArray(AbstractObservationValue<?> observationValue) throws EncodingException {
String observablePropertyIdentifier = observationValue.getObservableProperty();
SweDataArrayValue dataArrayValue = new SweDataArrayValue();
SweDataArray dataArray = new SweDataArray();
dataArray.setEncoding(createTextEncoding(observationValue));
dataArrayValue.setValue(dataArray);
if (observationValue instanceof SingleObservationValue) {
SingleObservationValue<?> singleValue = (SingleObservationValue<?>) observationValue;
if (singleValue.getValue() instanceof SweDataArrayValue) {
return (SweDataArray) singleValue.getValue().getValue();
} else {
dataArray.setElementType(createElementType(singleValue, observablePropertyIdentifier));
dataArrayValue.addBlock(createBlock(dataArray.getElementType(), observationValue.getPhenomenonTime(), observablePropertyIdentifier, singleValue.getValue()));
}
} else if (observationValue instanceof MultiObservationValues) {
MultiObservationValues<?> multiValue = (MultiObservationValues<?>) observationValue;
if (multiValue.getValue() instanceof SweDataArrayValue) {
return ((SweDataArrayValue) multiValue.getValue()).getValue();
} else if (multiValue.getValue() instanceof TVPValue) {
TVPValue tvpValues = (TVPValue) multiValue.getValue();
for (TimeValuePair timeValuePair : tvpValues.getValue()) {
if (timeValuePair != null && timeValuePair.getValue() != null && timeValuePair.getValue().isSetValue()) {
if (!dataArray.isSetElementTyp()) {
dataArray.setElementType(createElementType(timeValuePair, observablePropertyIdentifier));
}
List<String> newBlock = createBlock(dataArray.getElementType(), timeValuePair.getTime(), observablePropertyIdentifier, timeValuePair.getValue());
dataArrayValue.addBlock(newBlock);
}
}
}
}
return dataArray;
}
use of org.n52.shetland.ogc.swe.SweDataArray in project arctic-sea by 52North.
the class SweHelper method createSosSweDataArray.
/**
* Create {@link SweDataArray} from {@link OmObservation}
*
* @param sosObservation
* The {@link OmObservation} to create {@link SweDataArray} from
*
* @return Created {@link SweDataArray}
*
* @throws EncodingException
* If the service does not support the {@link SweDataArray}
* creation from value of {@link OmObservation}
*/
public SweDataArray createSosSweDataArray(OmObservation sosObservation) throws EncodingException {
String observablePropertyIdentifier = sosObservation.getObservationConstellation().getObservableProperty().getIdentifier();
SweDataArrayValue dataArrayValue = new SweDataArrayValue();
SweDataArray dataArray = new SweDataArray();
dataArray.setEncoding(createTextEncoding(sosObservation));
dataArrayValue.setValue(dataArray);
if (sosObservation.getValue() instanceof SingleObservationValue) {
SingleObservationValue<?> singleValue = (SingleObservationValue<?>) sosObservation.getValue();
if (singleValue.getValue() instanceof SweDataArrayValue) {
return (SweDataArray) singleValue.getValue().getValue();
} else {
dataArray.setElementType(createElementType(singleValue, observablePropertyIdentifier));
dataArrayValue.addBlock(createBlock(dataArray.getElementType(), sosObservation.getPhenomenonTime(), observablePropertyIdentifier, singleValue.getValue()));
}
} else if (sosObservation.getValue() instanceof MultiObservationValues) {
MultiObservationValues<?> multiValue = (MultiObservationValues<?>) sosObservation.getValue();
if (multiValue.getValue() instanceof SweDataArrayValue) {
return ((SweDataArrayValue) multiValue.getValue()).getValue();
} else if (multiValue.getValue() instanceof TVPValue) {
TVPValue tvpValues = (TVPValue) multiValue.getValue();
for (TimeValuePair timeValuePair : tvpValues.getValue()) {
if (timeValuePair != null && timeValuePair.getValue() != null && timeValuePair.getValue().isSetValue()) {
if (!dataArray.isSetElementTyp()) {
dataArray.setElementType(createElementType(timeValuePair, observablePropertyIdentifier));
}
List<String> newBlock = createBlock(dataArray.getElementType(), timeValuePair.getTime(), observablePropertyIdentifier, timeValuePair.getValue());
dataArrayValue.addBlock(newBlock);
}
}
}
}
return dataArray;
}
use of org.n52.shetland.ogc.swe.SweDataArray in project arctic-sea by 52North.
the class SweCommonDecoderV20 method parseAbstractDataComponent.
private SweAbstractDataComponent parseAbstractDataComponent(AbstractDataComponentType abstractDataComponent) throws DecodingException {
SweAbstractDataComponent sosAbstractDataComponent = null;
if (abstractDataComponent instanceof BooleanType) {
sosAbstractDataComponent = parseBoolean((BooleanType) abstractDataComponent);
} else if (abstractDataComponent instanceof CategoryType) {
sosAbstractDataComponent = parseCategory((CategoryType) abstractDataComponent);
} else if (abstractDataComponent instanceof CountRangeType) {
sosAbstractDataComponent = parseCountRange((CountRangeType) abstractDataComponent);
} else if (abstractDataComponent instanceof CountType) {
sosAbstractDataComponent = parseCount((CountType) abstractDataComponent);
} else if (abstractDataComponent instanceof QuantityType) {
sosAbstractDataComponent = parseQuantity((QuantityType) abstractDataComponent);
} else if (abstractDataComponent instanceof QuantityRangeType) {
sosAbstractDataComponent = parseQuantityRange((QuantityRangeType) abstractDataComponent);
} else if (abstractDataComponent instanceof TextType) {
sosAbstractDataComponent = parseText((TextType) abstractDataComponent);
} else if (abstractDataComponent instanceof TimeType) {
sosAbstractDataComponent = parseTime((TimeType) abstractDataComponent);
} else if (abstractDataComponent instanceof TimeRangeType) {
sosAbstractDataComponent = parseTimeRange((TimeRangeType) abstractDataComponent);
} else if (abstractDataComponent instanceof VectorType) {
sosAbstractDataComponent = parseVector((VectorType) abstractDataComponent);
} else if (abstractDataComponent instanceof DataRecordType) {
SweDataRecord sosDataRecord = parseDataRecord((DataRecordType) abstractDataComponent);
DataRecordDocument dataRecordDoc = DataRecordDocument.Factory.newInstance(getXmlOptions());
dataRecordDoc.setDataRecord((DataRecordType) abstractDataComponent);
sosDataRecord.setXml(dataRecordDoc.xmlText(getXmlOptions()));
sosAbstractDataComponent = sosDataRecord;
} else if (abstractDataComponent instanceof DataArrayType) {
SweDataArray sosDataArray = parseDataArray((DataArrayType) abstractDataComponent);
DataArrayDocument dataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
dataArrayDoc.setDataArray1((DataArrayType) abstractDataComponent);
sosDataArray.setXml(dataArrayDoc.xmlText(getXmlOptions()));
sosAbstractDataComponent = sosDataArray;
} else {
throw new UnsupportedDecoderXmlInputException(this, abstractDataComponent);
}
if (sosAbstractDataComponent != null) {
if (abstractDataComponent.isSetDefinition()) {
sosAbstractDataComponent.setDefinition(abstractDataComponent.getDefinition());
}
if (abstractDataComponent.isSetDescription()) {
sosAbstractDataComponent.setDescription(abstractDataComponent.getDescription());
}
if (abstractDataComponent.isSetIdentifier()) {
sosAbstractDataComponent.setIdentifier(abstractDataComponent.getIdentifier());
}
if (abstractDataComponent.isSetLabel()) {
sosAbstractDataComponent.setLabel(abstractDataComponent.getLabel());
}
}
return sosAbstractDataComponent;
}
use of org.n52.shetland.ogc.swe.SweDataArray 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.swe.SweDataArray in project arctic-sea by 52North.
the class OmEncoderv100 method addSingleObservationToResult.
// FIXME String.equals(QName) !?
private void addSingleObservationToResult(XmlObject xbResult, OmObservation sosObservation) throws EncodingException {
String observationType = sosObservation.getObservationConstellation().getObservationType();
SingleObservationValue<?> observationValue = (SingleObservationValue<?>) sosObservation.getValue();
if (observationValue.getValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) observationValue.getValue();
xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, quantityValue));
} else if (observationValue.getValue() instanceof CountValue) {
CountValue countValue = (CountValue) observationValue.getValue();
XmlInteger xbInteger = XmlInteger.Factory.newInstance(getXmlOptions());
if (countValue.getValue() != null && countValue.getValue() != Integer.MIN_VALUE) {
xbInteger.setBigIntegerValue(new BigInteger(countValue.getValue().toString()));
} else {
xbInteger.setNil();
}
xbResult.set(xbInteger);
} else if (observationValue.getValue() instanceof TextValue) {
TextValue textValue = (TextValue) observationValue.getValue();
XmlString xbString = XmlString.Factory.newInstance(getXmlOptions());
if (textValue.getValue() != null && !textValue.getValue().isEmpty()) {
xbString.setStringValue(textValue.getValue());
} else {
xbString.setNil();
}
xbResult.set(xbString);
} else if (observationValue.getValue() instanceof BooleanValue) {
BooleanValue booleanValue = (BooleanValue) observationValue.getValue();
XmlBoolean xbBoolean = XmlBoolean.Factory.newInstance(getXmlOptions());
if (booleanValue.getValue() != null) {
xbBoolean.setBooleanValue(booleanValue.getValue());
} else {
xbBoolean.setNil();
}
xbResult.set(xbBoolean);
} else if (observationValue.getValue() instanceof CategoryValue) {
CategoryValue categoryValue = (CategoryValue) observationValue.getValue();
if (categoryValue.getValue() != null && !categoryValue.getValue().isEmpty()) {
xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, categoryValue, EncodingContext.of(XmlBeansEncodingFlags.GMLID, SosConstants.OBS_ID_PREFIX + sosObservation.getObservationID())));
} else {
xbResult.setNil();
}
} else if (observationValue.getValue() instanceof GeometryValue) {
GeometryValue geometryValue = (GeometryValue) observationValue.getValue();
if (geometryValue.getValue() != null) {
xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, geometryValue.getValue(), EncodingContext.of(XmlBeansEncodingFlags.GMLID, SosConstants.OBS_ID_PREFIX + sosObservation.getObservationID())));
} else {
xbResult.setNil();
}
} else if (OmConstants.OBS_TYPE_SWE_ARRAY_OBSERVATION.equals(observationType) || OmConstants.RESULT_MODEL_OBSERVATION.getLocalPart().equals(observationType)) {
SweDataArray dataArray = sweHelper.createSosSweDataArray(sosObservation);
xbResult.set(encodeObjectToXml(SweConstants.NS_SWE_101, dataArray, EncodingContext.of(XmlBeansEncodingFlags.FOR_OBSERVATION)));
}
}
Aggregations