From fb9b449014cc939413d50163467e041affb2dab2 Mon Sep 17 00:00:00 2001 From: Francois Prunayre Date: Mon, 30 Sep 2024 09:40:22 +0200 Subject: [PATCH] Thesaurus / Date parsing fix. 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. --- .../main/java/org/fao/geonet/kernel/Thesaurus.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/fao/geonet/kernel/Thesaurus.java b/core/src/main/java/org/fao/geonet/kernel/Thesaurus.java index efaeaf60a89..91a506b57ab 100644 --- a/core/src/main/java/org/fao/geonet/kernel/Thesaurus.java +++ b/core/src/main/java/org/fao/geonet/kernel/Thesaurus.java @@ -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: "); @@ -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; }