Search in sources :

Example 11 with Time

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

the class GetObservationRequestDecoderTest method hasSingleTemporalFilter.

@Test
public void hasSingleTemporalFilter() throws IOException, DecodingException {
    final GetObservationRequest req = loadSingle();
    assertThat(req.getTemporalFilters(), is(notNullValue()));
    assertThat(req.getTemporalFilters(), hasSize(1));
    assertThat(req.getTemporalFilters().get(0), is(notNullValue()));
    assertThat(req.getTemporalFilters().get(0).getOperator(), is(TimeOperator.TM_Equals));
    assertThat(req.getTemporalFilters().get(0).getValueReference(), is("om:phenomenonTime"));
    assertThat(req.getTemporalFilters().get(0).getTime(), is(instanceOf(TimePeriod.class)));
    final TimePeriod time = (TimePeriod) req.getTemporalFilters().get(0).getTime();
    assertThat(time.getStart(), is(equalTo(new DateTime(2013, 01, 01, 00, 00, 00, 00, DateTimeZone.forOffsetHours(2)))));
    assertThat(time.getEnd(), is(equalTo(new DateTime(2013, 01, 01, 01, 00, 00, 00, DateTimeZone.forOffsetHours(2)))));
}
Also used : GetObservationRequest(org.n52.shetland.ogc.sos.request.GetObservationRequest) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 12 with Time

use of org.n52.shetland.ogc.gml.time.Time 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 13 with Time

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

the class SwesDecoderv20 method parseUpdateSensorDescription.

/**
 * parses the Xmlbeans UpdateSensorDescription document to a SOS request.
 *
 * @param xbUpSenDoc
 *            UpdateSensorDescription document
 * @return SOS UpdateSensor request
 *
 * @throws DecodingException
 *             * if an error occurs.
 */
private OwsServiceRequest parseUpdateSensorDescription(final UpdateSensorDescriptionDocument xbUpSenDoc) throws DecodingException {
    final UpdateSensorRequest request = new UpdateSensorRequest();
    final UpdateSensorDescriptionType xbUpdateSensor = xbUpSenDoc.getUpdateSensorDescription();
    request.setService(xbUpdateSensor.getService());
    request.setVersion(xbUpdateSensor.getVersion());
    request.setProcedureIdentifier(xbUpdateSensor.getProcedure());
    request.setProcedureDescriptionFormat(xbUpdateSensor.getProcedureDescriptionFormat());
    // extensions
    request.setExtensions(parseExtensibleRequest(xbUpdateSensor));
    for (final Description description : xbUpdateSensor.getDescriptionArray()) {
        SensorDescriptionType sensorDescription = description.getSensorDescription();
        try {
            // TODO exception if valid time is set
            final XmlObject xmlObject = XmlObject.Factory.parse(getNodeFromNodeList(sensorDescription.getData().getDomNode().getChildNodes()));
            Decoder<?, XmlObject> decoder = getDecoder(getDecoderKey(xmlObject));
            if (decoder == null) {
                throw new DecodingException(UpdateSensorDescriptionParams.procedureDescriptionFormat, "The requested procedureDescritpionFormat is not supported!");
            }
            final Object decodedObject = decoder.decode(xmlObject);
            SosProcedureDescription<?> sosProcedureDescription = null;
            if (decodedObject instanceof SosProcedureDescription) {
                sosProcedureDescription = (SosProcedureDescription) decodedObject;
            } else if (decodedObject instanceof AbstractFeature) {
                sosProcedureDescription = new SosProcedureDescription<>((AbstractFeature) decodedObject);
            }
            if (sosProcedureDescription != null) {
                if (sensorDescription.isSetValidTime()) {
                    sosProcedureDescription.setValidTime(getValidTime(sensorDescription.getValidTime()));
                }
            }
            request.addProcedureDescriptionString(sosProcedureDescription);
        } catch (final XmlException xmle) {
            throw new DecodingException("Error while parsing procedure description of UpdateSensor request!", xmle);
        }
    }
    return request;
}
Also used : UpdateSensorDescriptionType(net.opengis.swes.x20.UpdateSensorDescriptionType) UpdateSensorRequest(org.n52.shetland.ogc.sos.request.UpdateSensorRequest) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription) Description(net.opengis.swes.x20.UpdateSensorDescriptionType.Description) XmlException(org.apache.xmlbeans.XmlException) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) OwsServiceCommunicationObject(org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject) XmlObject(org.apache.xmlbeans.XmlObject) SensorDescriptionType(net.opengis.swes.x20.SensorDescriptionType) UpdateSensorDescriptionType(net.opengis.swes.x20.UpdateSensorDescriptionType)

Example 14 with Time

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

Example 15 with Time

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

the class GmlDecoderv321 method parseTimePeriod.

/**
 * creates SOS representation of time period from XMLBeans representation of time period
 *
 * @param xbTimePeriod XMLBeans representation of time period
 *
 * @return Returns SOS representation of time period
 *
 * @throws DecodingException if the time string is invalid
 */
private Object parseTimePeriod(TimePeriodType xbTimePeriod) throws DecodingException {
    // begin position
    TimePositionType xbBeginTPT = xbTimePeriod.getBeginPosition();
    TimeInstant begin = null;
    if (xbBeginTPT != null) {
        begin = parseTimePosition(xbBeginTPT);
    } else {
        throw new DecodingException("gml:TimePeriod must contain gml:beginPosition Element with valid ISO:8601 String!");
    }
    // end position
    TimePositionType xbEndTPT = xbTimePeriod.getEndPosition();
    TimeInstant end = null;
    if (xbEndTPT != null) {
        end = parseTimePosition(xbEndTPT);
    } else {
        throw new DecodingException("gml:TimePeriod must contain gml:endPosition Element with valid ISO:8601 String!");
    }
    TimePeriod timePeriod = new TimePeriod(begin, end);
    timePeriod.setGmlId(xbTimePeriod.getId());
    return timePeriod;
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) DecodingException(org.n52.svalbard.decode.exception.DecodingException) TimePositionType(net.opengis.gml.x32.TimePositionType) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Aggregations

Time (org.n52.shetland.ogc.gml.time.Time)24 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)18 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)17 DateTime (org.joda.time.DateTime)12 Test (org.junit.Test)11 XmlObject (org.apache.xmlbeans.XmlObject)9 OmObservation (org.n52.shetland.ogc.om.OmObservation)8 DecodingException (org.n52.svalbard.decode.exception.DecodingException)7 EncodingException (org.n52.svalbard.encode.exception.EncodingException)7 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)6 TimePosition (org.n52.shetland.ogc.gml.time.TimePosition)5 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)4 XmlException (org.apache.xmlbeans.XmlException)3 XmlString (org.apache.xmlbeans.XmlString)3 EReportingHeader (org.n52.shetland.aqd.EReportingHeader)3 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)3 MultiObservationValues (org.n52.shetland.ogc.om.MultiObservationValues)3 OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)3 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)3 TimeValuePair (org.n52.shetland.ogc.om.TimeValuePair)3