Search in sources :

Example 1 with DateTimeHelper

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

Aggregations

DateTimeParseException (java.time.format.DateTimeParseException)1 Time (org.n52.shetland.ogc.gml.time.Time)1 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)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