Search in sources :

Example 1 with TimeInstant

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

the class TimeJSONEncoder method encodeJSON.

@Override
public JsonNode encodeJSON(Time time) {
    if (time instanceof TimeInstant) {
        TimeInstant ti = (TimeInstant) time;
        return nodeFactory().textNode(encodeTimePosition(ti.getTimePosition()));
    }
    if (time instanceof TimePeriod) {
        TimePeriod tp = (TimePeriod) time;
        ArrayNode a = nodeFactory().arrayNode();
        a.add(encodeTimePosition(tp.getStartTimePosition()));
        a.add(encodeTimePosition(tp.getEndTimePosition()));
        return a;
    } else {
        return null;
    }
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 2 with TimeInstant

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

the class CountObservationDecodingTest method testObservation.

@Test
public void testObservation() {
    assertThat(observation, is(notNullValue()));
    final String type = observation.getObservationConstellation().getObservationType();
    assertThat(type, is(equalTo(OmConstants.OBS_TYPE_COUNT_OBSERVATION)));
    final ObservationValue<?> value = observation.getValue();
    assertThat(value, is(instanceOf(SingleObservationValue.class)));
    assertThat(value.getPhenomenonTime(), is(instanceOf(TimeInstant.class)));
    TimeInstant pt = (TimeInstant) value.getPhenomenonTime();
    assertThat(pt.getValue(), is(equalTo(phenomenonTime)));
    assertThat(value.getValue(), is(instanceOf(CountValue.class)));
    CountValue v = (CountValue) value.getValue();
    assertThat(v.getValue(), is(1));
    assertThat(v.getUnit(), is(nullValue()));
}
Also used : CountValue(org.n52.shetland.ogc.om.values.CountValue) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) Test(org.junit.Test)

Example 3 with TimeInstant

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

the class TruthObservationDecodingTest method testObservation.

@Test
public void testObservation() {
    assertThat(observation, is(notNullValue()));
    final String type = observation.getObservationConstellation().getObservationType();
    assertThat(type, is(equalTo(OmConstants.OBS_TYPE_TRUTH_OBSERVATION)));
    final ObservationValue<?> value = observation.getValue();
    assertThat(value, is(instanceOf(SingleObservationValue.class)));
    assertThat(value.getPhenomenonTime(), is(instanceOf(TimeInstant.class)));
    TimeInstant pt = (TimeInstant) value.getPhenomenonTime();
    assertThat(pt.getValue(), is(equalTo(phenomenonTime)));
    assertThat(value.getValue(), is(instanceOf(BooleanValue.class)));
    BooleanValue v = (BooleanValue) value.getValue();
    assertThat(v.getValue(), is(true));
    assertThat(v.getUnit(), is(nullValue()));
}
Also used : BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) Test(org.junit.Test)

Example 4 with TimeInstant

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

the class SosDecoderv20 method parseInsertObservation.

private OwsServiceRequest parseInsertObservation(final InsertObservationDocument insertObservationDoc) throws DecodingException {
    // set namespace for default XML type (e.g. xs:string, xs:integer,
    // xs:boolean, ...)
    // Fix for problem with XmlBeans: namespace is not set in child elements
    // when defined in root of request (SOAP)
    final XmlCursor cursor = insertObservationDoc.newCursor();
    if (cursor.toFirstChild() && cursor.namespaceForPrefix(W3CConstants.NS_XS_PREFIX) == null) {
        cursor.prefixForNamespace(W3CConstants.NS_XS);
    }
    cursor.dispose();
    final InsertObservationRequest insertObservationRequest = new InsertObservationRequest();
    final InsertObservationType insertObservationType = insertObservationDoc.getInsertObservation();
    insertObservationRequest.setService(insertObservationType.getService());
    insertObservationRequest.setVersion(insertObservationType.getVersion());
    if (insertObservationDoc.getInsertObservation().getOfferingArray() != null) {
        insertObservationRequest.setOfferings(Arrays.asList(insertObservationType.getOfferingArray()));
    }
    insertObservationRequest.setExtensions(parseExtensibleRequest(insertObservationType));
    if (insertObservationType.getObservationArray() != null) {
        final int length = insertObservationType.getObservationArray().length;
        final Map<String, Time> phenomenonTimes = new HashMap<>(length);
        final Map<String, TimeInstant> resultTimes = new HashMap<>(length);
        final Map<String, AbstractFeature> features = new HashMap<>(length);
        CompositeException exceptions = new CompositeException();
        for (final Observation observation : insertObservationType.getObservationArray()) {
            final Object decodedObject = decodeXmlElement(observation.getOMObservation());
            if (decodedObject instanceof OmObservation) {
                final OmObservation sosObservation = (OmObservation) decodedObject;
                checkAndAddPhenomenonTime(sosObservation.getPhenomenonTime(), phenomenonTimes);
                checkAndAddResultTime(sosObservation.getResultTime(), resultTimes);
                checkAndAddFeatures(sosObservation.getObservationConstellation().getFeatureOfInterest(), features);
                insertObservationRequest.addObservation(sosObservation);
            } else {
                exceptions.add(new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested observation type (%s) is not supported by this server!", observation.getOMObservation().getDomNode().getNodeName()));
            }
        }
        checkReferencedElements(insertObservationRequest.getObservations(), phenomenonTimes, resultTimes, features);
        try {
            exceptions.throwIfNotEmpty();
        } catch (CompositeException ex) {
            throw new DecodingException(ex, Sos2Constants.InsertObservationParams.observation);
        }
    } else {
        // TODO MissingMandatoryParameterException?
        throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The request does not contain an observation");
    }
    return insertObservationRequest;
}
Also used : HashMap(java.util.HashMap) CompositeException(org.n52.janmayen.exception.CompositeException) OmObservation(org.n52.shetland.ogc.om.OmObservation) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) Time(org.n52.shetland.ogc.gml.time.Time) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlString(org.apache.xmlbeans.XmlString) InsertObservationType(net.opengis.sos.x20.InsertObservationType) XmlCursor(org.apache.xmlbeans.XmlCursor) InsertObservationRequest(org.n52.shetland.ogc.sos.request.InsertObservationRequest) OmObservation(org.n52.shetland.ogc.om.OmObservation) Observation(net.opengis.sos.x20.InsertObservationType.Observation) OwsServiceCommunicationObject(org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject) XmlObject(org.apache.xmlbeans.XmlObject) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 5 with TimeInstant

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

the class OmDecoderv20 method getPhenomenonTime.

private Time getPhenomenonTime(OMObservationType omObservation) throws DecodingException {
    TimeObjectPropertyType phenomenonTime = omObservation.getPhenomenonTime();
    if (phenomenonTime.isSetHref() && phenomenonTime.getHref().startsWith("#")) {
        TimeInstant timeInstant = new TimeInstant();
        timeInstant.setGmlId(phenomenonTime.getHref());
        return timeInstant;
    } else if (phenomenonTime.isSetNilReason() && phenomenonTime.getNilReason() instanceof String && ((String) phenomenonTime.getNilReason()).equals(IndeterminateValue.TEMPLATE.getValue())) {
        return new TimeInstant(IndeterminateValue.TEMPLATE);
    } else if (phenomenonTime.isSetAbstractTimeObject()) {
        Object decodedObject = decodeXmlObject(phenomenonTime.getAbstractTimeObject());
        if (decodedObject instanceof Time) {
            return (Time) decodedObject;
        }
    // FIXME else
    }
    throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested phenomenonTime type is not supported by this service!");
}
Also used : TimeObjectPropertyType(net.opengis.om.x20.TimeObjectPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) Time(org.n52.shetland.ogc.gml.time.Time) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlString(org.apache.xmlbeans.XmlString) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

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