Skip to content

Commit

Permalink
Try parsing time dimension intervals to arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakarFin committed Nov 13, 2024
1 parent 34ecc62 commit 4c528ef
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.oskari.capabilities.ogc.wms;

import fi.nls.oskari.log.LogFactory;
import fi.nls.oskari.log.Logger;
import org.oskari.capabilities.TimeDimensionParser;
import org.oskari.capabilities.ogc.BoundingBox;
import org.oskari.capabilities.ogc.LayerCapabilitiesWMS;
import org.oskari.xml.XmlHelper;
Expand All @@ -14,6 +17,7 @@ public class WMSCapsParser1_3_0 extends WMSCapsParser {

public static final String ROOT_EL = "WMS_Capabilities";
public static final String VERSION = "1.3.0";
private static final Logger LOG = LogFactory.getLogger(WMSCapsParser1_3_0.class);

public static List<LayerCapabilitiesWMS> parseCapabilities(Element doc)
throws IllegalArgumentException, XMLStreamException {
Expand Down Expand Up @@ -96,7 +100,20 @@ private static String[] parseTimes(Element dimension) {
if (content.trim().isEmpty()) {
return null;
}
return content.split("\\s*,\\s*");
String[] times = content.split("\\s*,\\s*");
if (times.length == 1 && content.contains("/")) {
// We get a single time that has the / separator? Might be an interval format
// <Dimension name="time" units="ISO8601" default="2024-11-13T09:00:00Z" nearestValue="0">2024-11-13T00:00:00Z/2024-11-23T00:00:00Z/PT3H</Dimension>
try {
List<String> timeList = TimeDimensionParser.parseTimeDimensionAsStrings(content);
return timeList.toArray(new String[0]);
} catch (IllegalArgumentException e) {
// Note, if we throw the exception, none of the layers will get parsed which is bad since failing just the time dimension is not critical
// however in here we don't know what layer we are processing so it's not easy to track what the problematic layer was on logs
LOG.warn("Error parsing time dimension as interval: ", e.getMessage());
}
}
return times;
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,87 @@
"metadataId": "c041e79a-914a-5a4e-a485-9cbc506195df",
"queryable": true,
"times": [
"2024-11-13T00:00:00Z/2024-11-23T00:00:00Z/PT3H"
"2024-11-13T00:00:00Z",
"2024-11-13T03:00:00Z",
"2024-11-13T06:00:00Z",
"2024-11-13T09:00:00Z",
"2024-11-13T12:00:00Z",
"2024-11-13T15:00:00Z",
"2024-11-13T18:00:00Z",
"2024-11-13T21:00:00Z",
"2024-11-14T00:00:00Z",
"2024-11-14T03:00:00Z",
"2024-11-14T06:00:00Z",
"2024-11-14T09:00:00Z",
"2024-11-14T12:00:00Z",
"2024-11-14T15:00:00Z",
"2024-11-14T18:00:00Z",
"2024-11-14T21:00:00Z",
"2024-11-15T00:00:00Z",
"2024-11-15T03:00:00Z",
"2024-11-15T06:00:00Z",
"2024-11-15T09:00:00Z",
"2024-11-15T12:00:00Z",
"2024-11-15T15:00:00Z",
"2024-11-15T18:00:00Z",
"2024-11-15T21:00:00Z",
"2024-11-16T00:00:00Z",
"2024-11-16T03:00:00Z",
"2024-11-16T06:00:00Z",
"2024-11-16T09:00:00Z",
"2024-11-16T12:00:00Z",
"2024-11-16T15:00:00Z",
"2024-11-16T18:00:00Z",
"2024-11-16T21:00:00Z",
"2024-11-17T00:00:00Z",
"2024-11-17T03:00:00Z",
"2024-11-17T06:00:00Z",
"2024-11-17T09:00:00Z",
"2024-11-17T12:00:00Z",
"2024-11-17T15:00:00Z",
"2024-11-17T18:00:00Z",
"2024-11-17T21:00:00Z",
"2024-11-18T00:00:00Z",
"2024-11-18T03:00:00Z",
"2024-11-18T06:00:00Z",
"2024-11-18T09:00:00Z",
"2024-11-18T12:00:00Z",
"2024-11-18T15:00:00Z",
"2024-11-18T18:00:00Z",
"2024-11-18T21:00:00Z",
"2024-11-19T00:00:00Z",
"2024-11-19T03:00:00Z",
"2024-11-19T06:00:00Z",
"2024-11-19T09:00:00Z",
"2024-11-19T12:00:00Z",
"2024-11-19T15:00:00Z",
"2024-11-19T18:00:00Z",
"2024-11-19T21:00:00Z",
"2024-11-20T00:00:00Z",
"2024-11-20T03:00:00Z",
"2024-11-20T06:00:00Z",
"2024-11-20T09:00:00Z",
"2024-11-20T12:00:00Z",
"2024-11-20T15:00:00Z",
"2024-11-20T18:00:00Z",
"2024-11-20T21:00:00Z",
"2024-11-21T00:00:00Z",
"2024-11-21T03:00:00Z",
"2024-11-21T06:00:00Z",
"2024-11-21T09:00:00Z",
"2024-11-21T12:00:00Z",
"2024-11-21T15:00:00Z",
"2024-11-21T18:00:00Z",
"2024-11-21T21:00:00Z",
"2024-11-22T00:00:00Z",
"2024-11-22T03:00:00Z",
"2024-11-22T06:00:00Z",
"2024-11-22T09:00:00Z",
"2024-11-22T12:00:00Z",
"2024-11-22T15:00:00Z",
"2024-11-22T18:00:00Z",
"2024-11-22T21:00:00Z",
"2024-11-23T00:00:00Z"
],
"metadataUrl": "https://csw.open.canada.ca/geonetwork/srv/csw?service=CSW&version=2.0.2&request=GetRecordById&outputschema=csw:IsoRecord&elementsetname=full&id=c041e79a-914a-5a4e-a485-9cbc506195df",
"infoFormats": [
Expand Down

0 comments on commit 4c528ef

Please sign in to comment.