mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Revert changes to SimpleXpathDateFormatMetadataContributor and minor updates to PubmedDateMetadatumContributor to fix failing Pubmed integration tests.
This commit is contained in:
@@ -7,8 +7,9 @@
|
||||
*/
|
||||
package org.dspace.importer.external.metadatamapping.contributor;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
@@ -34,15 +35,15 @@ import org.jdom2.xpath.XPathFactory;
|
||||
*/
|
||||
public class SimpleXpathDateFormatMetadataContributor extends SimpleXpathMetadatumContributor {
|
||||
|
||||
private DateTimeFormatter dateFormatFrom;
|
||||
private DateTimeFormatter dateFormatTo;
|
||||
private DateFormat dateFormatFrom;
|
||||
private DateFormat dateFormatTo;
|
||||
|
||||
public void setDateFormatFrom(String dateFormatFrom) {
|
||||
this.dateFormatFrom = DateTimeFormatter.ofPattern(dateFormatFrom);
|
||||
this.dateFormatFrom = new SimpleDateFormat(dateFormatFrom);
|
||||
}
|
||||
|
||||
public void setDateFormatTo(String dateFormatTo) {
|
||||
this.dateFormatTo = DateTimeFormatter.ofPattern(dateFormatTo);
|
||||
this.dateFormatTo = new SimpleDateFormat(dateFormatTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,7 +79,7 @@ public class SimpleXpathDateFormatMetadataContributor extends SimpleXpathMetadat
|
||||
}
|
||||
try {
|
||||
dcValue.setValue(dateFormatTo.format(dateFormatFrom.parse(value)));
|
||||
} catch (DateTimeParseException e) {
|
||||
} catch (ParseException e) {
|
||||
dcValue.setValue(value);
|
||||
}
|
||||
dcValue.setElement(field.getElement());
|
||||
|
@@ -9,6 +9,8 @@
|
||||
package org.dspace.importer.external.pubmed.metadatamapping.contributor;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Year;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Collection;
|
||||
@@ -111,16 +113,20 @@ public class PubmedDateMetadatumContributor<T> implements MetadataContributor<T>
|
||||
String dateString = "";
|
||||
|
||||
DateTimeFormatter resultFormatter;
|
||||
String resultType;
|
||||
if (monthList.size() > i && dayList.size() > i) {
|
||||
dateString = yearList.get(i).getValue() + "-" + monthList.get(i).getValue() +
|
||||
"-" + dayList.get(i).getValue();
|
||||
resultFormatter = DateTimeFormatter.ISO_LOCAL_DATE;
|
||||
resultType = "DAY";
|
||||
} else if (monthList.size() > i) {
|
||||
dateString = yearList.get(i).getValue() + "-" + monthList.get(i).getValue();
|
||||
resultFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
||||
resultType = "MONTH";
|
||||
} else {
|
||||
dateString = yearList.get(i).getValue();
|
||||
resultFormatter = DateTimeFormatter.ofPattern("yyyy");
|
||||
resultType = "YEAR";
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
@@ -129,8 +135,16 @@ public class PubmedDateMetadatumContributor<T> implements MetadataContributor<T>
|
||||
String dateFormat = dateFormatsToAttempt.get(j);
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
|
||||
LocalDate date = LocalDate.parse(dateString, formatter);
|
||||
resultDateString = resultFormatter.format(date);
|
||||
if (resultType.equals("DAY")) {
|
||||
LocalDate parsedDate = LocalDate.parse(dateString, formatter);
|
||||
resultDateString = resultFormatter.format(parsedDate);
|
||||
} else if (resultType.equals("MONTH")) {
|
||||
YearMonth parsedMonth = YearMonth.parse(dateString, formatter);
|
||||
resultDateString = resultFormatter.format(parsedMonth);
|
||||
} else if (resultType.equals("YEAR")) {
|
||||
Year parsedYear = Year.parse(dateString, formatter);
|
||||
resultDateString = resultFormatter.format(parsedYear);
|
||||
}
|
||||
} catch (DateTimeParseException e) {
|
||||
// Multiple dateformats can be configured, we don't want to print the entire stacktrace every
|
||||
// time one of those formats fails.
|
||||
|
Reference in New Issue
Block a user