Search in sources :

Example 1 with TimePeriod

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

the class SweDataArrayValue method getPhenomenonTime.

@Override
public Time getPhenomenonTime() {
    final TimePeriod timePeriod = new TimePeriod();
    Set<Integer> dateTokenIndizes = Sets.newHashSet();
    if (getValue() != null && getValue().getElementType() != null && getValue().getEncoding() != null) {
        // get index of time token from elementtype
        if (getValue().getElementType() instanceof SweDataRecord) {
            final SweDataRecord elementType = (SweDataRecord) getValue().getElementType();
            final List<SweField> fields = elementType.getFields();
            for (int i = 0; i < fields.size(); i++) {
                final SweField sweField = fields.get(i);
                if (sweField.getElement() instanceof SweTime || sweField.getElement() instanceof SweTimeRange) {
                    if (checkFieldNameAndElementDefinition(sweField)) {
                        dateTokenIndizes.add(i);
                    }
                }
            }
        }
        if (CollectionHelper.isNotEmpty(dateTokenIndizes)) {
            for (final List<String> block : getValue().getValues()) {
                // datetimehelper to DateTime from joda time
                for (Integer index : dateTokenIndizes) {
                    String token = null;
                    try {
                        token = block.get(index);
                        final Time time = DateTimeHelper.parseIsoString2DateTime2Time(token);
                        timePeriod.extendToContain(time);
                    } catch (final DateTimeParseException dte) {
                        LOGGER.error(String.format("Could not parse ISO8601 string \"%s\"", token), dte);
                        // try next block;
                        continue;
                    }
                }
            }
        } else {
            final String errorMsg = "PhenomenonTime field could not be found in ElementType";
            LOGGER.error(errorMsg);
        }
    } else {
        final String errorMsg = String.format("Value of type \"%s\" not set correct.", SweDataArrayValue.class.getName());
        LOGGER.error(errorMsg);
    }
    return timePeriod;
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) Time(org.n52.shetland.ogc.gml.time.Time) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) DateTimeParseException(java.time.format.DateTimeParseException) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField)

Example 2 with TimePeriod

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

the class SweHelper method getPhenomenonTimeField.

private SweField getPhenomenonTimeField(Time sosTime) {
    SweAbstractUomType<?> time;
    if (sosTime instanceof TimePeriod) {
        time = new SweTimeRange();
    } else {
        time = new SweTime();
    }
    time.setDefinition(OmConstants.PHENOMENON_TIME);
    time.setUom(OmConstants.PHEN_UOM_ISO8601);
    return new SweField(OmConstants.PHENOMENON_TIME_NAME, time);
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) SweField(org.n52.shetland.ogc.swe.SweField) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange)

Example 3 with TimePeriod

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

the class UVFEncoder method encodeToUvf.

private File encodeToUvf(ObservationStream observationStream, File tempDir, MediaType contentType) throws IOException, EncodingException {
    List<OmObservation> mergeObservations = mergeTotoList(observationStream);
    String ending = getLineEnding(contentType);
    String filename = getFilename(mergeObservations);
    File uvfFile = new File(tempDir, filename);
    try (Writer fw = new OutputStreamWriter(new FileOutputStream(uvfFile), "UTF-8")) {
        for (OmObservation o : mergeObservations) {
            if (o.isSetValue() && !checkForSingleObservationValue(o.getValue()) && !checkForMultiObservationValue(o.getValue())) {
                String errorMessage = String.format("The resulting values are not of numeric type " + "which is only supported by this encoder '%s'.", this.getClass().getName());
                LOGGER.error(errorMessage);
                throw new EncodingException(errorMessage);
            }
            /*
                 * HEADER: Metadata
                 */
            writeFunktionInterpretation(fw, o, ending);
            writeIndex(fw, ending);
            writeMessGroesse(fw, o, ending);
            writeMessEinheit(fw, o, ending);
            writeMessStellennummer(fw, o, ending);
            writeMessStellenname(fw, o, ending);
            /*
                 * HEADER: Lines 1 - 4
                 */
            writeLine1(fw, ending);
            TimePeriod temporalBBox = getTemporalBBoxFromObservations(mergeObservations);
            writeLine2(fw, o, temporalBBox, ending);
            writeLine3(fw, o, ending);
            writeLine4(fw, temporalBBox, ending);
            /*
                 * Observation Data
                 */
            writeObservationValue(fw, o, ending);
        }
    }
    return uvfFile;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) FileOutputStream(java.io.FileOutputStream) OmObservation(org.n52.shetland.ogc.om.OmObservation) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 4 with TimePeriod

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

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

Aggregations

TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)33 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)16 DateTime (org.joda.time.DateTime)13 Time (org.n52.shetland.ogc.gml.time.Time)12 OmObservation (org.n52.shetland.ogc.om.OmObservation)10 EncodingException (org.n52.svalbard.encode.exception.EncodingException)8 XmlObject (org.apache.xmlbeans.XmlObject)7 Test (org.junit.Test)4 EReportingHeader (org.n52.shetland.aqd.EReportingHeader)3 ReferenceType (org.n52.shetland.ogc.gml.ReferenceType)3 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)3 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)3 DataAvailability (org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse.DataAvailability)3 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)3 SweField (org.n52.shetland.ogc.swe.SweField)3 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)3 DecodingException (org.n52.svalbard.decode.exception.DecodingException)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)2 GetObservationRequest (org.n52.shetland.ogc.sos.request.GetObservationRequest)2