use of org.n52.shetland.ogc.om.values.QuantityValue in project arctic-sea by 52North.
the class AbstractTimeLocationValueTripleTypeEncoder method createMeasurementTimeLocationValueTripleType.
/**
* Create a {@link MeasurementTimeLocationValueTripleType} from
* {@link TimeLocationValueTriple}
*
* @param timeLocationValueTriple
* The {@link TimeLocationValueTriple} to encode
* @return The encoded {@link TimeLocationValueTriple}
* @throws EncodingException
* If an error occurs
*/
private TimeValuePairType createMeasurementTimeLocationValueTripleType(TimeLocationValueTriple timeLocationValueTriple) throws EncodingException {
MeasurementTimeLocationValueTripleType mtlvtt = MeasurementTimeLocationValueTripleType.Factory.newInstance();
mtlvtt.addNewTime().setStringValue(getTimeString(timeLocationValueTriple.getTime()));
mtlvtt.addNewLocation().addNewPoint().set(encodeGML(timeLocationValueTriple.getLocation()));
String value = null;
if (timeLocationValueTriple.getValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) timeLocationValueTriple.getValue();
if (quantityValue.isSetValue()) {
value = quantityValue.getValue().toPlainString();
}
} else if (timeLocationValueTriple.getValue() instanceof CountValue) {
CountValue countValue = (CountValue) timeLocationValueTriple.getValue();
if (countValue.getValue() != null) {
value = Integer.toString(countValue.getValue().intValue());
}
}
if (value != null && !value.isEmpty()) {
mtlvtt.addNewValue().setStringValue(value);
} else {
mtlvtt.addNewValue().setNil();
mtlvtt.addNewMetadata().addNewTVPMeasurementMetadata().addNewNilReason().setNilReason(MISSING);
}
return mtlvtt;
}
use of org.n52.shetland.ogc.om.values.QuantityValue in project arctic-sea by 52North.
the class AbstractGmlDecoderv321 method parseNamedValueValue.
protected NamedValue<?> parseNamedValueValue(XmlObject xml) throws DecodingException {
XmlObject xmlObject = xml;
if (xmlObject.schemaType() == XmlAnyTypeImpl.type) {
try {
xmlObject = XmlObject.Factory.parse(xml.xmlText().trim());
} catch (XmlException e) {
LOGGER.error("Error while parsing NamedValueValue", e);
}
}
Object value;
if (XmlBoolean.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlBoolean) xmlObject).getBooleanValue();
} else if (XmlString.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlString) xmlObject).getStringValue();
} else if (XmlInt.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlInt) xmlObject).getIntValue();
} else if (XmlInteger.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlInteger) xmlObject).getBigIntegerValue().intValue();
} else if (XmlDouble.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlDouble) xmlObject).getDoubleValue();
} else {
value = decodeXmlObject(xmlObject);
}
if (value instanceof BooleanValue) {
NamedValue<Boolean> namedValue = new NamedValue<>();
namedValue.setValue((BooleanValue) value);
return namedValue;
} else if (value instanceof SweBoolean) {
NamedValue<Boolean> namedValue = new NamedValue<>();
namedValue.setValue(new BooleanValue(((SweBoolean) value).getValue()));
return namedValue;
} else if (value instanceof Boolean) {
NamedValue<Boolean> namedValue = new NamedValue<>();
namedValue.setValue(new BooleanValue((Boolean) value));
return namedValue;
} else if (value instanceof CategoryValue) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue((CategoryValue) value);
return namedValue;
} else if (value instanceof SweCategory) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue(new CategoryValue(((SweCategory) value).getValue(), ((SweCategory) value).getCodeSpace()));
return namedValue;
} else if (value instanceof CountValue) {
NamedValue<Integer> namedValue = new NamedValue<>();
namedValue.setValue((CountValue) value);
return namedValue;
} else if (value instanceof SweCount) {
NamedValue<Integer> namedValue = new NamedValue<>();
namedValue.setValue(new CountValue(((SweCount) value).getValue()));
return namedValue;
} else if (value instanceof Integer) {
NamedValue<Integer> namedValue = new NamedValue<>();
namedValue.setValue(new CountValue((Integer) value));
return namedValue;
} else if (value instanceof GeometryValue) {
NamedValue<Geometry> namedValue = new NamedValue<>();
namedValue.setValue((GeometryValue) value);
return namedValue;
} else if (value instanceof QuantityValue) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue((QuantityValue) value);
return namedValue;
} else if (value instanceof GmlMeasureType) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue(new QuantityValue(((GmlMeasureType) value).getValue(), ((GmlMeasureType) value).getUnit()));
return namedValue;
} else if (value instanceof SweQuantity) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue(new QuantityValue(((SweQuantity) value).getValue(), ((SweQuantity) value).getUom()));
return namedValue;
} else if (value instanceof Double) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue(new QuantityValue((Double) value));
return namedValue;
} else if (value instanceof TextValue) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue((TextValue) value);
return namedValue;
} else if (value instanceof SweText) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue(new TextValue(((SweText) value).getValue()));
return namedValue;
} else if (value instanceof String) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue(new TextValue((String) value));
return namedValue;
} else if (value instanceof AbstractGeometry) {
NamedValue<Geometry> namedValue = new NamedValue<>();
namedValue.setValue(new GeometryValue((AbstractGeometry) value));
return namedValue;
} else if (value instanceof org.n52.shetland.ogc.gml.ReferenceType) {
NamedValue<org.n52.shetland.ogc.gml.ReferenceType> namedValue = new NamedValue<>();
namedValue.setValue(new ReferenceValue((org.n52.shetland.ogc.gml.ReferenceType) value));
return namedValue;
} else if (value instanceof W3CHrefAttribute) {
NamedValue<W3CHrefAttribute> namedValue = new NamedValue<>();
namedValue.setValue(new HrefAttributeValue((W3CHrefAttribute) value));
return namedValue;
} else {
throw new UnsupportedDecoderInputException(this, xmlObject);
}
}
use of org.n52.shetland.ogc.om.values.QuantityValue in project arctic-sea by 52North.
the class GmlV321EncoderTest method throwsIllegalArgumentExceptionWhenConstructorValueNullTest.
@Test(expected = EncodingException.class)
public void throwsIllegalArgumentExceptionWhenConstructorValueNullTest() throws EncodingException {
QuantityValue quantity = new QuantityValue();
encoder.encode(quantity);
}
use of org.n52.shetland.ogc.om.values.QuantityValue in project arctic-sea by 52North.
the class GmlV321EncoderTest method isMeasureTypeValidAllSetTest.
@Test
public void isMeasureTypeValidAllSetTest() throws OwsExceptionReport, EncodingException {
QuantityValue quantity = new QuantityValue(2.2);
quantity.setUnit("cm");
XmlObject encode = encoder.encode(quantity);
assertTrue("Encoded Object is NOT valid", encode.validate());
}
use of org.n52.shetland.ogc.om.values.QuantityValue in project arctic-sea by 52North.
the class InsertObservationRequestEncoderTest method createInsertObservationRequest.
private InsertObservationRequest createInsertObservationRequest() throws InvalidSridException, ParseException {
SamplingFeature samplingFeature = new SamplingFeature(new CodeWithAuthority("test-feature-uri"));
samplingFeature.setName(new CodeType("test-feature-name"));
samplingFeature.setSampledFeatures(Arrays.asList(new SamplingFeature(new CodeWithAuthority("test-parent-feature-uri"))));
samplingFeature.setGeometry(JTSHelper.createGeometryFromWKT("POINT(52.0 42.0)", 4326));
PhysicalSystem procedure = new PhysicalSystem();
procedure.setIdentifier("test-procedure");
OmObservationConstellation observationConstellation = new OmObservationConstellation();
observationConstellation.setGmlId("o1");
observationConstellation.setObservationType(OmConstants.OBS_TYPE_MEASUREMENT);
observationConstellation.setObservableProperty(new OmObservableProperty("test-property"));
observationConstellation.setFeatureOfInterest(samplingFeature);
observationConstellation.setProcedure(procedure);
TimeInstant time = new TimeInstant(new Date(0));
QuantityValue quantity = new QuantityValue(23.0, "test-uom");
ObservationValue<?> value = new SingleObservationValue<>(time, quantity);
OmObservation omObservation = new OmObservation();
omObservation.setObservationConstellation(observationConstellation);
omObservation.setResultTime(time);
omObservation.setValue(value);
InsertObservationRequest request = new InsertObservationRequest("SOS", "2.0.0");
request.setOfferings(Arrays.asList(OFFERING_ID));
request.addObservation(omObservation);
return request;
}
Aggregations