use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.
the class WmlTVPEncoderv20 method createMeasurementTimeseries.
/**
* Create a XML MeasurementTimeseries object from SOS observation for
* om:result
*
* @param sosObservation
* SOS observation
*
* @return XML MeasurementTimeseries object
*
* @throws CodedException
* if the encoding fails
*/
private XmlObject createMeasurementTimeseries(OmObservation sosObservation) throws OwsExceptionReport {
MeasurementTimeseriesDocument measurementTimeseriesDoc = MeasurementTimeseriesDocument.Factory.newInstance();
MeasurementTimeseriesType measurementTimeseries = measurementTimeseriesDoc.addNewMeasurementTimeseries();
measurementTimeseries.setId(TIMESERIES_ID_PREFIX + sosObservation.getObservationID());
// Default value
TimeseriesMetadata timeseriesMetadata = new MeasurementTimeseriesMetadata().setCumulative(false);
if (sosObservation.isSetValue() && sosObservation.getValue().isSetValue() && sosObservation.getValue().getValue().getClass().isAssignableFrom(TVPValue.class) && sosObservation.getObservationConstellation().isSetMetadata() && sosObservation.getObservationConstellation().getMetadata().isSetTimeseriesMetadata()) {
timeseriesMetadata = sosObservation.getObservationConstellation().getMetadata().getTimeseriesmetadata();
}
addTimeseriesMetadata(measurementTimeseries, sosObservation.getPhenomenonTime().getGmlId(), timeseriesMetadata);
TVPDefaultMetadataPropertyType xbMetaComponent = measurementTimeseries.addNewDefaultPointMetadata();
DefaultTVPMeasurementMetadataDocument xbDefMeasureMetaComponent = DefaultTVPMeasurementMetadataDocument.Factory.newInstance();
TVPMeasurementMetadataType defaultTVPMeasurementMetadata = xbDefMeasureMetaComponent.addNewDefaultTVPMeasurementMetadata();
// Default value
InterpolationType interpolationType = InterpolationType.Continuous;
if (sosObservation.isSetValue() && sosObservation.getValue().isSetValue() && sosObservation.getObservationConstellation().isSetDefaultPointMetadata() && sosObservation.getObservationConstellation().getDefaultPointMetadata().isSetDefaultTVPMeasurementMetadata() && sosObservation.getObservationConstellation().getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().isSetInterpolationType()) {
interpolationType = sosObservation.getObservationConstellation().getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().getInterpolationtype();
}
defaultTVPMeasurementMetadata.addNewInterpolationType().setHref(interpolationType.getIdentifier());
xbDefMeasureMetaComponent.getDefaultTVPMeasurementMetadata().getInterpolationType().setTitle(interpolationType.getTitle());
String unit = addValues(measurementTimeseries, sosObservation.getValue());
// set uom
if (unit != null && !unit.isEmpty()) {
defaultTVPMeasurementMetadata.addNewUom().setCode(unit);
} else {
OmObservableProperty observableProperty = (OmObservableProperty) sosObservation.getObservationConstellation().getObservableProperty();
if (observableProperty.isSetUnit()) {
defaultTVPMeasurementMetadata.addNewUom().setCode(observableProperty.getUnit());
}
}
xbMetaComponent.set(xbDefMeasureMetaComponent);
return measurementTimeseriesDoc;
}
use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.
the class WmlTVPEncoderv20 method addValues.
private String addValues(MeasurementTimeseriesType measurementTimeseries, ObservationValue<?> observationValue) throws CodedException {
String unit = null;
if (observationValue instanceof SingleObservationValue) {
SingleObservationValue<?> singleObservationValue = (SingleObservationValue<?>) observationValue;
String time = getTimeString(singleObservationValue.getPhenomenonTime());
unit = singleObservationValue.getValue().getUnit();
String value = null;
if (singleObservationValue.getValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) singleObservationValue.getValue();
if (quantityValue.isSetValue()) {
value = quantityValue.getValue().toPlainString();
}
} else if (singleObservationValue.getValue() instanceof CountValue) {
CountValue countValue = (CountValue) singleObservationValue.getValue();
if (countValue.getValue() != null) {
value = Integer.toString(countValue.getValue());
}
} else if (singleObservationValue.getValue() instanceof ProfileValue) {
ProfileValue profileValue = (ProfileValue) singleObservationValue.getValue();
if (profileValue.isSetValue()) {
if (profileValue.getValue().iterator().next().getSimpleValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) profileValue.getValue().iterator().next().getSimpleValue();
if (quantityValue.isSetValue()) {
value = Double.toString(quantityValue.getValue().doubleValue());
}
}
}
}
addValuesToMeasurementTVP(measurementTimeseries.addNewPoint().addNewMeasurementTVP(), time, value);
} else if (observationValue instanceof MultiObservationValues) {
MultiObservationValues<?> mov = (MultiObservationValues<?>) observationValue;
TVPValue tvpValue = (TVPValue) mov.getValue();
List<TimeValuePair> timeValuePairs = tvpValue.getValue();
unit = tvpValue.getUnit();
for (TimeValuePair timeValuePair : timeValuePairs) {
String time = getTimeString(timeValuePair.getTime());
String value = null;
if (timeValuePair.getValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) timeValuePair.getValue();
if (quantityValue.isSetValue()) {
value = quantityValue.getValue().toPlainString();
}
} else if (timeValuePair.getValue() instanceof ProfileValue) {
ProfileValue profileValue = (ProfileValue) timeValuePair.getValue();
if (profileValue.isSetValue()) {
if (profileValue.getValue().iterator().next().getSimpleValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) profileValue.getValue().iterator().next().getSimpleValue();
if (quantityValue.isSetValue()) {
value = Double.toString(quantityValue.getValue().doubleValue());
}
}
}
} else if (timeValuePair.getValue() instanceof CountValue) {
CountValue countValue = (CountValue) timeValuePair.getValue();
if (countValue.isSetValue()) {
value = Integer.toString(countValue.getValue());
}
} else {
throw new NoApplicableCodeException().withMessage("The types of values '%s' is not yet supported", mov.getValue().getClass().getSimpleName());
}
addValuesToMeasurementTVP(measurementTimeseries.addNewPoint().addNewMeasurementTVP(), time, value);
}
}
return unit;
}
use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.
the class InsertObservationRequestEncoderTest method shouldEncodeSwesExtensions.
@Test
public void shouldEncodeSwesExtensions() throws InvalidSridException, ParseException, EncodingException, DecodingException {
String definition = Sos2Constants.Extensions.SplitDataArrayIntoObservations.name();
boolean value = true;
SweBoolean sweBoolean = new SweBoolean();
sweBoolean.setValue(value);
sweBoolean.setDefinition(definition);
SwesExtension<SweBoolean> swesExtension = new SwesExtension<>();
swesExtension.setValue(sweBoolean);
InsertObservationRequest request = createInsertObservationRequest();
request.addExtension(swesExtension);
XmlObject encodedRequest = encoder.create(request);
encodedRequest.xmlText();
XmlHelper.validateDocument(encodedRequest);
InsertObservationType insertObservation = ((InsertObservationDocument) encodedRequest).getInsertObservation();
Assert.assertThat(insertObservation.sizeOfExtensionArray(), Is.is(1));
XmlObject xbExtension = insertObservation.getExtensionArray(0);
Assert.assertThat(xbExtension, Matchers.instanceOf(BooleanPropertyType.class));
BooleanType xbBoolean = ((BooleanPropertyType) xbExtension).getBoolean();
Assert.assertThat(xbBoolean.getDefinition(), Is.is(definition));
Assert.assertThat(xbBoolean.getValue(), Is.is(value));
// no check for observation values, because that MUST be part of OmEncoderv20Test
}
use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_simpleDatarecord_with_fieldText.
@Test
public void should_encode_simpleDatarecord_with_fieldText() throws EncodingException {
final String field1Name = "field-1";
final String field1Value = "field-1-value";
final XmlObject encode = sweCommonEncoderv101.encode(new SweSimpleDataRecord().addField(new SweField(field1Name, new SweText().setValue(field1Value))));
assertThat(encode, instanceOf(SimpleDataRecordType.class));
final SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) encode;
final AnyScalarPropertyType field1 = xbSimpleDataRecord.getFieldArray(0);
assertThat(xbSimpleDataRecord.getFieldArray().length, is(1));
assertThat(field1.isSetText(), is(TRUE));
assertThat(field1.getName(), is(field1Name));
assertThat(field1.getText().getValue(), is(field1Value));
}
use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_simpleDatarecord_with_fieldCount.
@Test
public void should_encode_simpleDatarecord_with_fieldCount() throws EncodingException {
final String name = "field-1";
final int value = 42;
final XmlObject encode = sweCommonEncoderv101.encode(new SweSimpleDataRecord().addField(new SweField(name, new SweCount().setValue(value))));
assertThat(encode, instanceOf(SimpleDataRecordType.class));
final SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) encode;
final AnyScalarPropertyType field1 = xbSimpleDataRecord.getFieldArray(0);
assertThat(xbSimpleDataRecord.getFieldArray().length, is(1));
assertThat(field1.getName(), is(name));
assertThat(field1.isSetCount(), is(TRUE));
assertThat(field1.getCount().getValue().intValue(), is(value));
}
Aggregations