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

Add entry based on ISSN number #10124 #10178

Merged
merged 31 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e56cea0
Add: implementing the ISSN Fetcher
guipmenezes Aug 4, 2023
a582067
Add: implementing methods of IssnFetcher class
guipmenezes Aug 4, 2023
18ebb1e
Substantially changes on IssnFetcher class
guipmenezes Aug 7, 2023
7d87a31
Substantial changes of IssnFetcher
guipmenezes Aug 7, 2023
1f6eb67
Merge branch 'JabRef:main' into fix-issue-10124
guipmenezes Aug 9, 2023
80925e6
Implementing the performSearchById method for IssnFetcher class
guipmenezes Aug 10, 2023
f741462
Merge branch 'JabRef:main' into fix-issue-10124
guipmenezes Aug 11, 2023
479029f
Saving changes for branch updating
guipmenezes Aug 14, 2023
62cb93d
Merge branch 'JabRef:main' into fix-issue-10124
guipmenezes Aug 14, 2023
557f25b
Started to implement the ISSN search logic
guipmenezes Aug 15, 2023
49975f1
Merge branch 'JabRef:main' into fix-issue-10124
guipmenezes Aug 15, 2023
4994515
Merge branch 'fix-issue-10124' of https://github.com/guipmenezes/jabr…
guipmenezes Aug 15, 2023
9dd0a4c
Merge branch 'JabRef:main' into fix-issue-10124
guipmenezes Aug 15, 2023
e521a2f
Refactor the performSearchById method
guipmenezes Aug 16, 2023
89269e8
Add the IssnFetcher on WebFetcher class and add unit tests
guipmenezes Aug 16, 2023
6dfd8eb
Merge branch 'JabRef:main' into fix-issue-10124
guipmenezes Aug 17, 2023
d4300c3
Implement search based on the ISSN number
guipmenezes Aug 17, 2023
65a7d04
Merge branch 'JabRef:main' into fix-issue-10124
guipmenezes Aug 18, 2023
8926ce6
Change the ISSN Checker validation of a valid checksum
guipmenezes Aug 18, 2023
c2264f1
Merge branch 'fix-issue-10124' of https://github.com/guipmenezes/jabr…
guipmenezes Aug 18, 2023
6c701d9
Merge branch 'JabRef:main' into fix-issue-10124
guipmenezes Aug 22, 2023
6fa4d9e
Merge branch 'JabRef:main' into fix-issue-10124
guipmenezes Aug 23, 2023
1e1347e
Merge remote-tracking branch 'upstream/main' into fix-issue-10124
Siedlerchr Nov 1, 2023
b74f5d1
refactor to use exiting journal info fetcher
Siedlerchr Nov 1, 2023
08211ef
Merge remote-tracking branch 'upstream/main' into fix-issue-10124
Siedlerchr Nov 4, 2023
515fcc4
reafactor
Siedlerchr Nov 4, 2023
798d723
add button next to journal field
Siedlerchr Nov 4, 2023
a13e3c8
fix tests and checkstyle
Siedlerchr Nov 4, 2023
f6cd33f
Merge remote-tracking branch 'upstream/main' into fix-issue-10124
Siedlerchr Nov 4, 2023
1b41443
arch test
Siedlerchr Nov 4, 2023
4f13a2e
Fuuu checkstyle
Siedlerchr Nov 4, 2023
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
80 changes: 80 additions & 0 deletions src/main/java/org/jabref/logic/importer/fetcher/IssnFetcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.jabref.logic.importer.fetcher;

import java.util.List;
import java.util.Optional;

import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.IdBasedFetcher;
import org.jabref.logic.importer.IdFetcher;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.integrity.ISSNChecker;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.identifier.ISSN;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Fetcher to generate the BibTex entry from an ISSN.
* The idea is to use the {@link DOAJFetcher} to do a request for a given ISSN number.
*/

public class IssnFetcher implements IdBasedFetcher, IdFetcher<ISSN> {

private static final Logger LOGGER = LoggerFactory.getLogger(IssnFetcher.class);
private final DOAJFetcher doajFetcher;
private final String SEARCH_URL = "https://doaj.org/api/search/journals/";
private final ISSNChecker issnChecker;
private final ImportFormatPreferences importFormatPreferences;

public IssnFetcher(ImportFormatPreferences importFormatPreferences) {
this.importFormatPreferences = importFormatPreferences;
this.doajFetcher = new DOAJFetcher(importFormatPreferences);
this.issnChecker = new ISSNChecker();
}

@Override
public Optional<BibEntry> performSearchById(String identifier) throws FetcherException {

Optional<String> checkedId = issnChecker.checkValue(identifier);
if (checkedId.isEmpty()) {
LOGGER.warn("Not a valid ISSN");
return Optional.empty();
}

Optional<BibEntry> bibEntry = Optional.empty();

String queryString = concatenateIssnWithId(identifier);
List<BibEntry> bibEntries = doajFetcher.performSearch(queryString);

if (!bibEntries.isEmpty()) {
for (int i = 0; i < bibEntries.size(); i++) {
bibEntry = Optional.ofNullable(bibEntries.get(0));
}
} else {
LOGGER.warn("ISSN search failed, no results found");
}

return bibEntry;
}

@Override
public Optional<ISSN> findIdentifier(BibEntry entry) throws FetcherException {
// Need to create a getIssn() method in BibEntry that returns a Optional
return Optional.empty();
}

@Override
public String getIdentifierName() {
return getName();
}

@Override
public String getName() {
return "ISSN";
}

public String concatenateIssnWithId(String identifier) {
return "issn:" + identifier;
}
}
22 changes: 21 additions & 1 deletion src/main/java/org/jabref/model/entry/identifier/ISSN.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package org.jabref.model.entry.identifier;

import java.net.URI;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ISSN {
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;

public class ISSN implements Identifier {

private static final Pattern ISSN_PATTERN = Pattern.compile("^\\d{4}-\\d{3}[\\dxX]$");
private static final Pattern ISSN_PATTERN_NODASH = Pattern.compile("^(\\d{4})(\\d{3}[\\dxX])$");
Expand Down Expand Up @@ -48,4 +53,19 @@ public boolean isValidChecksum() {
}
return ((((sum % 11) + control) - '0') == 11) || ((sum % 11) == 0);
}

@Override
public String getNormalized() {
return issnString;
}

@Override
public Field getDefaultField() {
return StandardField.ISSN;
}

@Override
public Optional<URI> getExternalURI() {
return Optional.empty();
}
}