use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class OmEncoderv20Test method createComplexObservation.
protected OmObservation createComplexObservation() {
DateTime now = new DateTime(DateTimeZone.UTC);
TimeInstant resultTime = new TimeInstant(now);
TimeInstant phenomenonTime = new TimeInstant(now);
TimePeriod validTime = new TimePeriod(now.minusMinutes(5), now.plusMinutes(5));
OmObservation observation = new OmObservation();
OmObservationConstellation observationConstellation = new OmObservationConstellation();
observationConstellation.setFeatureOfInterest(new SamplingFeature(new CodeWithAuthority("feature", CODE_SPACE)));
OmCompositePhenomenon observableProperty = new OmCompositePhenomenon(PARENT_OBSERVABLE_PROPERTY);
observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_1));
observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_2));
observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_3));
observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_4));
observationConstellation.setObservableProperty(observableProperty);
observationConstellation.setObservationType(OmConstants.OBS_TYPE_COMPLEX_OBSERVATION);
observationConstellation.addOffering(OFFERING);
AbstractFeature procedure = new SosProcedureDescriptionUnknownType(PROCEDURE);
// procedure.setIdentifier(new CodeWithAuthority(PROCEDURE, CODE_SPACE));
observationConstellation.setProcedure(procedure);
observation.setObservationConstellation(observationConstellation);
observation.setParameter(null);
observation.setResultTime(resultTime);
observation.setTokenSeparator(TOKEN_SEPERATOR);
observation.setTupleSeparator(TUPLE_SEPERATOR);
observation.setValidTime(validTime);
ComplexValue complexValue = new ComplexValue();
SweDataRecord sweDataRecord = new SweDataRecord();
SweQuantity sweQuantity = new SweQuantity();
sweQuantity.setDefinition(CHILD_OBSERVABLE_PROPERTY_1);
sweQuantity.setUom("unit");
sweQuantity.setValue(42.0);
sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_1_NAME, sweQuantity));
SweBoolean sweBoolean = new SweBoolean();
sweBoolean.setValue(Boolean.TRUE);
sweBoolean.setDefinition(CHILD_OBSERVABLE_PROPERTY_2);
sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_2_NAME, sweBoolean));
SweCount sweCount = new SweCount();
sweCount.setDefinition(CHILD_OBSERVABLE_PROPERTY_3);
sweCount.setValue(42);
sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_3_NAME, sweCount));
SweText sweText = new SweText();
sweText.setDefinition(CHILD_OBSERVABLE_PROPERTY_4);
sweText.setValue("42");
sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_4_NAME, sweText));
SweCategory sweCategory = new SweCategory();
sweCategory.setDefinition(CHILD_OBSERVABLE_PROPERTY_5);
sweCategory.setCodeSpace(CODE_SPACE);
sweCategory.setValue("52");
sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_5_NAME, sweCategory));
complexValue.setValue(sweDataRecord);
observation.setValue(new SingleObservationValue<>(phenomenonTime, complexValue));
return observation;
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class OmDecoderV20Test method testComplexObservation.
@Test
public void testComplexObservation() throws XmlException, DecodingException {
XmlObject xml = XmlObject.Factory.parse(getComplexObservationXml());
// FIXME
// Object decoded = CodingHelper.decodeXmlObject(xml);
Object decoded = omDecoderv20.decode(xml);
assertThat(decoded, is(instanceOf(OmObservation.class)));
OmObservation observation = (OmObservation) decoded;
assertThat(observation.getValue(), is(instanceOf(SingleObservationValue.class)));
assertThat(observation.getValue().getValue(), is(instanceOf(ComplexValue.class)));
ComplexValue value = (ComplexValue) observation.getValue().getValue();
assertThat(value.getValue(), is(notNullValue()));
SweAbstractDataRecord dataRecord = value.getValue();
assertThat(dataRecord.getFields(), hasSize(5));
SweField field1 = dataRecord.getFields().get(0);
SweField field2 = dataRecord.getFields().get(1);
SweField field3 = dataRecord.getFields().get(2);
SweField field4 = dataRecord.getFields().get(3);
SweField field5 = dataRecord.getFields().get(4);
errors.checkThat(field1.getElement().getDefinition(), is("http://example.tld/phenomenon/child/1"));
errors.checkThat(field2.getElement().getDefinition(), is("http://example.tld/phenomenon/child/2"));
errors.checkThat(field3.getElement().getDefinition(), is("http://example.tld/phenomenon/child/3"));
errors.checkThat(field4.getElement().getDefinition(), is("http://example.tld/phenomenon/child/4"));
errors.checkThat(field5.getElement().getDefinition(), is("http://example.tld/phenomenon/child/5"));
errors.checkThat(field1.getElement().getDataComponentType(), is(SweDataComponentType.Quantity));
errors.checkThat(field2.getElement().getDataComponentType(), is(SweDataComponentType.Boolean));
errors.checkThat(field3.getElement().getDataComponentType(), is(SweDataComponentType.Count));
errors.checkThat(field4.getElement().getDataComponentType(), is(SweDataComponentType.Text));
errors.checkThat(field5.getElement().getDataComponentType(), is(SweDataComponentType.Category));
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class AbstractOmV20XmlStreamWriter method writeResult.
/**
* write om:result to stream
*
* @throws XMLStreamException
* If an error occurs when writing to stream
* @throws EncodingException
* If an error occurs when creating elements to be written
*/
protected void writeResult() throws XMLStreamException, EncodingException {
OmObservation observation = getElement();
if (observation.getValue() instanceof AbstractObservationValue<?>) {
((AbstractObservationValue<?>) observation.getValue()).setValuesForResultEncoding(observation);
}
XmlObject createResult = (XmlObject) getEncoder(getEncodeNamespace().orElse(OmConstants.NS_OM_2), observation.getValue()).encode(observation.getValue());
if (createResult != null) {
if (createResult.xmlText().contains(XML_FRAGMENT)) {
XmlObject set = OMObservationType.Factory.newInstance(getXmlOptions()).addNewResult().set(createResult);
writeXmlObject(set, OmConstants.QN_OM_20_RESULT);
} else {
if (checkResult(createResult)) {
QName name = createResult.schemaType().getName();
String prefix = name.getPrefix();
if (Strings.isNullOrEmpty(prefix)) {
XmlCursor newCursor = createResult.newCursor();
prefix = newCursor.prefixForNamespace(name.getNamespaceURI());
newCursor.setAttributeText(W3CConstants.QN_XSI_TYPE, prefix + ":" + name.getLocalPart());
newCursor.dispose();
}
writeXmlObject(createResult, OmConstants.QN_OM_20_RESULT);
} else {
start(OmConstants.QN_OM_20_RESULT);
writeXmlObject(createResult, OmConstants.QN_OM_20_RESULT);
end(OmConstants.QN_OM_20_RESULT);
}
}
} else {
empty(OmConstants.QN_OM_20_RESULT);
}
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class AbstractOmV20XmlStreamWriter method writeObservableProperty.
/**
* Write om:observedProperty to stream
*
* @throws XMLStreamException
* If an error occurs when writing to stream
*/
protected void writeObservableProperty() throws XMLStreamException {
empty(OmConstants.QN_OM_20_OBSERVED_PROPERTY);
OmObservation observation = getElement();
addXlinkHrefAttr(observation.getObservationConstellation().getObservableProperty().getIdentifier());
if (observation.getObservationConstellation().getObservableProperty().isSetName() && observation.getObservationConstellation().getObservableProperty().getFirstName().isSetValue()) {
addXlinkTitleAttr(observation.getObservationConstellation().getObservableProperty().getFirstName().getValue());
}
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class AqdGetObservationResponseXmlStreamWriter method writeFeatureCollectionDoc.
private void writeFeatureCollectionDoc() throws XMLStreamException, EncodingException {
start(GmlConstants.QN_FEATURE_COLLECTION_32);
addNamespaces();
addSchemaLocations();
FeatureCollection featureCollection = getElement();
addGmlId(featureCollection.getGmlId());
TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
for (AbstractFeature abstractFeature : featureCollection.getMembers().values()) {
long start = System.currentTimeMillis();
Encoder<XmlObject, AbstractFeature> encoder = getEncoder(abstractFeature);
if (abstractFeature instanceof OmObservation) {
OmObservation observation = (OmObservation) abstractFeature;
if (observation.getValue() instanceof ObservationStream) {
try {
// start the timer task to write blank strings to avoid
// connection closing
startTimer();
ObservationStream mergeObservation = ((ObservationStream) observation.getValue()).merge();
LOGGER.debug("Observation processing requires {} ms", System.currentTimeMillis() - start);
int count = 0;
while (mergeObservation.hasNext()) {
OmObservation omObservation = mergeObservation.next();
if (abstractFeature.isSetGmlID()) {
if (count == 0) {
omObservation.setGmlId(abstractFeature.getGmlId());
} else {
omObservation.setGmlId(abstractFeature.getGmlId() + "_" + count);
}
count++;
}
omObservation.setResultTime(resultTime);
String xmlTextObservation = prepareObservation(omObservation, encoder);
// stop the timer task
stopTimer();
writeMember(xmlTextObservation);
}
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
} else {
if (encoder instanceof XmlStreamWriter) {
encoder.encode(abstractFeature, getContext());
} else {
writeMember(abstractFeature, encoder);
}
}
} else {
writeMember(abstractFeature, encoder);
}
LOGGER.debug("Writing member requires {} ms", System.currentTimeMillis() - start);
}
end(GmlConstants.QN_FEATURE_COLLECTION_32);
}
Aggregations