Skip to content

Commit

Permalink
Thesaurus / Date parsing fix.
Browse files Browse the repository at this point in the history
https://github.com/geonetwork/core-geonetwork/pull/6972/files#diff-c7548d94bdb4268915f50f66df5a90f1f7868e4fb1de2f3d2938397e202aaf2fR1057
added month and year format support. This was resolving thesaurus date
to the last matching format ie. 1st January for the default date.

This can be tested using regions thesaurus which will contains 2 dates
for the thesaurus block.
  • Loading branch information
fxprunayre committed Sep 30, 2024
1 parent cfcd829 commit fb9b449
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions core/src/main/java/org/fao/geonet/kernel/Thesaurus.java
Original file line number Diff line number Diff line change
Expand Up @@ -1064,12 +1064,11 @@ private Date parseThesaurusDate(Element dateEl) {

StringBuffer errorMsg = new StringBuffer("Error parsing the thesaurus date value: ");
errorMsg.append(dateVal);
boolean success = false;

for (SimpleDateFormat df : dfList) {
try {
thesaurusDate = df.parse(dateVal);
success = true;
return thesaurusDate;
} catch (Exception ex) {
// Ignore the exception and try next format
errorMsg.append("\n * with format: ");
Expand All @@ -1079,11 +1078,9 @@ private Date parseThesaurusDate(Element dateEl) {
}
}
// Report error if no success
if (!success) {
errorMsg.append("\nCheck thesaurus date in ");
errorMsg.append(this.fname);
Log.error(Geonet.THESAURUS_MAN, errorMsg.toString());
}
errorMsg.append("\nCheck thesaurus date in ");
errorMsg.append(this.fname);
Log.error(Geonet.THESAURUS_MAN, errorMsg.toString());
return thesaurusDate;
}

Expand Down

0 comments on commit fb9b449

Please sign in to comment.