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;
}
Aggregations