diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ComplexSearchQuery.java b/src/main/java/org/jabref/logic/importer/fetcher/ComplexSearchQuery.java index ade12d2d8b9..0d1f0d39c6f 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ComplexSearchQuery.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ComplexSearchQuery.java @@ -21,8 +21,9 @@ public class ComplexSearchQuery { private final Integer toYear; private final Integer singleYear; private final String journal; + private final String doi; - private ComplexSearchQuery(List defaultField, List authors, List titlePhrases, List abstractPhrases, Integer fromYear, Integer toYear, Integer singleYear, String journal) { + private ComplexSearchQuery(List defaultField, List authors, List titlePhrases, List abstractPhrases, Integer fromYear, Integer toYear, Integer singleYear, String journal, String doi) { this.defaultField = defaultField; this.authors = authors; this.titlePhrases = titlePhrases; @@ -32,6 +33,7 @@ private ComplexSearchQuery(List defaultField, List authors, List this.toYear = toYear; this.journal = journal; this.singleYear = singleYear; + this.doi = doi; } public static ComplexSearchQuery fromTerms(List terms) { @@ -45,6 +47,7 @@ public static ComplexSearchQuery fromTerms(List terms) { case "journal" -> builder.journal(termText); case "year" -> builder.singleYear(Integer.valueOf(termText)); case "year-range" -> builder.parseYearRange(termText); + case "doi" -> builder.DOI(termText); case "default" -> builder.defaultFieldPhrase(termText); // add unknown field as default field default -> builder.defaultFieldPhrase(termText); @@ -85,6 +88,10 @@ public Optional getJournal() { return Optional.ofNullable(journal); } + public Optional getDOI() { + return Optional.ofNullable(doi); + } + public static ComplexSearchQueryBuilder builder() { return new ComplexSearchQueryBuilder(); } @@ -122,12 +129,15 @@ public boolean equals(Object o) { if (getSingleYear().isPresent() ? !getSingleYear().equals(that.getSingleYear()) : that.getSingleYear().isPresent()) { return false; } - return getJournal().isPresent() ? getJournal().equals(that.getJournal()) : !that.getJournal().isPresent(); + if (getDOI().isPresent() ? !getDOI().equals(that.getDOI()) : that.getDOI().isPresent()) { + return false; + } + return getJournal().isPresent() ? getJournal().equals(that.getJournal()) : that.getJournal().isEmpty(); } @Override public int hashCode() { - return Objects.hash(defaultField, getAuthors(), getSingleYear(), getAbstractPhrases(), getFromYear(), getToYear(), getTitlePhrases(), getJournal()); + return Objects.hash(defaultField, getAuthors(), getSingleYear(), getAbstractPhrases(), getFromYear(), getToYear(), getTitlePhrases(), getJournal(), getDOI()); } @Override @@ -138,6 +148,7 @@ public String toString() { getFromYear().ifPresent(fromYear -> stringJoiner.add(fromYear.toString())); getToYear().ifPresent(toYear -> stringJoiner.add(toYear.toString())); getJournal().ifPresent(stringJoiner::add); + getDOI().ifPresent(newElement -> stringJoiner.add("doi:" + newElement)); stringJoiner.add(String.join(" ", getTitlePhrases())) .add(String.join(" ", getDefaultFieldPhrases())) .add(String.join(" ", getAuthors())) @@ -147,11 +158,12 @@ public String toString() { } public static class ComplexSearchQueryBuilder { - private List defaultFieldPhrases = new ArrayList<>(); - private List authors = new ArrayList<>(); - private List titlePhrases = new ArrayList<>(); - private List abstractPhrases = new ArrayList<>(); + private final List defaultFieldPhrases = new ArrayList<>(); + private final List authors = new ArrayList<>(); + private final List titlePhrases = new ArrayList<>(); + private final List abstractPhrases = new ArrayList<>(); private String journal; + private String doi; private Integer fromYear; private Integer toYear; private Integer singleYear; @@ -229,6 +241,14 @@ public ComplexSearchQueryBuilder journal(String journal) { return this; } + public ComplexSearchQueryBuilder DOI(String doi) { + if (Objects.requireNonNull(doi).isBlank()) { + throw new IllegalArgumentException("Parameter must not be blank"); + } + this.doi = doi.replace("\"", ""); + return this; + } + public ComplexSearchQueryBuilder terms(Collection terms) { terms.forEach(term -> { String termText = term.text(); @@ -237,6 +257,7 @@ public ComplexSearchQueryBuilder terms(Collection terms) { case "title" -> this.titlePhrase(termText); case "abstract" -> this.abstractPhrase(termText); case "journal" -> this.journal(termText); + case "doi" -> this.DOI(termText); case "year" -> this.singleYear(Integer.valueOf(termText)); case "year-range" -> this.parseYearRange(termText); case "default" -> this.defaultFieldPhrase(termText); @@ -257,7 +278,7 @@ public ComplexSearchQuery build() throws IllegalStateException { if (textSearchFieldsAndYearFieldsAreEmpty()) { throw new IllegalStateException("At least one text field has to be set"); } - return new ComplexSearchQuery(defaultFieldPhrases, authors, titlePhrases, abstractPhrases, fromYear, toYear, singleYear, journal); + return new ComplexSearchQuery(defaultFieldPhrases, authors, titlePhrases, abstractPhrases, fromYear, toYear, singleYear, journal, doi); } void parseYearRange(String termText) { @@ -281,7 +302,7 @@ void parseYearRange(String termText) { private boolean textSearchFieldsAndYearFieldsAreEmpty() { return this.stringListIsBlank(defaultFieldPhrases) && this.stringListIsBlank(titlePhrases) && - this.stringListIsBlank(authors) && this.stringListIsBlank(abstractPhrases) && StringUtil.isBlank(journal) && yearFieldsAreEmpty(); + this.stringListIsBlank(authors) && this.stringListIsBlank(abstractPhrases) && StringUtil.isBlank(journal) && StringUtil.isBlank(doi) && yearFieldsAreEmpty(); } private boolean yearFieldsAreEmpty() { diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java index b0b326c50d5..b639c35cf5b 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java @@ -14,6 +14,7 @@ import org.jabref.logic.importer.SearchBasedFetcher; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; +import org.jabref.support.DisabledOnCIServer; import org.jabref.testutils.category.FetcherTest; import org.junit.jupiter.api.Assertions; @@ -28,6 +29,7 @@ import static org.mockito.Mockito.when; @FetcherTest +@DisabledOnCIServer("Produces to many requests on CI") public class CompositeSearchBasedFetcherTest { private static final Logger LOGGER = LoggerFactory.getLogger(CompositeSearchBasedFetcherTest.class); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java index 2124b8f73cc..7d7c39a9002 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java @@ -44,7 +44,7 @@ public class JstorFetcherTest implements SearchBasedFetcherCapabilityTest { .withCitationKey("10.1086/501484") .withField(StandardField.AUTHOR, "Johnmarshall Reeve") .withField(StandardField.TITLE, "Teachers as Facilitators: What Autonomy‐Supportive Teachers Do and Why Their Students Benefit") - .withField(StandardField.ISSN, "{00135984, 15548279") + .withField(StandardField.ISSN, "00135984, 15548279") .withField(StandardField.JOURNAL, "The Elementary School Journal") .withField(StandardField.ABSTRACT, "Abstract Students are sometimes proactive and engaged in classroom learning activities, but they are also sometimes only reactive and passive. Recognizing this, in this article I argue that students’ classroom engagement depends, in part, on the supportive quality of the classroom climate in which they learn. According to the dialectical framework within self‐determination theory, students possess inner motivational resources that classroom conditions can support or frustrate. When teachers find ways to nurture these inner resources, they adopt an autonomy‐supportive motivating style. After articulating what autonomy‐supportive teachers say and do during instruction, I discuss 3 points: teachers can learn how to be more autonomy supportive toward students; teachers most engage students when they offer high levels of both autonomy support and structure; and an autonomy‐supportive motivating style is an important element to a high‐quality teacher‐student relationship.") .withField(StandardField.PUBLISHER, "The University of Chicago Press") diff --git a/src/test/java/org/jabref/logic/importer/fetcher/TitleFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/TitleFetcherTest.java index 3a289eec9a8..9a4d229c0e2 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/TitleFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/TitleFetcherTest.java @@ -34,6 +34,7 @@ public void setUp() { bibEntryBischof2009.setField(StandardField.PUBLISHER, "{IEEE}"); bibEntryBischof2009.setField(StandardField.TITLE, "{BPELscript}: A Simplified Script Syntax for {WS}-{BPEL} 2.0"); bibEntryBischof2009.setField(StandardField.YEAR, "2009"); + bibEntryBischof2009.setField(StandardField.MONTH, "aug"); bibEntryBischof2009.setField(StandardField.DOI, "10.1109/seaa.2009.21"); }