Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some fetcher test #7225

Merged
merged 6 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> defaultField, List<String> authors, List<String> titlePhrases, List<String> abstractPhrases, Integer fromYear, Integer toYear, Integer singleYear, String journal) {
private ComplexSearchQuery(List<String> defaultField, List<String> authors, List<String> titlePhrases, List<String> abstractPhrases, Integer fromYear, Integer toYear, Integer singleYear, String journal, String doi) {
this.defaultField = defaultField;
this.authors = authors;
this.titlePhrases = titlePhrases;
Expand All @@ -32,6 +33,7 @@ private ComplexSearchQuery(List<String> defaultField, List<String> authors, List
this.toYear = toYear;
this.journal = journal;
this.singleYear = singleYear;
this.doi = doi;
}

public static ComplexSearchQuery fromTerms(List<Term> terms) {
Expand All @@ -45,6 +47,7 @@ public static ComplexSearchQuery fromTerms(List<Term> 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);
Expand Down Expand Up @@ -85,6 +88,10 @@ public Optional<String> getJournal() {
return Optional.ofNullable(journal);
}

public Optional<String> getDOI() {
return Optional.ofNullable(doi);
}

public static ComplexSearchQueryBuilder builder() {
return new ComplexSearchQueryBuilder();
}
Expand Down Expand Up @@ -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
Expand All @@ -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()))
Expand All @@ -147,11 +158,12 @@ public String toString() {
}

public static class ComplexSearchQueryBuilder {
private List<String> defaultFieldPhrases = new ArrayList<>();
private List<String> authors = new ArrayList<>();
private List<String> titlePhrases = new ArrayList<>();
private List<String> abstractPhrases = new ArrayList<>();
private final List<String> defaultFieldPhrases = new ArrayList<>();
private final List<String> authors = new ArrayList<>();
private final List<String> titlePhrases = new ArrayList<>();
private final List<String> abstractPhrases = new ArrayList<>();
private String journal;
private String doi;
private Integer fromYear;
private Integer toYear;
private Integer singleYear;
Expand Down Expand Up @@ -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<Term> terms) {
terms.forEach(term -> {
String termText = term.text();
Expand All @@ -237,6 +257,7 @@ public ComplexSearchQueryBuilder terms(Collection<Term> 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);
Expand All @@ -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) {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.jabref.testutils.category.FetcherTest;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand All @@ -28,6 +29,7 @@
import static org.mockito.Mockito.when;

@FetcherTest
@Disabled("Produces to many requests on CI")
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
public class CompositeSearchBasedFetcherTest {

private static final Logger LOGGER = LoggerFactory.getLogger(CompositeSearchBasedFetcherTest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down