Skip to content

Commit

Permalink
Merge branch 'JabRef:main' into fix-issue-10506
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyan-z authored Nov 24, 2023
2 parents a587359 + 43364b8 commit 47e2c97
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/deployment-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ jobs:
with:
java-version: 21.0.1
distribution: 'liberica'
cache: 'gradle'
- name: Clean up keychain
run: |
security delete-keychain signing_temp.keychain ${{runner.temp}}/keychain/notarization.keychain || true
Expand All @@ -85,6 +84,8 @@ jobs:
mkdir ${{runner.temp}}/keychain
security create-keychain -p jabref ${{runner.temp}}/keychain/notarization.keychain
security set-keychain-settings ${{runner.temp}}/keychain/notarization.keychain
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Prepare merged jars and modules dir (macOS)
run: ./gradlew -i -PprojVersion="${{ steps.gitversion.outputs.AssemblySemVer }}" -PprojVersionInfo="${{ steps.gitversion.outputs.InformationalVersion }}" prepareModulesDir
- name: Build dmg (macOS)
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ jobs:
with:
java-version: 21.0.1
distribution: 'liberica'
cache: 'gradle'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Prepare merged jars and modules dir (macOS)
if: (matrix.os == 'macos-latest') || (steps.checksecrets.outputs.secretspresent == 'NO')
run: ./gradlew -i -PprojVersion="${{ steps.gitversion.outputs.AssemblySemVer }}" -PprojVersionInfo="${{ steps.gitversion.outputs.InformationalVersion }}" prepareModulesDir
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/refresh-journal-lists.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ jobs:
with:
java-version: 21.0.1
distribution: 'liberica'
cache: 'gradle'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Check whether journal-list.mv can be generated (the "real" generation is done inside JabRef's build process)
run: |
./gradlew generateJournalListMV
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/tests-fetchers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ jobs:
with:
java-version: 21.0.1
distribution: 'liberica'
cache: 'gradle'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Run fetcher tests
run: ./gradlew fetcherTest
env:
Expand Down
21 changes: 14 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ jobs:
with:
java-version: 21.0.1
distribution: 'liberica'
cache: 'gradle'
- name: Run checkstyle reporter
uses: nikitasavinov/checkstyle-action@master
with:
reporter: github-pr-review
github_token: ${{ secrets.GITHUB_TOKEN }}
checkstyle_config: 'config/checkstyle/checkstyle_reviewdog.xml'
checkstyle_version: '10.3'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Run checkstyle using gradle
run: ./gradlew checkstyleMain checkstyleTest checkstyleJmh
openrewrite:
Expand All @@ -63,7 +64,8 @@ jobs:
with:
java-version: 21.0.1
distribution: 'liberica'
cache: 'gradle'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Run OpenRewrite
run: |
./gradlew rewriteDryRun
Expand All @@ -81,7 +83,8 @@ jobs:
with:
java-version: 21.0.1
distribution: 'liberica'
cache: 'gradle'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Run modernizer
run: |
# enable failing of this task if modernizer complains
Expand Down Expand Up @@ -162,7 +165,8 @@ jobs:
with:
java-version: 21.0.1
distribution: 'liberica'
cache: 'gradle'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Run tests
run: xvfb-run --auto-servernum ./gradlew check -x checkstyleJmh -x checkstyleMain -x checkstyleTest -x modernizer
env:
Expand Down Expand Up @@ -197,7 +201,8 @@ jobs:
with:
java-version: 21.0.1
distribution: 'liberica'
cache: 'gradle'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Run tests on PostgreSQL
run: ./gradlew databaseTest --rerun-tasks
env:
Expand Down Expand Up @@ -234,7 +239,8 @@ jobs:
with:
java-version: 21.0.1
distribution: 'liberica'
cache: 'gradle'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Run GUI tests
run: xvfb-run --auto-servernum ./gradlew guiTest
env:
Expand Down Expand Up @@ -278,7 +284,8 @@ jobs:
with:
java-version: 21.0.1
distribution: 'liberica'
cache: 'gradle'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Update test coverage metrics
if: (github.ref == 'refs/heads/main') && (steps.checksecrets.outputs.secretspresent == 'YES')
run: xvfb-run --auto-servernum ./gradlew jacocoTestReport
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ processResources {
"astrophysicsDataSystemAPIKey": System.getenv('AstrophysicsDataSystemAPIKey') ? System.getenv('AstrophysicsDataSystemAPIKey') : '',
"ieeeAPIKey": System.getenv('IEEEAPIKey') ? System.getenv('IEEEAPIKey') : '',
"scienceDirectApiKey": System.getenv('SCIENCEDIRECTAPIKEY') ? System.getenv('SCIENCEDIRECTAPIKEY') : '',
"biodiversityHeritageApiKey": System.getenv('BiodiversityHeritageApiKey') ? System.getenv('BiodiversityHeritageApiKey') : ''
"biodiversityHeritageApiKey": System.getenv('BiodiversityHeritageApiKey') ? System.getenv('BiodiversityHeritageApiKey') : '',
"semanticScholarApiKey": System.getenv('SemanticScholarApiKey') ? System.getenv("SemanticScholarApiKey") : ''
)
filteringCharset = 'UTF-8'
}
Expand Down
21 changes: 11 additions & 10 deletions docs/code-howtos/fetchers.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ parent: Code Howtos

Fetchers are the implementation of the [search using online services](https://docs.jabref.org/collect/import-using-online-bibliographic-database). Some fetchers require API keys to get them working. To get the fetchers running in a JabRef development setup, the keys need to be placed in the respective environment variable. The following table lists the respective fetchers, where to get the key from and the environment variable where the key has to be placed.

| Service | Key Source | Environment Variable | Rate Limit |
|:-----------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|--------------------------------|----------------------------------|
| [IEEEXplore](https://docs.jabref.org/collect/import-using-online-bibliographic-database#ieeexplore) | [IEEE Xplore API portal](https://developer.ieee.org) | `IEEEAPIKey` | 200 calls/day |
| [MathSciNet](http://www.ams.org/mathscinet) | (none) | (none) | Depending on the current network |
| [SAO/NASA Astrophysics Data System](https://docs.jabref.org/collect/import-using-online-bibliographic-database#sao-nasa-astrophysics-data-system) | [ADS UI](https://ui.adsabs.harvard.edu/user/settings/token) | `AstrophysicsDataSystemAPIKey` | 5000 calls/day |
| [ScienceDirect](https://www.sciencedirect.com) | | `ScienceDirectApiKey` | |
| [Springer Nature](https://docs.jabref.org/collect/import-using-online-bibliographic-database#springer) | [Springer Nature API Portal](https://dev.springernature.com) | `SpringerNatureAPIKey` | 5000 calls/day |
| [Zentralblatt Math](https://www.zbmath.org) | (none) | (none) | Depending on the current network |
| [Biodiversity Heritage Library](https://www.biodiversitylibrary.org/) | [Biodiversitylibrary](https://about.biodiversitylibrary.org/tools-and-services/developer-and-data-tools/#APIs) | `BiodiversityHeritageApiKey` | - |
| Service | Key Source | Environment Variable | Rate Limit |
|:--------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|--------------------------------|----------------------------------|
| [IEEEXplore](https://docs.jabref.org/collect/import-using-online-bibliographic-database#ieeexplore) | [IEEE Xplore API portal](https://developer.ieee.org) | `IEEEAPIKey` | 200 calls/day |
| [MathSciNet](http://www.ams.org/mathscinet) | (none) | (none) | Depending on the current network |
| [SAO/NASA Astrophysics Data System](https://docs.jabref.org/collect/import-using-online-bibliographic-database#sao-nasa-astrophysics-data-system) | [ADS UI](https://ui.adsabs.harvard.edu/user/settings/token) | `AstrophysicsDataSystemAPIKey` | 5000 calls/day |
| [ScienceDirect](https://www.sciencedirect.com) | | `ScienceDirectApiKey` | |
| [SemanticScholar](https://www.semanticscholar.org/) | <https://www.semanticscholar.org/product/api#api-key-form> | `SemanticScholarApiKey` | |
| [Springer Nature](https://docs.jabref.org/collect/import-using-online-bibliographic-database#springer) | [Springer Nature API Portal](https://dev.springernature.com) | `SpringerNatureAPIKey` | 5000 calls/day |
| [Zentralblatt Math](https://www.zbmath.org) | (none) | (none) | Depending on the current network |
| [Biodiversity Heritage Library](https://www.biodiversitylibrary.org/) | [Biodiversitylibrary](https://about.biodiversitylibrary.org/tools-and-services/developer-and-data-tools/#APIs) | `BiodiversityHeritageApiKey` | - |

"Depending on the current network" means that it depends on whether your request is routed through a network having paid access. For instance, some universities have subscriptions to MathSciNet.

Expand Down Expand Up @@ -72,7 +73,7 @@ springerNatureAPIKey=${springerNatureAPIKey}
In `build.gradle`, these variables are filled:

```groovy
"springerNatureAPIKey": System.getenv('SpringerNatureAPIKey')
"springerNatureAPIKey" : System.getenv('SpringerNatureAPIKey')
```

The `BuildInfo` class reads from that file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public CitationRelationsTab(EntryEditorPreferences preferences, DialogService di
setText(Localization.lang("Citation relations"));
setTooltip(new Tooltip(Localization.lang("Show articles related by citation")));

this.bibEntryRelationsRepository = new BibEntryRelationsRepository(new SemanticScholarFetcher(),
this.bibEntryRelationsRepository = new BibEntryRelationsRepository(new SemanticScholarFetcher(preferencesService.getImporterPreferences()),
new BibEntryRelationsCache());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@
import java.util.List;

import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.ImporterPreferences;
import org.jabref.logic.importer.fetcher.CustomizableKeyFetcher;
import org.jabref.logic.net.URLDownload;
import org.jabref.logic.util.BuildInfo;
import org.jabref.model.entry.BibEntry;

import com.google.gson.Gson;

public class SemanticScholarFetcher implements CitationFetcher {
public class SemanticScholarFetcher implements CitationFetcher, CustomizableKeyFetcher {
private static final String SEMANTIC_SCHOLAR_API = "https://api.semanticscholar.org/graph/v1/";

private static final String API_KEY = new BuildInfo().semanticScholarApiKey;

private final ImporterPreferences importerPreferences;

public SemanticScholarFetcher(ImporterPreferences importerPreferences) {
this.importerPreferences = importerPreferences;
}

@Override
public List<BibEntry> searchCitedBy(BibEntry entry) throws FetcherException {
if (entry.getDOI().isPresent()) {
Expand All @@ -24,17 +35,20 @@ public List<BibEntry> searchCitedBy(BibEntry entry) throws FetcherException {
.append("/citations")
.append("?fields=").append("title,authors,year,citationCount,referenceCount")
.append("&limit=1000");

try {
URL citationsUrl = URI.create(urlBuilder.toString()).toURL();

URLDownload urlDownload = new URLDownload(citationsUrl);

String apiKey = getApiKey();
if (!apiKey.isEmpty()) {
urlDownload.addHeader("x-api-key", apiKey);
}
CitationsResponse citationsResponse = new Gson()
.fromJson(urlDownload.asString(), CitationsResponse.class);

return citationsResponse.getData()
.stream().filter(citationDataItem -> citationDataItem.getCitingPaper() != null)
.map(citationDataItem -> citationDataItem.getCitingPaper().toBibEntry()).toList();
.stream().filter(citationDataItem -> citationDataItem.getCitingPaper() != null)
.map(citationDataItem -> citationDataItem.getCitingPaper().toBibEntry()).toList();
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -50,19 +64,23 @@ public List<BibEntry> searchCiting(BibEntry entry) {
.append("paper/")
.append("DOI:").append(entry.getDOI().get().getDOI())
.append("/references")
.append("?fields=").append("title,authors,year,citationCount,referenceCount")
.append("?fields=")
.append("title,authors,year,citationCount,referenceCount")
.append("&limit=1000");
try {
URL referencesUrl = URI.create(urlBuilder.toString()).toURL();

URLDownload urlDownload = new URLDownload(referencesUrl);
String apiKey = getApiKey();
if (!apiKey.isEmpty()) {
urlDownload.addHeader("x-api-key", apiKey);
}
ReferencesResponse referencesResponse = new Gson()
.fromJson(urlDownload.asString(), ReferencesResponse.class);

return referencesResponse.getData()
.stream()
.filter(citationDataItem -> citationDataItem.getCitedPaper() != null)
.map(referenceDataItem -> referenceDataItem.getCitedPaper().toBibEntry()).toList();
.stream()
.filter(citationDataItem -> citationDataItem.getCitedPaper() != null)
.map(referenceDataItem -> referenceDataItem.getCitedPaper().toBibEntry()).toList();
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -75,4 +93,8 @@ public List<BibEntry> searchCiting(BibEntry entry) {
public String getName() {
return "Semantic Scholar Citations Fetcher";
}

private String getApiKey() {
return importerPreferences.getApiKey(getName()).orElse(API_KEY);
}
}
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/logic/util/BuildInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final class BuildInfo {
public final String minRequiredJavaVersion;
public final boolean allowJava9;
public final String biodiversityHeritageApiKey;
public final String semanticScholarApiKey;

public BuildInfo() {
this("/build.properties");
Expand Down Expand Up @@ -57,14 +58,15 @@ public BuildInfo(String path) {
minRequiredJavaVersion = properties.getProperty("minRequiredJavaVersion", "1.8");
allowJava9 = "true".equals(properties.getProperty("allowJava9", "true"));
biodiversityHeritageApiKey = BuildInfo.getValue(properties, "biodiversityHeritageApiKey", "36b910b6-2eb3-46f2-b64c-9abc149925ba");
semanticScholarApiKey = BuildInfo.getValue(properties, "semanticScholarApiKey", "");
}

private static String getValue(Properties properties, String key, String defaultValue) {
String result = Optional.ofNullable(properties.getProperty(key))
// workaround unprocessed build.properties file --> just remove the reference to some variable used in build.gradle
.map(value -> value.replaceAll("\\$\\{.*\\}", ""))
.orElse("");
if (!"".equals(result)) {
if (!result.isEmpty()) {
return result;
}
return defaultValue;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ springerNatureAPIKey=${springerNatureAPIKey}
astrophysicsDataSystemAPIKey=${astrophysicsDataSystemAPIKey}
ieeeAPIKey=${ieeeAPIKey}
biodiversityHeritageApiKey=${biodiversityHeritageApiKey}

semanticScholarApiKey=${semanticScholarApiKey}
Loading

0 comments on commit 47e2c97

Please sign in to comment.