Search in sources :

Example 11 with TimeInstant

use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.

the class AqdEncoder method encodeGetObservationResponse.

private XmlObject encodeGetObservationResponse(GetObservationResponse response, EncodingContext ctx) throws EncodingException {
    try {
        FeatureCollection featureCollection = getFeatureCollection(response);
        // TODO get FLOW from response
        EReportingHeader eReportingHeader = getEReportingHeader(getReportObligationType(response));
        featureCollection.addMember(eReportingHeader);
        TimePeriod timePeriod = new TimePeriod();
        TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
        int counter = 1;
        ObservationStream observationCollection = response.getObservationCollection();
        while (observationCollection.hasNext()) {
            OmObservation observation = observationCollection.next();
            if (observation.getValue() instanceof ObservationStream) {
                ObservationStream value = (ObservationStream) observation.getValue();
                if (value instanceof StreamingValue) {
                    value = value.merge();
                }
                while (value.hasNext()) {
                    processObservation(value.next(), timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
                }
            } else {
                processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
            }
        }
        if (!timePeriod.isEmpty()) {
            eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
        }
        return encodeObjectToXml(GmlConstants.NS_GML_32, featureCollection, ctx.with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT));
    } catch (OwsExceptionReport ex) {
        throw new EncodingException(ex);
    }
}
Also used : FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) StreamingValue(org.n52.shetland.ogc.om.StreamingValue) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AbstractEReportingHeader(org.n52.shetland.aqd.AbstractEReportingHeader) EReportingHeader(org.n52.shetland.aqd.EReportingHeader) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) OmObservation(org.n52.shetland.ogc.om.OmObservation) Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) DateTime(org.joda.time.DateTime)

Example 12 with TimeInstant

use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.

the class AqdGetObservationResponseEncoder method create.

@Override
protected XmlObject create(GetObservationResponse response) throws EncodingException {
    try {
        FeatureCollection featureCollection = createFeatureCollection(response);
        // TODO get FLOW from response
        EReportingHeader eReportingHeader = getEReportingHeader(getReportObligationType(response));
        featureCollection.addMember(eReportingHeader);
        TimePeriod timePeriod = new TimePeriod();
        TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
        int counter = 1;
        while (response.getObservationCollection().hasNext()) {
            OmObservation observation = response.getObservationCollection().next();
            processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
        }
        if (!timePeriod.isEmpty()) {
            eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
        }
        EncodingContext ctx = EncodingContext.empty().with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT);
        return encodeGml(ctx, featureCollection);
    } catch (OwsExceptionReport ex) {
        throw new EncodingException(ex);
    }
}
Also used : FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) EncodingException(org.n52.svalbard.encode.exception.EncodingException) EReportingHeader(org.n52.shetland.aqd.EReportingHeader) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) OmObservation(org.n52.shetland.ogc.om.OmObservation) Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) DateTime(org.joda.time.DateTime)

Example 13 with TimeInstant

use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.

the class AqdGetObservationResponseEncoder method addToFeatureCollectionAndGetTimePeriod.

private TimePeriod addToFeatureCollectionAndGetTimePeriod(FeatureCollection featureCollection, GetObservationResponse response, EReportingHeader eReportingHeader) throws OwsExceptionReport {
    TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
    TimePeriod timePeriod = new TimePeriod();
    int counter = 1;
    while (response.getObservationCollection().hasNext()) {
        OmObservation observation = response.getObservationCollection().next();
        processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
    }
    return timePeriod;
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) OmObservation(org.n52.shetland.ogc.om.OmObservation) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) DateTime(org.joda.time.DateTime)

Example 14 with TimeInstant

use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.

the class SensorMLEncoderv101 method addAbstractProcessValues.

// TODO refactor/rename
private void addAbstractProcessValues(final AbstractProcessType abstractProcess, final AbstractProcess sosAbstractProcess) throws EncodingException {
    if (sosAbstractProcess.isSetGmlID()) {
        abstractProcess.setId(sosAbstractProcess.getGmlId());
    }
    if (sosAbstractProcess.isSetCapabilities()) {
        final Capabilities[] existing = abstractProcess.getCapabilitiesArray();
        final Set<String> names = Sets.newHashSetWithExpectedSize(existing.length);
        for (final Capabilities element : existing) {
            if (element.getName() != null) {
                names.add(element.getName());
            }
        }
        for (final SmlCapabilities sosCapability : sosAbstractProcess.getCapabilities()) {
            final Capabilities c = createCapability(sosCapability);
            // replace existing capability with the same name
            if (names.contains(c.getName())) {
                removeCapability(abstractProcess, c);
            }
            abstractProcess.addNewCapabilities().set(c);
        }
    }
    // set description
    if (sosAbstractProcess.isSetDescription() && !abstractProcess.isSetDescription()) {
        abstractProcess.addNewDescription().setStringValue(sosAbstractProcess.getDescription());
    }
    if (sosAbstractProcess.isSetName() && CollectionHelper.isNullOrEmpty(abstractProcess.getNameArray())) {
        // TODO check if override existing names
        addNamesToAbstractProcess(abstractProcess, sosAbstractProcess.getNames());
    }
    // set identification
    if (sosAbstractProcess.isSetIdentifications()) {
        abstractProcess.setIdentificationArray(createIdentification(sosAbstractProcess.getIdentifications()));
    }
    // set classification
    if (sosAbstractProcess.isSetClassifications()) {
        abstractProcess.setClassificationArray(createClassification(sosAbstractProcess.getClassifications()));
    }
    // set characteristics
    if (sosAbstractProcess.isSetCharacteristics()) {
        abstractProcess.setCharacteristicsArray(createCharacteristics(sosAbstractProcess.getCharacteristics()));
    }
    // set documentation
    if (sosAbstractProcess.isSetDocumentation() && CollectionHelper.isNullOrEmpty(abstractProcess.getDocumentationArray())) {
        abstractProcess.setDocumentationArray(createDocumentationArray(sosAbstractProcess.getDocumentation()));
    }
    // process
    if (sosAbstractProcess.isSetContact() && CollectionHelper.isNullOrEmpty(abstractProcess.getContactArray())) {
        ContactList contactList = createContactList(sosAbstractProcess.getContact());
        if (contactList != null && contactList.getMemberArray().length > 0) {
            abstractProcess.addNewContact().setContactList(contactList);
        }
    }
    // set keywords
    if (sosAbstractProcess.isSetKeywords()) {
        final List<String> keywords = sosAbstractProcess.getKeywords();
        final int length = abstractProcess.getKeywordsArray().length;
        for (int i = 0; i < length; ++i) {
            abstractProcess.removeKeywords(i);
        }
        abstractProcess.addNewKeywords().addNewKeywordList().setKeywordArray(keywords.toArray(new String[keywords.size()]));
    }
    if (sosAbstractProcess.isSetValidTime()) {
        if (abstractProcess.isSetValidTime()) {
            // remove existing validTime element
            final XmlCursor newCursor = abstractProcess.getValidTime().newCursor();
            newCursor.removeXml();
            newCursor.dispose();
        }
        final Time time = sosAbstractProcess.getMergedValidTime();
        final XmlObject xbtime = encodeObjectToXml(GmlConstants.NS_GML, time);
        if (time instanceof TimeInstant) {
            abstractProcess.addNewValidTime().addNewTimeInstant().set(xbtime);
        } else if (time instanceof TimePeriod) {
            abstractProcess.addNewValidTime().addNewTimePeriod().set(xbtime);
        }
    }
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) Time(org.n52.shetland.ogc.gml.time.Time) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) ContactList(net.opengis.sensorML.x101.ContactListDocument.ContactList) SmlContactList(org.n52.shetland.ogc.sensorML.SmlContactList) XmlCursor(org.apache.xmlbeans.XmlCursor) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) Capabilities(net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) XmlObject(org.apache.xmlbeans.XmlObject) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 15 with TimeInstant

use of org.n52.shetland.ogc.gml.time.TimeInstant 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)

Aggregations

TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)38 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)16 Time (org.n52.shetland.ogc.gml.time.Time)13 DateTime (org.joda.time.DateTime)12 OmObservation (org.n52.shetland.ogc.om.OmObservation)12 Test (org.junit.Test)9 XmlObject (org.apache.xmlbeans.XmlObject)7 DecodingException (org.n52.svalbard.decode.exception.DecodingException)5 EncodingException (org.n52.svalbard.encode.exception.EncodingException)5 EReportingHeader (org.n52.shetland.aqd.EReportingHeader)4 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)4 XmlString (org.apache.xmlbeans.XmlString)3 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)3 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)3 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)3 URI (java.net.URI)2 Date (java.util.Date)2 XmlCursor (org.apache.xmlbeans.XmlCursor)2 EReportingChange (org.n52.shetland.aqd.EReportingChange)2 GeographicalName (org.n52.shetland.inspire.GeographicalName)2