-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Check duplicate DOI #6333
Check duplicate DOI #6333
Changes from 14 commits
2e07d9b
c3724a8
1a7aa44
a1b0fbc
9b46f85
ae89990
006c241
b3e703b
2c00e7d
fd7621d
03dd2a0
6f9b148
2de1858
4c9e687
97b9cbe
eaebdf5
7c72d52
c8296c3
6597dc6
de629d2
5a5046c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.jabref.logic.integrity; | ||
|
||
import java.util.List; | ||
|
||
import org.jabref.model.entry.BibEntry; | ||
|
||
@FunctionalInterface | ||
public interface Checker { | ||
List<IntegrityMessage> check(BibEntry entry); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.jabref.logic.integrity; | ||
|
||
import java.util.List; | ||
|
||
import org.jabref.model.database.BibDatabase; | ||
|
||
@FunctionalInterface | ||
public interface DatabaseChecker { | ||
List<IntegrityMessage> check(BibDatabase database); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.jabref.logic.integrity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import javafx.collections.ObservableList; | ||
|
||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.model.database.BibDatabase; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.StandardField; | ||
import org.jabref.model.entry.identifier.DOI; | ||
|
||
import com.google.common.collect.BiMap; | ||
import com.google.common.collect.HashBiMap; | ||
|
||
public class DoiDuplicationChecker implements DatabaseChecker { | ||
|
||
@Override | ||
public List<IntegrityMessage> check(BibDatabase database) { | ||
ObservableList<BibEntry> bibEntries = database.getEntries(); | ||
BiMap<DOI, List<BibEntry>> duplicateMap = HashBiMap.create(bibEntries.size()); | ||
for (BibEntry bibEntry : bibEntries) { | ||
bibEntry.getDOI().ifPresent(doi -> | ||
duplicateMap.computeIfAbsent(doi, absentDoi -> new ArrayList<>()).add(bibEntry)); | ||
} | ||
|
||
return duplicateMap.inverse().keySet().stream() | ||
.filter(list -> list.size() > 1) | ||
.flatMap(list -> list.stream()) | ||
.map(item -> new IntegrityMessage(Localization.lang("Unique DOI used in multiple entries"), item, StandardField.DOI)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think "The same DOI is used..." is better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just "Same DOI..." will do. |
||
.collect(Collectors.toList()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
package org.jabref.logic.integrity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; | ||
import org.jabref.logic.journals.JournalAbbreviationRepository; | ||
import org.jabref.model.database.BibDatabase; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.StandardField; | ||
|
@@ -14,75 +15,77 @@ | |
public class IntegrityCheck { | ||
|
||
private final BibDatabaseContext bibDatabaseContext; | ||
private final FilePreferences filePreferences; | ||
private final BibtexKeyPatternPreferences bibtexKeyPatternPreferences; | ||
private final JournalAbbreviationRepository journalAbbreviationRepository; | ||
private final boolean enforceLegalKey; | ||
private final boolean allowIntegerEdition; | ||
private final FieldCheckers fieldCheckers; | ||
private final List<Checker> entryCheckers; | ||
|
||
public IntegrityCheck(BibDatabaseContext bibDatabaseContext, | ||
FilePreferences filePreferences, | ||
BibtexKeyPatternPreferences bibtexKeyPatternPreferences, | ||
JournalAbbreviationRepository journalAbbreviationRepository, | ||
boolean enforceLegalKey, | ||
boolean allowIntegerEdition) { | ||
this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext); | ||
this.filePreferences = Objects.requireNonNull(filePreferences); | ||
this.bibtexKeyPatternPreferences = Objects.requireNonNull(bibtexKeyPatternPreferences); | ||
this.journalAbbreviationRepository = Objects.requireNonNull(journalAbbreviationRepository); | ||
this.enforceLegalKey = enforceLegalKey; | ||
this.allowIntegerEdition = allowIntegerEdition; | ||
this.bibDatabaseContext = bibDatabaseContext; | ||
|
||
fieldCheckers = new FieldCheckers(bibDatabaseContext, | ||
filePreferences, | ||
journalAbbreviationRepository, | ||
enforceLegalKey, | ||
allowIntegerEdition); | ||
|
||
entryCheckers = new ArrayList<>(List.of( | ||
new BibtexKeyChecker(), | ||
new TypeChecker(), | ||
new BibStringChecker(), | ||
new HTMLCharacterChecker(), | ||
new EntryLinkChecker(bibDatabaseContext.getDatabase()), | ||
new BibtexkeyDeviationChecker(bibDatabaseContext, bibtexKeyPatternPreferences), | ||
new BibtexKeyDuplicationChecker(bibDatabaseContext.getDatabase()) | ||
)); | ||
|
||
if (!bibDatabaseContext.isBiblatexMode()) { | ||
entryCheckers.add(new JournalInAbbreviationListChecker(StandardField.JOURNALTITLE, journalAbbreviationRepository)); | ||
} else { | ||
entryCheckers.addAll(List.of( | ||
new JournalInAbbreviationListChecker(StandardField.JOURNAL, journalAbbreviationRepository), | ||
new ASCIICharacterChecker(), | ||
new NoBibtexFieldChecker(), | ||
new BibTeXEntryTypeChecker()) | ||
); | ||
} | ||
} | ||
|
||
public List<IntegrityMessage> checkDatabase() { | ||
List<IntegrityMessage> executeAllCheckers() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name it simply |
||
List<IntegrityMessage> result = new ArrayList<>(); | ||
|
||
for (BibEntry entry : bibDatabaseContext.getDatabase().getEntries()) { | ||
BibDatabase database = bibDatabaseContext.getDatabase(); | ||
|
||
for (BibEntry entry : database.getEntries()) { | ||
result.addAll(checkEntry(entry)); | ||
} | ||
|
||
result.addAll(checkDatabase(database)); | ||
|
||
return result; | ||
} | ||
|
||
public List<IntegrityMessage> checkEntry(BibEntry entry) { | ||
List<IntegrityMessage> result = new ArrayList<>(); | ||
|
||
if (entry == null) { | ||
return result; | ||
} | ||
|
||
FieldCheckers fieldCheckers = new FieldCheckers(bibDatabaseContext, | ||
filePreferences, | ||
journalAbbreviationRepository, | ||
enforceLegalKey, | ||
allowIntegerEdition); | ||
for (FieldChecker checker : fieldCheckers.getAll()) { | ||
result.addAll(checker.check(entry)); | ||
for (FieldChecker fieldChecker : fieldCheckers.getAll()) { | ||
result.addAll(fieldChecker.check(entry)); | ||
} | ||
|
||
if (!bibDatabaseContext.isBiblatexMode()) { | ||
// BibTeX only checkers | ||
result.addAll(new ASCIICharacterChecker().check(entry)); | ||
result.addAll(new NoBibtexFieldChecker().check(entry)); | ||
result.addAll(new BibTeXEntryTypeChecker().check(entry)); | ||
result.addAll(new JournalInAbbreviationListChecker(StandardField.JOURNAL, journalAbbreviationRepository).check(entry)); | ||
} else { | ||
result.addAll(new JournalInAbbreviationListChecker(StandardField.JOURNALTITLE, journalAbbreviationRepository).check(entry)); | ||
for (Checker entryChecker : entryCheckers) { | ||
result.addAll(entryChecker.check(entry)); | ||
} | ||
|
||
result.addAll(new BibtexKeyChecker().check(entry)); | ||
result.addAll(new TypeChecker().check(entry)); | ||
result.addAll(new BibStringChecker().check(entry)); | ||
result.addAll(new HTMLCharacterChecker().check(entry)); | ||
result.addAll(new EntryLinkChecker(bibDatabaseContext.getDatabase()).check(entry)); | ||
result.addAll(new BibtexkeyDeviationChecker(bibDatabaseContext, bibtexKeyPatternPreferences).check(entry)); | ||
result.addAll(new BibtexKeyDuplicationChecker(bibDatabaseContext.getDatabase()).check(entry)); | ||
|
||
return result; | ||
} | ||
|
||
@FunctionalInterface | ||
public interface Checker { | ||
List<IntegrityMessage> check(BibEntry entry); | ||
public List<IntegrityMessage> checkDatabase(BibDatabase database) { | ||
return new DoiDuplicationChecker().check(database); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to EntryChecker?