Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into revert-7750-fixTest
Browse files Browse the repository at this point in the history
* upstream/main:
  Add more unit tests (#7638)
  Fix for issue 5804: Rewrite ACM fetcher (#7733)
  • Loading branch information
Siedlerchr committed May 21, 2021
2 parents 38ae1ac + 7196eb3 commit 3c5ad18
Show file tree
Hide file tree
Showing 12 changed files with 560 additions and 59 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- The export to MS Office XML now uses the month name for the field `Month` instead of the two digit number [forum#2685](https://discourse.jabref.org/t/export-month-as-text-not-number/2685)
- We reintroduced missing default keybindings for new entries. [#7346](https://github.com/JabRef/jabref/issues/7346) [#7439](https://github.com/JabRef/jabref/issues/7439)
- Lists of available fields are now sorted alphabetically. [#7716](https://github.com/JabRef/jabref/issues/7716)
- We rewrote the ACM fetcher to adapt to the new interface. [#5804](https://github.com/JabRef/jabref/issues/5804)
- We moved the select/collapse buttons in the unlinked files dialog into a context menu. [#7383](https://github.com/JabRef/jabref/issues/7383)

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class BibStringDiff {
private final BibtexString originalString;
private final BibtexString newString;

private BibStringDiff(BibtexString originalString, BibtexString newString) {
BibStringDiff(BibtexString originalString, BibtexString newString) {
this.originalString = originalString;
this.newString = newString;
}
Expand Down Expand Up @@ -88,4 +88,22 @@ public BibtexString getOriginalString() {
public BibtexString getNewString() {
return newString;
}

@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if ((other == null) || (getClass() != other.getClass())) {
return false;
}

BibStringDiff that = (BibStringDiff) other;
return Objects.equals(newString, that.newString) && Objects.equals(originalString, that.originalString);
}

@Override
public int hashCode() {
return Objects.hash(originalString, newString);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.logic.bibtex.comparator;

import java.util.Objects;
import java.util.Optional;

import org.jabref.model.database.BibDatabaseContext;
Expand All @@ -9,7 +10,7 @@ public class PreambleDiff {
private final String originalPreamble;
private final String newPreamble;

private PreambleDiff(String originalPreamble, String newPreamble) {
PreambleDiff(String originalPreamble, String newPreamble) {
this.originalPreamble = originalPreamble;
this.newPreamble = newPreamble;
}
Expand All @@ -31,4 +32,22 @@ public String getNewPreamble() {
public String getOriginalPreamble() {
return originalPreamble;
}

@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if ((other == null) || (getClass() != other.getClass())) {
return false;
}

PreambleDiff that = (PreambleDiff) other;
return Objects.equals(newPreamble, that.newPreamble) && Objects.equals(originalPreamble, that.originalPreamble);
}

@Override
public int hashCode() {
return Objects.hash(originalPreamble, newPreamble);
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/importer/WebFetchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.SortedSet;
import java.util.TreeSet;

import org.jabref.logic.importer.fetcher.ACMPortalFetcher;
import org.jabref.logic.importer.fetcher.ACS;
import org.jabref.logic.importer.fetcher.ApsFetcher;
import org.jabref.logic.importer.fetcher.ArXiv;
Expand Down Expand Up @@ -92,8 +93,7 @@ public static SortedSet<SearchBasedFetcher> getSearchBasedFetchers(ImportFormatP
set.add(new AstrophysicsDataSystem(importFormatPreferences));
set.add(new MathSciNet(importFormatPreferences));
set.add(new ZbMATH(importFormatPreferences));
// see https://github.com/JabRef/jabref/issues/5804
// set.add(new ACMPortalFetcher(importFormatPreferences));
set.add(new ACMPortalFetcher());
// set.add(new GoogleScholar(importFormatPreferences));
set.add(new DBLPFetcher(importFormatPreferences));
set.add(new SpringerFetcher());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
package org.jabref.logic.importer.fetcher;

import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Objects;
import java.util.Optional;

import org.jabref.logic.help.HelpFile;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.Parser;
import org.jabref.logic.importer.SearchBasedParserFetcher;
import org.jabref.logic.importer.fetcher.transformers.DefaultQueryTransformer;
import org.jabref.logic.importer.fileformat.BibtexParser;
import org.jabref.model.util.DummyFileUpdateMonitor;
import org.jabref.logic.importer.fileformat.ACMPortalParser;

import org.apache.http.client.utils.URIBuilder;
import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode;

public class ACMPortalFetcher implements SearchBasedParserFetcher {

private static final String SEARCH_URL = "https://dl.acm.org/exportformats_search.cfm";
private static final String SEARCH_URL = "https://dl.acm.org/action/doSearch";

private final ImportFormatPreferences preferences;

public ACMPortalFetcher(ImportFormatPreferences preferences) {
this.preferences = Objects.requireNonNull(preferences);
public ACMPortalFetcher() {
// website dl.acm.org requires cookies
CookieHandler.setDefault(new CookieManager());
}

@Override
Expand All @@ -38,23 +36,31 @@ public Optional<HelpFile> getHelpPage() {
return Optional.of(HelpFile.FETCHER_ACM);
}

private static String createQueryString(QueryNode query) throws FetcherException {
String queryString = new DefaultQueryTransformer().transformLuceneQuery(query).orElse("");
// Query syntax to search for an entry that matches "one" and "two" in any field is: (+one +two)
return "(%252B" + queryString.trim().replaceAll("\\s+", "%20%252B") + ")";
private static String createQueryString(QueryNode query) {
return new DefaultQueryTransformer().transformLuceneQuery(query).orElse("");
}

/**
* Constructing the url for the searchpage.
*
* @param query query node
* @return query URL
*/
@Override
public URL getURLForQuery(QueryNode luceneQuery) throws URISyntaxException, MalformedURLException, FetcherException {
public URL getURLForQuery(QueryNode query) throws URISyntaxException, MalformedURLException, FetcherException {
URIBuilder uriBuilder = new URIBuilder(SEARCH_URL);
uriBuilder.addParameter("query", createQueryString(luceneQuery)); // Search all fields
uriBuilder.addParameter("within", "owners.owner=GUIDE"); // Search within the ACM Guide to Computing Literature (encompasses the ACM Full-Text Collection)
uriBuilder.addParameter("expformat", "bibtex"); // BibTeX format
uriBuilder.addParameter("AllField", createQueryString(query));
return uriBuilder.build().toURL();
}

/**
* Gets an instance of ACMPortalParser.
*
* @return the parser which can process the results returned from the ACM Portal search page
*/
@Override
public Parser getParser() {
return new BibtexParser(preferences, new DummyFileUpdateMonitor());
return new ACMPortalParser();
}

}
Loading

0 comments on commit 3c5ad18

Please sign in to comment.