Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public ConsistencyCheckAction(Supplier<LibraryTab> tabSupplier,
this.preferences = preferences;
this.entryTypesManager = entryTypesManager;
this.taskExecutor = taskExecutor;

this.executable.bind(needsDatabase(stateManager));
}

Expand All @@ -63,7 +62,7 @@ public BibliographyConsistencyCheck.Result call() {
BibDatabaseContext bibContext = databaseContext.get();

BibliographyConsistencyCheck consistencyCheck = new BibliographyConsistencyCheck();
return consistencyCheck.check(bibContext, (count, total) ->
return consistencyCheck.check(bibContext, entryTypesManager, (count, total) ->
UiTaskExecutor.runInJavaFXThread(() -> {
updateProgress(count, total);
updateMessage(Localization.lang("%0/%1 entry types", count + 1, total));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.jabref.logic.quality.consistency.BibliographyConsistencyCheckResultTxtWriter;
import org.jabref.logic.quality.consistency.BibliographyConsistencyCheckResultWriter;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.toolkit.converter.CygWinPathConverter;

import org.slf4j.Logger;
Expand Down Expand Up @@ -65,7 +66,8 @@ public Integer call() {
BibDatabaseContext databaseContext = parserResult.get().getDatabaseContext();

BibliographyConsistencyCheck consistencyCheck = new BibliographyConsistencyCheck();
BibliographyConsistencyCheck.Result result = consistencyCheck.check(databaseContext, (count, total) -> {
BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager();
BibliographyConsistencyCheck.Result result = consistencyCheck.check(databaseContext, bibEntryTypesManager, (count, total) -> {
if (!sharedOptions.porcelain) {
System.out.println(Localization.lang("Checking consistency for entry type %0 of %1", count + 1, total));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.InternalField;
import org.jabref.model.entry.field.SpecialField;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.field.UserSpecificCommentField;
import org.jabref.model.entry.types.BiblatexEntryTypeDefinitions;
import org.jabref.model.entry.types.BibtexEntryTypeDefinitions;
import org.jabref.model.entry.types.EntryType;

import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -102,7 +101,7 @@ public record EntryTypeResult(Collection<Field> fields, SequencedCollection<BibE
*
* @implNote This class does not implement {@link org.jabref.logic.integrity.DatabaseChecker}, because it returns a list of {@link org.jabref.logic.integrity.IntegrityMessage}, which are too fine-grained.
*/
public Result check(BibDatabaseContext bibContext, BiConsumer<Integer, Integer> entriesGroupingProgress) {
public Result check(BibDatabaseContext bibContext, BibEntryTypesManager bibEntryTypesManager, BiConsumer<Integer, Integer> entriesGroupingProgress) {
// collects fields existing in any entry, scoped by entry type
Map<EntryType, Set<Field>> entryTypeToFieldsInAnyEntryMap = new HashMap<>();
// collects fields existing in all entries, scoped by entry type
Expand All @@ -112,12 +111,7 @@ public Result check(BibDatabaseContext bibContext, BiConsumer<Integer, Integer>

collectEntriesIntoMaps(bibContext, entryTypeToFieldsInAnyEntryMap, entryTypeToFieldsInAllEntriesMap, entryTypeToEntriesMap);

List<BibEntryType> entryTypeDefinitions;
if (bibContext.getMode() == BibDatabaseMode.BIBLATEX) {
entryTypeDefinitions = BiblatexEntryTypeDefinitions.ALL;
} else {
entryTypeDefinitions = BibtexEntryTypeDefinitions.ALL;
}
List<BibEntryType> entryTypeDefinitions = bibEntryTypesManager.getAllTypes(bibContext.getMode()).stream().toList();

// Use LinkedHashMap to preserve the order of Bib(tex|latex)EntryTypeDefinitions.ALL
Map<EntryType, EntryTypeResult> resultMap = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Set;

import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.fileformat.BibtexImporter;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.BibField;
import org.jabref.model.entry.field.FieldPriority;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.field.UnknownField;
import org.jabref.model.entry.types.EntryType;
import org.jabref.model.entry.types.StandardEntryType;
import org.jabref.model.entry.types.UnknownEntryType;
import org.jabref.model.util.DummyFileUpdateMonitor;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -27,8 +36,30 @@

class BibliographyConsistencyCheckResultCsvWriterTest {

private static final EntryType UNKNOWN_TYPE = new UnknownEntryType("unknownType");
private static final EntryType CUSTOM_TYPE = new UnknownEntryType("customType");

private final BibtexImporter importer = new BibtexImporter(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS), new DummyFileUpdateMonitor());

private BibEntryType newCustomType;
private BibEntryType overwrittenStandardType;
private BibEntryTypesManager entryTypesManager;

@BeforeEach
void setUp() {
newCustomType = new BibEntryType(
CUSTOM_TYPE,
List.of(new BibField(StandardField.AUTHOR, FieldPriority.IMPORTANT)),
Set.of());

overwrittenStandardType = new BibEntryType(
StandardEntryType.Article,
List.of(new BibField(StandardField.TITLE, FieldPriority.IMPORTANT)),
Set.of());

entryTypesManager = new BibEntryTypesManager();
}

@Test
void checkSimpleLibrary(@TempDir Path tempDir) throws IOException {
BibEntry first = new BibEntry(StandardEntryType.Article, "first")
Expand All @@ -42,7 +73,7 @@ void checkSimpleLibrary(@TempDir Path tempDir) throws IOException {
database.insertEntry(second);

BibDatabaseContext bibContext = new BibDatabaseContext(database);
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> {
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (count, total) -> {
});

Path csvFile = tempDir.resolve("checkSimpleLibrary-result.csv");
Expand Down Expand Up @@ -73,7 +104,7 @@ void checkDifferentOutputSymbols(@TempDir Path tempDir) throws IOException {

BibDatabaseContext bibContext = new BibDatabaseContext(database);
bibContext.setMode(BibDatabaseMode.BIBTEX);
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> {
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (count, total) -> {
});

Path csvFile = tempDir.resolve("checkDifferentOutputSymbols-result.csv");
Expand Down Expand Up @@ -119,7 +150,7 @@ void checkComplexLibrary(@TempDir Path tempDir) throws IOException {
database.insertEntry(fifth);

BibDatabaseContext bibContext = new BibDatabaseContext(database);
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> {
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (count, total) -> {
});

Path csvFile = tempDir.resolve("checkSimpleLibrary-result.csv");
Expand Down Expand Up @@ -151,7 +182,7 @@ void checkLibraryWithoutIssues(@TempDir Path tempDir) throws IOException {

BibDatabaseContext bibContext = new BibDatabaseContext(database);
bibContext.setMode(BibDatabaseMode.BIBTEX);
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> {
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (count, total) -> {
});

Path csvFile = tempDir.resolve("checkLibraryWithoutIssues-result.csv");
Expand All @@ -170,7 +201,7 @@ void checkManualInput() throws IOException {
Path file = Path.of("C:\\TEMP\\JabRef\\biblio-anon.bib");
Path csvFile = file.resolveSibling("biblio-cited.csv");
BibDatabaseContext databaseContext = importer.importDatabase(file).getDatabaseContext();
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(databaseContext, (_, _) -> {
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(databaseContext, entryTypesManager, (_, _) -> {
});
try (Writer writer = new OutputStreamWriter(Files.newOutputStream(csvFile));
BibliographyConsistencyCheckResultCsvWriter paperConsistencyCheckResultCsvWriter = new BibliographyConsistencyCheckResultCsvWriter(result, writer, true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void checkSimpleLibrary(@TempDir Path tempDir) throws IOException {

BibDatabaseContext bibContext = new BibDatabaseContext(database);
bibContext.setMode(BibDatabaseMode.BIBTEX);
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> {
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (count, total) -> {
});

Path txtFile = tempDir.resolve("checkSimpleLibrary-result.txt");
Expand Down Expand Up @@ -89,7 +89,7 @@ void entriesMissingRequiredFieldsAreReported(@TempDir Path tempDir) throws Excep
bibContext.setMode(BibDatabaseMode.BIBLATEX);

BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck()
.check(bibContext, (_, _) -> {
.check(bibContext, new BibEntryTypesManager(), (_, _) -> {
});

Path txtFile = tempDir.resolve("checkSimpleLibrary-result.txt");
Expand Down Expand Up @@ -131,7 +131,7 @@ void checkDifferentOutputSymbols(@TempDir Path tempDir) throws IOException {
BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase);
bibContext.setMode(BibDatabaseMode.BIBTEX);

BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> {
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (_, _) -> {
});

Path txtFile = tempDir.resolve("checkDifferentOutputSymbols-result.txt");
Expand Down Expand Up @@ -171,7 +171,7 @@ void checkVeryLongCitationKey(@TempDir Path tempDir) throws IOException {
bibDatabase.insertEntries(bibEntriesList);
BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase);
bibContext.setMode(BibDatabaseMode.BIBTEX);
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> {
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (_, _) -> {
});

Path txtFile = tempDir.resolve("checkDifferentOutputSymbols-result.txt");
Expand Down Expand Up @@ -228,7 +228,7 @@ void checkComplexLibrary(@TempDir Path tempDir) throws IOException {
bibDatabase.insertEntries(bibEntriesList);
BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase);

BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> {
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (_, _) -> {
});

Path txtFile = tempDir.resolve("checkSimpleLibrary-result.txt");
Expand Down Expand Up @@ -270,7 +270,7 @@ void checkLibraryWithoutIssuesWithOutPorcelain(@TempDir Path tempDir) throws IOE
bibDatabase.insertEntries(bibEntriesList);
BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase);

BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> {
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (_, _) -> {
});

Path txtFile = tempDir.resolve("checkLibraryWithoutIssues-result.txt");
Expand Down Expand Up @@ -298,7 +298,7 @@ void checkLibraryWithoutIssuesWithPorcelain(@TempDir Path tempDir) throws IOExce
bibDatabase.insertEntries(bibEntriesList);
BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase);

BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> {
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (_, _) -> {
});

Path txtFile = tempDir.resolve("checkLibraryWithoutIssues-result.txt");
Expand All @@ -315,7 +315,7 @@ void checkManualInput() throws IOException {
Path file = Path.of("C:\\TEMP\\JabRef\\biblio-anon.bib");
Path txtFile = file.resolveSibling("biblio-cited.txt");
BibDatabaseContext databaseContext = importer.importDatabase(file).getDatabaseContext();
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(databaseContext, (_, _) -> {
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(databaseContext, new BibEntryTypesManager(), (_, _) -> {
});
try (Writer writer = new OutputStreamWriter(Files.newOutputStream(txtFile));
BibliographyConsistencyCheckResultTxtWriter txtWriter = new BibliographyConsistencyCheckResultTxtWriter(result, writer, true)) {
Expand Down
Loading