Search in sources :

Example 1 with SweTimeRange

use of org.n52.shetland.ogc.swe.simpleType.SweTimeRange 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 SweTimeRange

use of org.n52.shetland.ogc.swe.simpleType.SweTimeRange 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 SweTimeRange

use of org.n52.shetland.ogc.swe.simpleType.SweTimeRange in project arctic-sea by 52North.

the class FieldDecoder method decodeTimeRange.

protected SweAbstractDataComponent decodeTimeRange(JsonNode node) throws DecodingException {
    SweTimeRange swe = new SweTimeRange();
    if (node.hasNonNull(JSONConstants.VALUE)) {
        String start = node.path(JSONConstants.VALUE).path(0).textValue();
        String end = node.path(JSONConstants.VALUE).path(1).textValue();
        swe.setValue(new RangeValue<DateTime>(parseDateTime(start), parseDateTime(end)));
    }
    return swe.setUom(node.path(JSONConstants.UOM).textValue());
}
Also used : SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) DateTime(org.joda.time.DateTime)

Example 4 with SweTimeRange

use of org.n52.shetland.ogc.swe.simpleType.SweTimeRange in project arctic-sea by 52North.

the class FieldDecoderTest method timeRange.

@Test
public void timeRange() throws DecodingException {
    ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.TIME_RANGE_TYPE).put(JSONConstants.UOM, UOM);
    SweField field = checkCommon(json, false);
    assertThat(field.getElement(), is(instanceOf(SweTimeRange.class)));
    SweTimeRange swe = (SweTimeRange) field.getElement();
    errors.checkThat(swe.getUom(), is(UOM));
    errors.checkThat(swe.getValue(), is(nullValue()));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweField(org.n52.shetland.ogc.swe.SweField) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) Test(org.junit.Test)

Example 5 with SweTimeRange

use of org.n52.shetland.ogc.swe.simpleType.SweTimeRange in project arctic-sea by 52North.

the class FieldDecoderTest method timeRangeWithValue.

@Test
public void timeRangeWithValue() throws DecodingException {
    ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.TIME_RANGE_TYPE).put(JSONConstants.UOM, UOM);
    json.putArray(JSONConstants.VALUE).add(TIME_START).add(TIME_END);
    SweField field = checkCommon(json, true);
    assertThat(field.getElement(), is(instanceOf(SweTimeRange.class)));
    SweTimeRange swe = (SweTimeRange) field.getElement();
    errors.checkThat(swe.getUom(), is(UOM));
    errors.checkThat(swe.getValue(), is(notNullValue()));
    errors.checkThat(swe.getValue().getRangeStart(), is(timeStart));
    errors.checkThat(swe.getValue().getRangeEnd(), is(timeEnd));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweField(org.n52.shetland.ogc.swe.SweField) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) Test(org.junit.Test)

Aggregations

SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)18 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)7 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)7 DateTime (org.joda.time.DateTime)6 Test (org.junit.Test)6 SweField (org.n52.shetland.ogc.swe.SweField)6 XmlObject (org.apache.xmlbeans.XmlObject)4 SweEnvelope (org.n52.shetland.ogc.swe.SweEnvelope)4 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)4 NotYetSupportedEncodingException (org.n52.svalbard.encode.exception.NotYetSupportedEncodingException)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 DataComponentPropertyType (net.opengis.swe.x101.DataComponentPropertyType)3 DataRecordType (net.opengis.swe.x101.DataRecordType)3 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)3 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)3 RangeValue (org.n52.shetland.ogc.swe.RangeValue)3 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)3 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)3 SweCategory (org.n52.shetland.ogc.swe.simpleType.SweCategory)3 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)3