Search in sources :

Example 1 with DateTimeParseException

use of org.n52.shetland.util.DateTimeParseException 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 DateTimeParseException

use of org.n52.shetland.util.DateTimeParseException in project arctic-sea by 52North.

the class SweCommonDecoderV101 method parseAllowedTimes.

@SuppressWarnings({ "unchecked", "rawtypes" })
private SweAllowedTimes parseAllowedTimes(AllowedTimes att) throws DateTimeParseException {
    SweAllowedTimes allowedTimes = new SweAllowedTimes();
    if (att.isSetId()) {
        allowedTimes.setGmlId(att.getId());
    }
    if (CollectionHelper.isNotNullOrEmpty(att.getValueListArray())) {
        for (List list : att.getValueListArray()) {
            if (CollectionHelper.isNotEmpty(list)) {
                for (Object value : list) {
                    allowedTimes.addValue(DateTimeHelper.parseIsoString2DateTime(value.toString()));
                }
            }
        }
    }
    if (CollectionHelper.isNotNullOrEmpty(att.getIntervalArray())) {
        for (List interval : att.getIntervalArray()) {
            RangeValue<DateTime> rangeValue = new RangeValue<DateTime>();
            Iterator iterator = interval.iterator();
            if (iterator.hasNext()) {
                rangeValue.setRangeStart(DateTimeHelper.parseIsoString2DateTime(iterator.next().toString()));
            }
            if (iterator.hasNext()) {
                rangeValue.setRangeEnd(DateTimeHelper.parseIsoString2DateTime(iterator.next().toString()));
            }
            allowedTimes.addInterval(rangeValue);
        }
    }
    return allowedTimes;
}
Also used : Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) XmlObject(org.apache.xmlbeans.XmlObject) SweAllowedTimes(org.n52.shetland.ogc.swe.simpleType.SweAllowedTimes) DateTime(org.joda.time.DateTime) RangeValue(org.n52.shetland.ogc.swe.RangeValue)

Example 3 with DateTimeParseException

use of org.n52.shetland.util.DateTimeParseException in project arctic-sea by 52North.

the class SweCommonDecoderV20 method parseAllowedTimes.

@SuppressWarnings("rawtypes")
private SweAllowedTimes parseAllowedTimes(AllowedTimesType att) throws DateTimeParseException {
    SweAllowedTimes allowedTimes = new SweAllowedTimes();
    if (att.isSetId()) {
        allowedTimes.setGmlId(att.getId());
    }
    if (CollectionHelper.isNotNullOrEmpty(att.getValueArray())) {
        for (Object value : att.getValueArray()) {
            allowedTimes.addValue(DateTimeHelper.parseIsoString2DateTime(value.toString()));
        }
    }
    if (CollectionHelper.isNotNullOrEmpty(att.getIntervalArray())) {
        for (List interval : att.getIntervalArray()) {
            RangeValue<DateTime> rangeValue = new RangeValue<DateTime>();
            Iterator iterator = interval.iterator();
            if (iterator.hasNext()) {
                rangeValue.setRangeStart(DateTimeHelper.parseIsoString2DateTime(iterator.next().toString()));
            }
            if (iterator.hasNext()) {
                rangeValue.setRangeEnd(DateTimeHelper.parseIsoString2DateTime(iterator.next().toString()));
            }
            allowedTimes.addInterval(rangeValue);
        }
    }
    if (att.isSetSignificantFigures()) {
        allowedTimes.setSignificantFigures(att.getSignificantFigures());
    }
    return allowedTimes;
}
Also used : Iterator(java.util.Iterator) XmlObject(org.apache.xmlbeans.XmlObject) List(java.util.List) ArrayList(java.util.ArrayList) SweAllowedTimes(org.n52.shetland.ogc.swe.simpleType.SweAllowedTimes) DateTime(org.joda.time.DateTime) RangeValue(org.n52.shetland.ogc.swe.RangeValue)

Example 4 with DateTimeParseException

use of org.n52.shetland.util.DateTimeParseException in project arctic-sea by 52North.

the class GmlDecoderv311 method parseTimePosition.

private TimeInstant parseTimePosition(TimePositionType xbTimePosition) throws DecodingException {
    TimeInstant ti = new TimeInstant();
    String timeString = xbTimePosition.getStringValue();
    if (timeString != null && !timeString.isEmpty()) {
        try {
            // TODO better differnetiate between ISO8601 and an
            // indeterminate value
            DateTime dateTime = DateTimeHelper.parseIsoString2DateTime(timeString);
            ti.setValue(dateTime);
            ti.setRequestedTimeLength(DateTimeHelper.getTimeLengthBeforeTimeZone(timeString));
        } catch (DateTimeParseException ex) {
            ti.setIndeterminateValue(new IndeterminateValue(timeString));
        }
    }
    if (xbTimePosition.getIndeterminatePosition() != null) {
        ti.setIndeterminateValue(new IndeterminateValue(xbTimePosition.getIndeterminatePosition().toString()));
    }
    return ti;
}
Also used : DateTimeParseException(org.n52.shetland.util.DateTimeParseException) IndeterminateValue(org.n52.shetland.ogc.gml.time.IndeterminateValue) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) DateTime(org.joda.time.DateTime)

Example 5 with DateTimeParseException

use of org.n52.shetland.util.DateTimeParseException in project arctic-sea by 52North.

the class JSONDecoder method parseTimePeriod.

protected TimePeriod parseTimePeriod(JsonNode node) throws DateTimeParseException {
    if (node.isArray()) {
        ArrayNode array = (ArrayNode) node;
        String startTime = array.get(0).textValue();
        String endTime = array.get(1).textValue();
        DateTime start = parseDateTime(startTime);
        DateTime end = parseDateTime(endTime);
        return new TimePeriod(start, end);
    } else {
        return null;
    }
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) DateTime(org.joda.time.DateTime)

Aggregations

DateTime (org.joda.time.DateTime)4 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 XmlObject (org.apache.xmlbeans.XmlObject)2 IndeterminateValue (org.n52.shetland.ogc.gml.time.IndeterminateValue)2 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)2 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)2 RangeValue (org.n52.shetland.ogc.swe.RangeValue)2 SweAllowedTimes (org.n52.shetland.ogc.swe.simpleType.SweAllowedTimes)2 DateTimeParseException (org.n52.shetland.util.DateTimeParseException)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 DateTimeParseException (java.time.format.DateTimeParseException)1 Time (org.n52.shetland.ogc.gml.time.Time)1 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)1 SweField (org.n52.shetland.ogc.swe.SweField)1 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)1 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)1