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