Skip to content

Commit

Permalink
Harvester / ISO19115-3 / Better support missing metadata date info
Browse files Browse the repository at this point in the history
While harvesting, `extract-date-modified.xsl` is used to retrieve last update of the record. If empty, harvester will fail with:

```
[geonetwork.harvester] - Invalid ISO date: 
java.lang.IllegalArgumentException: Invalid ISO date: 
	at org.fao.geonet.domain.ISODate.parseDate(ISODate.java:426) ~[gn-domain-4.4.5-SNAPSHOT.jar:?]
	at org.fao.geonet.domain.ISODate.setDateAndTime(ISODate.java:239) ~[gn-domain-4.4.5-SNAPSHOT.jar:?]
	at org.fao.geonet.domain.ISODate.<init>(ISODate.java:117) ~[gn-domain-4.4.5-SNAPSHOT.jar:?]
	at org.fao.geonet.kernel.harvest.harvester.simpleurl.Aligner.addMetadata(Aligner.java:237) ~[gn-harvesters-4.4.5-SNAPSHOT.jar:?]
	at org.fao.geonet.kernel.harvest.harvester.simpleurl.Aligner.lambda$insertOrUpdate$0(Aligner.java:126) ~[gn-harvesters-4.4.5-SNAPSHOT.jar:?]
```


Fallback to now.
  • Loading branch information
fxprunayre committed Oct 9, 2024
1 parent 78f8bfc commit a0465e3
Showing 1 changed file with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,21 @@
version="2.0"
xmlns:cit="http://standards.iso.org/iso/19115/-3/cit/2.0"
xmlns:mdb="http://standards.iso.org/iso/19115/-3/mdb/2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xsl:variable name="dateFormat"
as="xs:string"
select="'[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01][ZN]'"/>

<xsl:template
match="mdb:MD_Metadata">
<xsl:variable name="revisionDate"
select="(mdb:dateInfo/cit:CI_Date
[cit:dateType/cit:CI_DateTypeCode/@codeListValue='revision']
/cit:date/*)[1]"/>
<dateStamp>
<xsl:choose>
<xsl:when test="normalize-space($revisionDate)">
<xsl:value-of select="$revisionDate"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="mdb:dateInfo/cit:CI_Date
[cit:dateType/cit:CI_DateTypeCode/@codeListValue='creation']
/cit:date/*"/>
<!-- TODO: Should we handle when no creation nor revision date
defined ? -->
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="(
mdb:dateInfo/*[cit:dateType/*/@codeListValue = 'revision']/cit:date/*[. != ''],
mdb:dateInfo/*[cit:dateType/*/@codeListValue = 'creation']/cit:date/*[. != ''],
format-dateTime(current-dateTime(), $dateFormat)
)[1]"/>
</dateStamp>
</xsl:template>
</xsl:stylesheet>

0 comments on commit a0465e3

Please sign in to comment.