Skip to content

Commit

Permalink
Create List of checkers at the contructor
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Apr 23, 2020
1 parent fd7621d commit 03dd2a0
Showing 1 changed file with 30 additions and 64 deletions.
94 changes: 30 additions & 64 deletions src/main/java/org/jabref/logic/integrity/IntegrityCheck.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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;
Expand All @@ -14,64 +14,44 @@
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 ASCIICharacterChecker asciiCharacterChecker;
private NoBibtexFieldChecker noBibtexFieldChecker;
private BibTeXEntryTypeChecker bibTeXEntryTypeChecker;
private BibtexKeyChecker bibtexKeyChecker;
private TypeChecker typeChecker;
private BibStringChecker bibStringChecker;
private HTMLCharacterChecker htmlCharacterChecker;
private EntryLinkChecker entryLinkChecker;
private BibtexkeyDeviationChecker bibtexkeyDeviationChecker;
private BibtexKeyDuplicationChecker bibtexKeyDuplicationChecker;
private JournalInAbbreviationListChecker journalInAbbreviationListChecker;
private FieldCheckers fieldCheckers;
private DoiDuplicationChecker doiDuplicationChecker;
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;
initCheckers(bibDatabaseContext, bibtexKeyPatternPreferences, journalAbbreviationRepository);
}

private void initCheckers(BibDatabaseContext bibDatabaseContext, BibtexKeyPatternPreferences bibtexKeyPatternPreferences, JournalAbbreviationRepository journalAbbreviationRepository) {
asciiCharacterChecker = new ASCIICharacterChecker();
noBibtexFieldChecker = new NoBibtexFieldChecker();
bibTeXEntryTypeChecker = new BibTeXEntryTypeChecker();
bibtexKeyChecker = new BibtexKeyChecker();
typeChecker = new TypeChecker();
bibStringChecker = new BibStringChecker();
htmlCharacterChecker = new HTMLCharacterChecker();
entryLinkChecker = new EntryLinkChecker(bibDatabaseContext.getDatabase());
bibtexkeyDeviationChecker = new BibtexkeyDeviationChecker(bibDatabaseContext, bibtexKeyPatternPreferences);
bibtexKeyDuplicationChecker = new BibtexKeyDuplicationChecker(bibDatabaseContext.getDatabase());
doiDuplicationChecker = new DoiDuplicationChecker(bibDatabaseContext.getDatabase());

if (bibDatabaseContext.isBiblatexMode()) {
journalInAbbreviationListChecker = new JournalInAbbreviationListChecker(StandardField.JOURNALTITLE, journalAbbreviationRepository);
} else {
journalInAbbreviationListChecker = new JournalInAbbreviationListChecker(StandardField.JOURNAL, journalAbbreviationRepository);
}
this.bibDatabaseContext = bibDatabaseContext;

fieldCheckers = new FieldCheckers(bibDatabaseContext,
filePreferences,
journalAbbreviationRepository,
enforceLegalKey,
allowIntegerEdition);

entryCheckers = Arrays.asList(
new BibtexKeyChecker(),
new TypeChecker(),
new BibStringChecker(),
new HTMLCharacterChecker(),
new EntryLinkChecker(bibDatabaseContext.getDatabase()),
new BibtexkeyDeviationChecker(bibDatabaseContext, bibtexKeyPatternPreferences),
new BibtexKeyDuplicationChecker(bibDatabaseContext.getDatabase()),
new DoiDuplicationChecker(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())
);
}
}

List<IntegrityMessage> checkDatabase() {
Expand All @@ -86,32 +66,18 @@ List<IntegrityMessage> checkDatabase() {

public List<IntegrityMessage> checkEntry(BibEntry entry) {
List<IntegrityMessage> result = new ArrayList<>();

if (entry == null) {
return result;
}

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(asciiCharacterChecker.check(entry));
result.addAll(noBibtexFieldChecker.check(entry));
result.addAll(bibTeXEntryTypeChecker.check(entry));
for (Checker entryChecker : entryCheckers) {
result.addAll(entryChecker.check(entry));
}

result.addAll(journalInAbbreviationListChecker.check(entry));
result.addAll(bibtexKeyChecker.check(entry));
result.addAll(typeChecker.check(entry));
result.addAll(bibStringChecker.check(entry));
result.addAll(htmlCharacterChecker.check(entry));
result.addAll(entryLinkChecker.check(entry));
result.addAll(bibtexkeyDeviationChecker.check(entry));
result.addAll(bibtexKeyDuplicationChecker.check(entry));
result.addAll(doiDuplicationChecker.check(entry));

return result;
}
}

0 comments on commit 03dd2a0

Please sign in to comment.