make MergeUtils.selectOldestDate less prone to errors when receiving invalid date formats

This commit is contained in:
Claudio Atzori 2024-10-30 11:24:25 +01:00
parent 26cdc7e439
commit a877c76d70
2 changed files with 6 additions and 11 deletions

View File

@ -810,7 +810,7 @@ public class GraphCleaningFunctions extends CleaningFunctions {
return author; return author;
} }
private static Optional<String> cleanDateField(Field<String> dateofacceptance) { public static Optional<String> cleanDateField(Field<String> dateofacceptance) {
return Optional return Optional
.ofNullable(dateofacceptance) .ofNullable(dateofacceptance)
.map(Field::getValue) .map(Field::getValue)

View File

@ -654,16 +654,9 @@ public class MergeUtils {
} }
private static Field<String> selectOldestDate(Field<String> d1, Field<String> d2) { private static Field<String> selectOldestDate(Field<String> d1, Field<String> d2) {
if (d1 == null || StringUtils.isBlank(d1.getValue())) { if (!GraphCleaningFunctions.cleanDateField(d1).isPresent()) {
return d2; return d2;
} else if (d2 == null || StringUtils.isBlank(d2.getValue())) { } else if (!GraphCleaningFunctions.cleanDateField(d2).isPresent()) {
return d1;
}
if (StringUtils.contains(d1.getValue(), "null")) {
return d2;
}
if (StringUtils.contains(d2.getValue(), "null")) {
return d1; return d1;
} }
@ -715,7 +708,9 @@ public class MergeUtils {
private static String spKeyExtractor(StructuredProperty sp) { private static String spKeyExtractor(StructuredProperty sp) {
return Optional return Optional
.ofNullable(sp) .ofNullable(sp)
.map(s -> Joiner.on("||") .map(
s -> Joiner
.on("||")
.useForNull("") .useForNull("")
.join(qualifierKeyExtractor(s.getQualifier()), s.getValue())) .join(qualifierKeyExtractor(s.getQualifier()), s.getValue()))
.orElse(null); .orElse(null);