Search in sources :

Example 31 with OmObservation

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;
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) ComplexValue(org.n52.shetland.ogc.om.values.ComplexValue) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) OmCompositePhenomenon(org.n52.shetland.ogc.om.OmCompositePhenomenon) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) OmObservation(org.n52.shetland.ogc.om.OmObservation) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) DateTime(org.joda.time.DateTime) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) SosProcedureDescriptionUnknownType(org.n52.shetland.ogc.sos.SosProcedureDescriptionUnknownType) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty)

Example 32 with OmObservation

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));
}
Also used : ComplexValue(org.n52.shetland.ogc.om.values.ComplexValue) SweAbstractDataRecord(org.n52.shetland.ogc.swe.SweAbstractDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) OmObservation(org.n52.shetland.ogc.om.OmObservation) XmlObject(org.apache.xmlbeans.XmlObject) XmlObject(org.apache.xmlbeans.XmlObject) Test(org.junit.Test)

Example 33 with OmObservation

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);
    }
}
Also used : AbstractObservationValue(org.n52.shetland.ogc.om.AbstractObservationValue) QName(javax.xml.namespace.QName) OmObservation(org.n52.shetland.ogc.om.OmObservation) XmlObject(org.apache.xmlbeans.XmlObject) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 34 with OmObservation

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());
    }
}
Also used : OmObservation(org.n52.shetland.ogc.om.OmObservation)

Example 35 with OmObservation

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);
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) OmObservation(org.n52.shetland.ogc.om.OmObservation) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) DateTime(org.joda.time.DateTime) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) XmlObject(org.apache.xmlbeans.XmlObject) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Aggregations

OmObservation (org.n52.shetland.ogc.om.OmObservation)32 XmlObject (org.apache.xmlbeans.XmlObject)17 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)16 Time (org.n52.shetland.ogc.gml.time.Time)15 EncodingException (org.n52.svalbard.encode.exception.EncodingException)14 DateTime (org.joda.time.DateTime)13 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)11 OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)11 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)10 XmlString (org.apache.xmlbeans.XmlString)9 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)9 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)9 MultiObservationValues (org.n52.shetland.ogc.om.MultiObservationValues)7 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)7 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)7 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)6 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)6 List (java.util.List)5 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)5 QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)5