diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 05c03a4594f..eee63f64018 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -257,7 +257,7 @@ jobs: uses: unsplash/comment-on-pr@master if: steps.authors_check.outputs.newauthor == 'true' env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GH_TOKEN_COMMENT_ON_PR }} with: msg: "${{ steps.authors_check.outputs.message }}" check_for_duplicate_msg: true diff --git a/docs/getting-into-the-code/code-howtos.md b/docs/getting-into-the-code/code-howtos.md index e89ee545dd8..b153255ba40 100644 --- a/docs/getting-into-the-code/code-howtos.md +++ b/docs/getting-into-the-code/code-howtos.md @@ -30,6 +30,7 @@ Principles: Localization.lang("Something went wrong...", ioe); } ``` + * Never, ever throw and catch `Exception` or `Throwable` * Errors should only be logged when they are finally caught \(i.e., logged only once\). See **Logging** for details. * If the Exception message is intended to be shown to the User in the UI \(see below\) provide also a localizedMessage \(see `JabRefException`\). @@ -51,7 +52,7 @@ TODO: Usage of status bar and Swing Dialogs ## Using the EventSystem -### What the EventSystem is used for? +### What the EventSystem is used for Many times there is a need to provide an object on many locations simultaneously. This design pattern is quite similar to Java's Observer, but it is much simplier and readable while having the same functional sense. @@ -368,7 +369,7 @@ The following expressions can be used in FXML attributes, according to the [offi All radio buttons that should be grouped together need to have a ToggleGroup defined in the FXML code Example: -```markup +```xml @@ -383,4 +384,3 @@ All radio buttons that should be grouped together need to have a ToggleGroup def ``` - diff --git a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace.md b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace.md index dbdaf5b0ee7..13890e7e753 100644 --- a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace.md +++ b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace.md @@ -222,6 +222,7 @@ Make sure your Eclipse installation us up to date, Eclipse JEE 2020-03 or newer --add-exports javafx.web/com.sun.webkit=org.controlsfx.controls --add-exports javafx.graphics/com.sun.javafx.css=org.controlsfx.controls --add-exports javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix + --add-exports javafx.graphics/com.sun.javafx.stage=com.jfoenix --add-exports com.oracle.truffle.regex/com.oracle.truffle.regex=org.graalvm.truffle --patch-module org.jabref=build/resources/main ``` diff --git a/scripts/generate-authors.sh b/scripts/generate-authors.sh index c2e1108e47e..6f00f12bb62 100755 --- a/scripts/generate-authors.sh +++ b/scripts/generate-authors.sh @@ -58,5 +58,5 @@ cd "$(dirname "$(readlink -f "$BASH_SOURCE")")/.." # co-authors coauthors=$(git log -i --grep=co-authored-by | grep -i "co-authored-by" | sed "s/.*co-authored-by: \(.*\)/\1/I" | sed "s/ <.*//") - echo -e "$authors\n$(git log --format='%aN')\n$coauthors" | grep -v "\[bot\]" | grep -v "JabRef" | grep -v "Siedlerchr" | grep -v "^Christoph$" | grep -v "^Mootez$" | grep -v "oscargus" | grep -v "dependabot" | grep -v "github actions" | grep -v "igorsteinmacher" | grep -v "halirutan" | grep -v "matthiasgeiger" | grep -v "Gitter Badger" | grep -v "gdstewart" | LC_ALL=C.UTF-8 sort --unique --ignore-case + echo -e "$authors\n$(git log --format='%aN')\n$coauthors" | grep -v "\[bot\]" | grep -v "JabRef" | grep -v "Siedlerchr" | grep -v "^Christoph$" | grep -v "^Mootez$" | grep -v "oscargus" | grep -v "dependabot" | grep -v "github actions" | grep -v "igorsteinmacher" | grep -v "halirutan" | grep -v "matthiasgeiger" | grep -v "Gitter Badger" | grep -v "gdstewart" | grep -v "chenyuheng" | LC_ALL=C.UTF-8 sort --unique --ignore-case } > AUTHORS diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 91b401415fb..61949d75312 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -614,7 +614,7 @@ public void copy() { } public void paste() { - mainTable.paste(); + mainTable.paste(this.bibDatabaseContext.getMode()); } public void cut() { diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index c8b11e5e1e7..09ea0e88789 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -20,6 +20,7 @@ import org.jabref.logic.database.DuplicateCheck; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.IdBasedFetcher; +import org.jabref.logic.importer.ImportCleanup; import org.jabref.logic.importer.WebFetchers; import org.jabref.logic.importer.fetcher.DoiFetcher; import org.jabref.logic.l10n.Localization; @@ -147,6 +148,8 @@ public void runFetcherWorker() { Optional result = fetcherWorker.getValue(); if (result.isPresent()) { final BibEntry entry = result.get(); + ImportCleanup cleanup = new ImportCleanup(basePanel.getBibDatabaseContext().getMode()); + cleanup.doPostCleanup(entry); Optional duplicate = new DuplicateCheck(Globals.entryTypesManager).containsDuplicate(basePanel.getDatabase(), entry, basePanel.getBibDatabaseContext().getMode()); if ((duplicate.isPresent())) { DuplicateResolverDialog dialog = new DuplicateResolverDialog(entry, duplicate.get(), DuplicateResolverDialog.DuplicateResolverType.IMPORT_CHECK, basePanel.getBibDatabaseContext(), stateManager); diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index cab16f4435e..e4096a9ca39 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -125,6 +125,7 @@ import org.jabref.logic.autosaveandbackup.BackupManager; import org.jabref.logic.citationstyle.CitationStyleOutputFormat; import org.jabref.logic.importer.IdFetcher; +import org.jabref.logic.importer.ImportCleanup; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.WebFetchers; import org.jabref.logic.l10n.Localization; @@ -1189,6 +1190,8 @@ private boolean readyForAutosave(BibDatabaseContext context) { */ private void addImportedEntries(final BasePanel panel, final ParserResult parserResult) { BackgroundTask task = BackgroundTask.wrap(() -> parserResult); + ImportCleanup cleanup = new ImportCleanup(panel.getBibDatabaseContext().getMode()); + cleanup.doPostCleanup(parserResult.getDatabase().getEntries()); ImportEntriesDialog dialog = new ImportEntriesDialog(panel.getBibDatabaseContext(), task); dialog.setTitle(Localization.lang("Import")); dialog.showAndWait(); diff --git a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java index 039e229d508..43caa526ef6 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java @@ -22,8 +22,11 @@ import org.jabref.gui.DialogService; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.util.BackgroundTask; +import org.jabref.logic.importer.ImportCleanup; import org.jabref.logic.importer.fetcher.MrDLibFetcher; import org.jabref.logic.l10n.Localization; +import org.jabref.model.database.BibDatabase; +import org.jabref.model.database.BibDatabaseModeDetection; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.preferences.JabRefPreferences; @@ -67,6 +70,8 @@ private StackPane getRelatedArticlesPane(BibEntry entry) { .wrap(() -> fetcher.performSearch(entry)) .onRunning(() -> progress.setVisible(true)) .onSuccess(relatedArticles -> { + ImportCleanup cleanup = new ImportCleanup(BibDatabaseModeDetection.inferMode(new BibDatabase(List.of(entry)))); + cleanup.doPostCleanup(relatedArticles); progress.setVisible(false); root.getChildren().add(getRelatedArticleInfo(relatedArticles, fetcher)); }) diff --git a/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesDialog.java b/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesDialog.java index ceaea36f3d2..6e22853a021 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesDialog.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesDialog.java @@ -57,7 +57,7 @@ import org.slf4j.LoggerFactory; /** - * GUI Dialog for the feature "Find unlinked files". + * GUI Dialog for the feature "Search for unlinked local files". */ public class FindUnlinkedFilesDialog extends BaseDialog { @@ -77,7 +77,7 @@ public class FindUnlinkedFilesDialog extends BaseDialog { public FindUnlinkedFilesDialog(BibDatabaseContext database, DialogService dialogService, CountingUndoManager undoManager) { super(); - this.setTitle(Localization.lang("Find unlinked files")); + this.setTitle(Localization.lang("Search for unlinked local files")); this.dialogService = dialogService; databaseContext = database; diff --git a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java index 9ffed42bc07..4c872f1d55e 100644 --- a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java +++ b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java @@ -15,6 +15,7 @@ import org.jabref.gui.undo.UndoableInsertEntries; import org.jabref.logic.citationkeypattern.CitationKeyGenerator; import org.jabref.logic.externalfiles.ExternalFilesContentImporter; +import org.jabref.logic.importer.ImportCleanup; import org.jabref.logic.util.UpdateField; import org.jabref.logic.util.io.FileUtil; import org.jabref.model.FieldChange; @@ -107,7 +108,8 @@ private BibEntry createEmptyEntryWithLink(Path file) { public void importEntries(List entries) { // TODO: Add undo/redo // undoManager.addEdit(new UndoableInsertEntries(panel.getDatabase(), entries)); - + ImportCleanup cleanup = new ImportCleanup(database.getMode()); + cleanup.doPostCleanup(entries); database.getDatabase().insertEntries(entries); // Set owner/timestamp diff --git a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java index 9f87403d97a..89a42d021cf 100644 --- a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java +++ b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java @@ -20,7 +20,6 @@ import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.journals.Abbreviation; -import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; @@ -109,7 +108,7 @@ public SimpleBooleanProperty isLoadingProperty() { */ void addBuiltInList() { BackgroundTask - .wrap(JournalAbbreviationLoader::getBuiltInAbbreviations) + .wrap(journalAbbreviationRepository::getAllLoaded) .onRunning(() -> isLoading.setValue(true)) .onSuccess(result -> { isLoading.setValue(false); @@ -271,10 +270,6 @@ private void setCurrentAbbreviationNameAndAbbreviationIfValid(String name, Strin shouldWriteLists = true; } - private void setCurrentAbbreviationNameAndAbbreviationIfValid(String name, String abbreviation) { - setCurrentAbbreviationNameAndAbbreviationIfValid(name, abbreviation, ""); - } - /** * Method to delete the abbreviation set in the currentAbbreviation property. The currentAbbreviationProperty will * be set to the previous or next abbreviation in the abbreviations property if applicable. Else it will be set to @@ -336,7 +331,7 @@ public void selectLastJournalFile() { /** * This method first saves all external files to its internal list, then writes all abbreviations to their files and * finally updates the abbreviations auto complete. It basically calls {@link #saveExternalFilesList()}, {@link - * #saveJournalAbbreviationFiles() } and finally {@link JournalAbbreviationLoader#update(JournalAbbreviationPreferences)}. + * #saveJournalAbbreviationFiles() }}. */ public void save() { BackgroundTask.wrap(() -> { diff --git a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java index cffd70d7f6e..e6afb160540 100644 --- a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java +++ b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java @@ -37,7 +37,7 @@ public enum KeyBinding { ENTRY_EDITOR_PREVIOUS_PANEL("Entry editor, previous panel", Localization.lang("Entry editor, previous panel"), "ctrl+shift+TAB", KeyBindingCategory.VIEW), FILE_LIST_EDITOR_MOVE_ENTRY_DOWN("File list editor, move entry down", Localization.lang("File list editor, move entry down"), "ctrl+DOWN", KeyBindingCategory.VIEW), FILE_LIST_EDITOR_MOVE_ENTRY_UP("File list editor, move entry up", Localization.lang("File list editor, move entry up"), "ctrl+UP", KeyBindingCategory.VIEW), - FIND_UNLINKED_FILES("Find unlinked files", Localization.lang("Find unlinked files"), "shift+F7", KeyBindingCategory.QUALITY), + FIND_UNLINKED_FILES("Search for unlinked local files", Localization.lang("Search for unlinked local files"), "shift+F7", KeyBindingCategory.QUALITY), FOCUS_ENTRY_TABLE("Focus entry table", Localization.lang("Focus entry table"), "alt+1", KeyBindingCategory.VIEW), HELP("Help", Localization.lang("Help"), "F1", KeyBindingCategory.FILE), IMPORT_INTO_CURRENT_DATABASE("Import into current library", Localization.lang("Import into current library"), "ctrl+I", KeyBindingCategory.FILE), diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index e646b56b286..3fdd2bbfe54 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -40,9 +40,11 @@ import org.jabref.gui.util.CustomLocalDragboard; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.ViewModelTableRowFactory; +import org.jabref.logic.importer.ImportCleanup; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.OS; import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.database.event.EntriesAddedEvent; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.PreferencesService; @@ -157,7 +159,7 @@ public MainTable(MainTableDataModel model, * The {@link MainTable} will scroll to the cell with the same starting column value and typed string * * @param sortedColumn The sorted column in {@link MainTable} - * @param keyEvent The pressed character + * @param keyEvent The pressed character */ private void jumpToSearchKey(TableColumn sortedColumn, KeyEvent keyEvent) { @@ -271,14 +273,15 @@ private void clearAndSelectLast() { scrollTo(getItems().size() - 1); } - public void paste() { + public void paste(BibDatabaseMode bibDatabaseMode) { // Find entries in clipboard List entriesToAdd = Globals.clipboardManager.extractData(); + ImportCleanup cleanup = new ImportCleanup(bibDatabaseMode); + cleanup.doPostCleanup(entriesToAdd); panel.insertEntries(entriesToAdd); if (!entriesToAdd.isEmpty()) { this.requestFocus(); } - } private void handleOnDragOver(TableRow row, BibEntryTableViewModel item, DragEvent event) { diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index e44d3265c34..c5b9d0d4102 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -18,6 +18,7 @@ import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.importer.EntryBasedFetcher; import org.jabref.logic.importer.IdBasedFetcher; +import org.jabref.logic.importer.ImportCleanup; import org.jabref.logic.importer.WebFetcher; import org.jabref.logic.importer.WebFetchers; import org.jabref.logic.l10n.Localization; @@ -64,6 +65,8 @@ public void fetchAndMerge(BibEntry entry, List fields) { if (fetcher.isPresent()) { BackgroundTask.wrap(() -> fetcher.get().performSearchById(fieldContent.get())) .onSuccess(fetchedEntry -> { + ImportCleanup cleanup = new ImportCleanup(panel.getBibDatabaseContext().getMode()); + cleanup.doPostCleanup(entry); String type = field.getDisplayName(); if (fetchedEntry.isPresent()) { showMergeDialog(entry, fetchedEntry.get(), fetcher.get()); @@ -147,6 +150,8 @@ public void fetchAndMerge(BibEntry entry, EntryBasedFetcher fetcher) { BackgroundTask.wrap(() -> fetcher.performSearch(entry).stream().findFirst()) .onSuccess(fetchedEntry -> { if (fetchedEntry.isPresent()) { + ImportCleanup cleanup = new ImportCleanup(panel.getBibDatabaseContext().getMode()); + cleanup.doPostCleanup(fetchedEntry.get()); showMergeDialog(entry, fetchedEntry.get(), fetcher); } else { dialogService.notify(Localization.lang("Could not find any bibliographic information.")); diff --git a/src/main/java/org/jabref/logic/journals/JournalAbbreviationLoader.java b/src/main/java/org/jabref/logic/journals/JournalAbbreviationLoader.java index 69f87bedd2c..72f0664b046 100644 --- a/src/main/java/org/jabref/logic/journals/JournalAbbreviationLoader.java +++ b/src/main/java/org/jabref/logic/journals/JournalAbbreviationLoader.java @@ -1,13 +1,11 @@ package org.jabref.logic.journals; import java.io.IOException; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; import java.util.List; -import java.util.Objects; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,18 +14,6 @@ public class JournalAbbreviationLoader { private static final Logger LOGGER = LoggerFactory.getLogger(JournalAbbreviationLoader.class); - private static final String JOURNALS_FILE_BUILTIN = "/journals/journalList.csv"; - - public static List getBuiltInAbbreviations() { - return readJournalListFromResource(JOURNALS_FILE_BUILTIN); - } - - private static List readJournalListFromResource(String resource) { - AbbreviationParser parser = new AbbreviationParser(); - parser.readJournalListFromResource(Objects.requireNonNull(resource)); - return parser.getAbbreviations(); - } - public static List readJournalListFromFile(Path file) throws IOException { LOGGER.debug(String.format("Reading journal list from file %s", file)); AbbreviationParser parser = new AbbreviationParser(); @@ -35,13 +21,6 @@ public static List readJournalListFromFile(Path file) throws IOExc return parser.getAbbreviations(); } - private static List readJournalListFromFile(Path file, Charset encoding) throws IOException { - LOGGER.debug(String.format("Reading journal list from file %s", file)); - AbbreviationParser parser = new AbbreviationParser(); - parser.readJournalListFromFile(file, Objects.requireNonNull(encoding)); - return parser.getAbbreviations(); - } - public static JournalAbbreviationRepository loadRepository(JournalAbbreviationPreferences journalAbbreviationPreferences) { JournalAbbreviationRepository repository; // Initialize with built-in list diff --git a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java index 5d4d35d7bf7..523e1323be1 100644 --- a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java +++ b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java @@ -7,6 +7,7 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import org.h2.mvstore.MVMap; import org.h2.mvstore.MVStore; @@ -65,8 +66,7 @@ public boolean isAbbreviatedName(String journalName) { String journal = journalName.trim(); return customAbbreviations.stream().anyMatch(abbreviation -> isMatchedAbbreviated(journal, abbreviation)) - || - abbreviationToFull.containsKey(journal); + || abbreviationToFull.containsKey(journal); } /** @@ -125,4 +125,9 @@ public Optional getShortestUniqueAbbreviation(String text) { public Set getFullNames() { return fullToAbbreviation.keySet(); } + + public List getAllLoaded() { + return fullToAbbreviation.entrySet().stream().map(entry -> + new Abbreviation(entry.getKey(), entry.getValue())).collect(Collectors.toList()); + } } diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 2062dbb8838..0a59fc752d7 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1128,7 +1128,6 @@ Resetting\ preference\ key\ '%0'=Resetting preference key '%0' Unknown\ preference\ key\ '%0'=Unknown preference key '%0' Unable\ to\ clear\ preferences.=Unable to clear preferences. -Find\ unlinked\ files=Find unlinked files Unselect\ all=Unselect all Expand\ all=Expand all Collapse\ all=Collapse all @@ -2267,3 +2266,8 @@ Removes\ digits.=Removes digits. The\ query\ cannot\ contain\ a\ year\ and\ year-range\ field.=The query cannot contain a year and year-range field. This\ query\ uses\ unsupported\ fields.=This query uses unsupported fields. This\ query\ uses\ unsupported\ syntax.=This query uses unsupported syntax. + +Check\ Proxy\ Setting=Check Proxy Setting +Check\ connection=Check connection +Connection\ failed\!=Connection failed\! +Connection\ successful\!=Connection successful\! diff --git a/src/test/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtilTest.java b/src/test/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtilTest.java index 990d9c25c50..1053aedb75e 100644 --- a/src/test/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtilTest.java +++ b/src/test/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtilTest.java @@ -27,7 +27,7 @@ public class AutoSetFileLinksUtilTest { private final FilePreferences fileDirPrefs = mock(FilePreferences.class); private final AutoLinkPreferences autoLinkPrefs = - new AutoLinkPreferences(AutoLinkPreferences.CitationKeyDependency.REGEX, "", ';'); + new AutoLinkPreferences(AutoLinkPreferences.CitationKeyDependency.START, "", ';'); private final BibDatabaseContext databaseContext = mock(BibDatabaseContext.class); private final ExternalFileTypes externalFileTypes = mock(ExternalFileTypes.class); private final BibEntry entry = new BibEntry(StandardEntryType.Article); diff --git a/src/test/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModelMixedAbbreviationsTest.java b/src/test/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModelMixedAbbreviationsTest.java index 8834b1b3c56..8d6c11a54a9 100644 --- a/src/test/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModelMixedAbbreviationsTest.java +++ b/src/test/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModelMixedAbbreviationsTest.java @@ -12,13 +12,13 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import org.jabref.JabRefException; import org.jabref.gui.DialogService; import org.jabref.gui.util.CurrentThreadTaskExecutor; import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.journals.Abbreviation; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.preferences.PreferencesService; import org.junit.jupiter.api.BeforeEach; @@ -45,6 +45,7 @@ class ManageJournalAbbreviationsViewModelMixedAbbreviationsTest { private Path testFile4Entries; private Path testFile5EntriesWithDuplicate; private JournalAbbreviationPreferences abbreviationPreferences; + private final JournalAbbreviationRepository repository = JournalAbbreviationLoader.loadBuiltInRepository(); private DialogService dialogService; @BeforeEach @@ -55,7 +56,7 @@ void setUpViewModel(@TempDir Path tempFolder) throws Exception { dialogService = mock(DialogService.class); TaskExecutor taskExecutor = new CurrentThreadTaskExecutor(); - viewModel = new ManageJournalAbbreviationsViewModel(preferences, dialogService, taskExecutor, JournalAbbreviationLoader.loadBuiltInRepository()); + viewModel = new ManageJournalAbbreviationsViewModel(preferences, dialogService, taskExecutor, repository); emptyTestFile = createTestFile(tempFolder, "emptyTestFile.csv", ""); testFile1Entries = createTestFile(tempFolder, "testFile1Entries.csv", "Test Entry;TE" + NEWLINE + ""); testFile3Entries = createTestFile(tempFolder, "testFile3Entries.csv", "Abbreviations;Abb;A" + NEWLINE + "Test Entry;TE" + NEWLINE + "MoreEntries;ME;M" + NEWLINE + ""); @@ -70,7 +71,7 @@ void testInitialHasNoFilesAndNoAbbreviations() { } @Test - void testInitialWithSavedFilesIncrementsFilesCounter() throws Exception { + void testInitialWithSavedFilesIncrementsFilesCounter() { addFourTestFileToViewModelAndPreferences(); viewModel.createFileObjects(); @@ -78,7 +79,7 @@ void testInitialWithSavedFilesIncrementsFilesCounter() throws Exception { } @Test - void testRemoveDuplicatesWhenReadingFiles() throws Exception { + void testRemoveDuplicatesWhenReadingFiles() { addFourTestFileToViewModelAndPreferences(); viewModel.createFileObjects(); viewModel.selectLastJournalFile(); @@ -88,7 +89,7 @@ void testRemoveDuplicatesWhenReadingFiles() throws Exception { } @Test - void addFileIncreasesCounterOfOpenFilesAndHasNoAbbreviations() throws Exception { + void addFileIncreasesCounterOfOpenFilesAndHasNoAbbreviations() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(emptyTestFile)); viewModel.addNewFile(); @@ -97,7 +98,7 @@ void addFileIncreasesCounterOfOpenFilesAndHasNoAbbreviations() throws Exception } @Test - void addDuplicatedFileResultsInErrorDialog() throws Exception { + void addDuplicatedFileResultsInErrorDialog() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile1Entries)); viewModel.addNewFile(); viewModel.addNewFile(); @@ -105,7 +106,7 @@ void addDuplicatedFileResultsInErrorDialog() throws Exception { } @Test - void testOpenDuplicatedFileResultsInAnException() throws Exception { + void testOpenDuplicatedFileResultsInAnException() { when(dialogService.showFileOpenDialog(any())).thenReturn(Optional.of(testFile1Entries)); viewModel.openFile(); viewModel.openFile(); @@ -113,7 +114,7 @@ void testOpenDuplicatedFileResultsInAnException() throws Exception { } @Test - void testSelectLastJournalFileSwitchesFilesAndTheirAbbreviations() throws Exception { + void testSelectLastJournalFileSwitchesFilesAndTheirAbbreviations() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(emptyTestFile)); viewModel.addNewFile(); viewModel.selectLastJournalFile(); @@ -126,7 +127,7 @@ void testSelectLastJournalFileSwitchesFilesAndTheirAbbreviations() throws Except } @Test - void testOpenValidFileContainsTheSpecificEntryAndEnoughAbbreviations() throws Exception { + void testOpenValidFileContainsTheSpecificEntryAndEnoughAbbreviations() { Abbreviation testAbbreviation = new Abbreviation("Test Entry", "TE"); when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile3Entries)); viewModel.addNewFile(); @@ -139,7 +140,7 @@ void testOpenValidFileContainsTheSpecificEntryAndEnoughAbbreviations() throws Ex } @Test - void testRemoveLastListSetsCurrentFileAndCurrentAbbreviationToNull() throws Exception { + void testRemoveLastListSetsCurrentFileAndCurrentAbbreviationToNull() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile1Entries)); viewModel.addNewFile(); viewModel.removeCurrentFile(); @@ -151,7 +152,7 @@ void testRemoveLastListSetsCurrentFileAndCurrentAbbreviationToNull() throws Exce } @Test - void testMixedFileUsage() throws Exception { + void testMixedFileUsage() { Abbreviation testAbbreviation = new Abbreviation("Entry", "E"); Abbreviation testAbbreviation2 = new Abbreviation("EntryEntry", "EE"); @@ -197,17 +198,17 @@ void testBuiltInListsIncludeAllBuiltInAbbreviations() { viewModel.addBuiltInList(); assertEquals(1, viewModel.journalFilesProperty().getSize()); viewModel.currentFileProperty().set(viewModel.journalFilesProperty().get(0)); - ObservableList expected = FXCollections - .observableArrayList(JournalAbbreviationLoader.getBuiltInAbbreviations()); + ObservableList expected = FXCollections.observableArrayList(repository.getAllLoaded()); ObservableList actualAbbreviations = FXCollections .observableArrayList(viewModel.abbreviationsProperty().stream() - .map(AbbreviationViewModel::getAbbreviationObject).collect(Collectors.toList())); + .map(AbbreviationViewModel::getAbbreviationObject) + .collect(Collectors.toList())); assertEquals(expected, actualAbbreviations); } @Test - void testCurrentFilePropertyChangeActiveFile() throws Exception { + void testCurrentFilePropertyChangeActiveFile() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile1Entries)); viewModel.addNewFile(); when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile3Entries)); @@ -241,7 +242,7 @@ void testCurrentFilePropertyChangeActiveFile() throws Exception { } @Test - void testAddAbbreviationIncludesAbbreviationsInAbbreviationList() throws Exception { + void testAddAbbreviationIncludesAbbreviationsInAbbreviationList() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile4Entries)); viewModel.addNewFile(); when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile5EntriesWithDuplicate)); @@ -255,7 +256,7 @@ void testAddAbbreviationIncludesAbbreviationsInAbbreviationList() throws Excepti } @Test - void testAddDuplicatedAbbreviationResultsInException() throws JabRefException { + void testAddDuplicatedAbbreviationResultsInException() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile3Entries)); viewModel.addNewFile(); viewModel.selectLastJournalFile(); @@ -265,7 +266,7 @@ void testAddDuplicatedAbbreviationResultsInException() throws JabRefException { } @Test - void testEditSameAbbreviationWithNoChangeDoesNotResultInException() throws Exception { + void testEditSameAbbreviationWithNoChangeDoesNotResultInException() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(emptyTestFile)); viewModel.addNewFile(); viewModel.selectLastJournalFile(); @@ -277,7 +278,7 @@ void testEditSameAbbreviationWithNoChangeDoesNotResultInException() throws Excep } @Test - void testEditAbbreviationIncludesNewAbbreviationInAbbreviationsList() throws Exception { + void testEditAbbreviationIncludesNewAbbreviationInAbbreviationsList() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile4Entries)); viewModel.addNewFile(); when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile5EntriesWithDuplicate)); @@ -300,7 +301,7 @@ void testEditAbbreviationIncludesNewAbbreviationInAbbreviationsList() throws Exc } @Test - void testEditAbbreviationToExistingOneResultsInException() throws Exception { + void testEditAbbreviationToExistingOneResultsInException() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile3Entries)); viewModel.addNewFile(); viewModel.selectLastJournalFile(); @@ -315,7 +316,7 @@ void testEditAbbreviationToExistingOneResultsInException() throws Exception { } @Test - void testEditAbbreviationToEmptyNameResultsInException() throws Exception { + void testEditAbbreviationToEmptyNameResultsInException() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile3Entries)); viewModel.addNewFile(); viewModel.selectLastJournalFile(); @@ -328,7 +329,7 @@ void testEditAbbreviationToEmptyNameResultsInException() throws Exception { } @Test - void testEditAbbreviationToEmptyAbbreviationResultsInException() throws Exception { + void testEditAbbreviationToEmptyAbbreviationResultsInException() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile3Entries)); viewModel.addNewFile(); viewModel.selectLastJournalFile(); @@ -341,7 +342,7 @@ void testEditAbbreviationToEmptyAbbreviationResultsInException() throws Exceptio } @Test - void testDeleteAbbreviationSelectsPreviousOne() throws Exception { + void testDeleteAbbreviationSelectsPreviousOne() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile4Entries)); viewModel.addNewFile(); when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile5EntriesWithDuplicate)); @@ -361,7 +362,7 @@ void testDeleteAbbreviationSelectsPreviousOne() throws Exception { } @Test - void testDeleteAbbreviationSelectsNextOne() throws Exception { + void testDeleteAbbreviationSelectsNextOne() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile1Entries)); viewModel.addNewFile(); viewModel.selectLastJournalFile(); @@ -417,10 +418,11 @@ void testSaveAbbreviationsToFilesCreatesNewFilesWithWrittenAbbreviations() throw } @Test - void testSaveExternalFilesListToPreferences() throws Exception { + void testSaveExternalFilesListToPreferences() { addFourTestFileToViewModelAndPreferences(); List expected = Stream.of(testFile1Entries, testFile3Entries, testFile4Entries, testFile5EntriesWithDuplicate) - .map(Path::toString).collect(Collectors.toList()); + .map(Path::toString) + .collect(Collectors.toList()); verify(abbreviationPreferences).setExternalJournalLists(expected); } @@ -430,15 +432,15 @@ private Path createTestFile(Path folder, String name, String content) throws Exc return file; } - private void addAbbrevaition(Abbreviation testAbbreviation) throws Exception { + private void addAbbrevaition(Abbreviation testAbbreviation) { viewModel.addAbbreviation(testAbbreviation.getName(), testAbbreviation.getAbbreviation()); } - private void editAbbreviation(Abbreviation testAbbreviation) throws Exception { + private void editAbbreviation(Abbreviation testAbbreviation) { viewModel.editAbbreviation(testAbbreviation.getName(), testAbbreviation.getAbbreviation()); } - private void addFourTestFileToViewModelAndPreferences() throws Exception { + private void addFourTestFileToViewModelAndPreferences() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile1Entries)); viewModel.addNewFile(); when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile3Entries)); diff --git a/src/test/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModelNoShortestUniqueAbbreviationsTest.java b/src/test/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModelNoShortestUniqueAbbreviationsTest.java index 22705f86720..07e4b9ddc6b 100644 --- a/src/test/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModelNoShortestUniqueAbbreviationsTest.java +++ b/src/test/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModelNoShortestUniqueAbbreviationsTest.java @@ -19,6 +19,7 @@ import org.jabref.logic.journals.Abbreviation; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.preferences.PreferencesService; import org.junit.jupiter.api.BeforeEach; @@ -46,6 +47,7 @@ class ManageJournalAbbreviationsViewModelNoShortestUniqueAbbreviationsTest { private Path testFile5EntriesWithDuplicate; private JournalAbbreviationPreferences abbreviationPreferences; private DialogService dialogService; + private final JournalAbbreviationRepository repository = JournalAbbreviationLoader.loadBuiltInRepository(); @BeforeEach void setUpViewModel(@TempDir Path tempFolder) throws Exception { @@ -55,7 +57,7 @@ void setUpViewModel(@TempDir Path tempFolder) throws Exception { dialogService = mock(DialogService.class); TaskExecutor taskExecutor = new CurrentThreadTaskExecutor(); - viewModel = new ManageJournalAbbreviationsViewModel(preferences, dialogService, taskExecutor, JournalAbbreviationLoader.loadBuiltInRepository()); + viewModel = new ManageJournalAbbreviationsViewModel(preferences, dialogService, taskExecutor, repository); emptyTestFile = createTestFile(tempFolder, "emptyTestFile.csv", ""); testFile1Entries = createTestFile(tempFolder, "testFile1Entries.csv", "Test Entry;TE" + NEWLINE + ""); testFile3Entries = createTestFile(tempFolder, "testFile3Entries.csv", "Abbreviations;Abb" + NEWLINE + "Test Entry;TE" + NEWLINE + "MoreEntries;ME" + NEWLINE + ""); @@ -198,7 +200,7 @@ void testBuiltInListsIncludeAllBuiltInAbbreviations() { assertEquals(1, viewModel.journalFilesProperty().getSize()); viewModel.currentFileProperty().set(viewModel.journalFilesProperty().get(0)); ObservableList expected = FXCollections - .observableArrayList(JournalAbbreviationLoader.getBuiltInAbbreviations()); + .observableArrayList(repository.getAllLoaded()); ObservableList actualAbbreviations = FXCollections .observableArrayList(viewModel.abbreviationsProperty().stream() .map(AbbreviationViewModel::getAbbreviationObject).collect(Collectors.toList())); diff --git a/src/test/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModelWithShortestUniqueAbbreviationsTest.java b/src/test/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModelWithShortestUniqueAbbreviationsTest.java index 50b3810c54d..c098839f1b1 100644 --- a/src/test/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModelWithShortestUniqueAbbreviationsTest.java +++ b/src/test/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModelWithShortestUniqueAbbreviationsTest.java @@ -19,6 +19,7 @@ import org.jabref.logic.journals.Abbreviation; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.preferences.PreferencesService; import org.junit.jupiter.api.BeforeEach; @@ -46,6 +47,7 @@ class ManageJournalAbbreviationsViewModelWithShortestUniqueAbbreviationsTest { private Path testFile5EntriesWithDuplicate; private JournalAbbreviationPreferences abbreviationPreferences; private DialogService dialogService; + private final JournalAbbreviationRepository repository = JournalAbbreviationLoader.loadBuiltInRepository(); @BeforeEach void setUpViewModel(@TempDir Path tempFolder) throws Exception { @@ -55,7 +57,7 @@ void setUpViewModel(@TempDir Path tempFolder) throws Exception { dialogService = mock(DialogService.class); TaskExecutor taskExecutor = new CurrentThreadTaskExecutor(); - viewModel = new ManageJournalAbbreviationsViewModel(preferences, dialogService, taskExecutor, JournalAbbreviationLoader.loadBuiltInRepository()); + viewModel = new ManageJournalAbbreviationsViewModel(preferences, dialogService, taskExecutor, repository); emptyTestFile = createTestFile(tempFolder, "emptyTestFile.csv", ""); testFile1Entries = createTestFile(tempFolder, "testFile1Entries.csv", "Test Entry;TE;T" + NEWLINE + ""); testFile3Entries = createTestFile(tempFolder, "testFile3Entries.csv", "Abbreviations;Abb;A" + NEWLINE + "Test Entry;TE;T" + NEWLINE + "MoreEntries;ME;M" + NEWLINE + ""); @@ -198,7 +200,7 @@ void testBuiltInListsIncludeAllBuiltInAbbreviations() { assertEquals(1, viewModel.journalFilesProperty().getSize()); viewModel.currentFileProperty().set(viewModel.journalFilesProperty().get(0)); ObservableList expected = FXCollections - .observableArrayList(JournalAbbreviationLoader.getBuiltInAbbreviations()); + .observableArrayList(repository.getAllLoaded()); ObservableList actualAbbreviations = FXCollections .observableArrayList(viewModel.abbreviationsProperty().stream() .map(AbbreviationViewModel::getAbbreviationObject).collect(Collectors.toList())); diff --git a/src/test/java/org/jabref/logic/journals/AbbreviationParserTest.java b/src/test/java/org/jabref/logic/journals/AbbreviationParserTest.java deleted file mode 100644 index 941a5599701..00000000000 --- a/src/test/java/org/jabref/logic/journals/AbbreviationParserTest.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.jabref.logic.journals; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertFalse; - -public class AbbreviationParserTest { - - @Test - public void testReadJournalListFromResource() { - AbbreviationParser ap = new AbbreviationParser(); - ap.readJournalListFromResource("/journals/journalList.csv"); - assertFalse(ap.getAbbreviations().isEmpty()); - } -} diff --git a/src/test/java/org/jabref/logic/journals/AbbreviationsTest.java b/src/test/java/org/jabref/logic/journals/AbbreviationsTest.java index 049bf2f75bb..3f2d01f3f47 100644 --- a/src/test/java/org/jabref/logic/journals/AbbreviationsTest.java +++ b/src/test/java/org/jabref/logic/journals/AbbreviationsTest.java @@ -16,13 +16,11 @@ void setUp() { @Test void getNextAbbreviationAbbreviatesJournalTitle() { - assertEquals("2D Mater.", - repository.getNextAbbreviation("2D Materials").get()); + assertEquals("2D Mater.", repository.getNextAbbreviation("2D Materials").get()); } @Test void getNextAbbreviationConvertsAbbreviationToDotLessAbbreviation() { - assertEquals("2D Mater", - repository.getNextAbbreviation("2D Mater.").get()); + assertEquals("2D Mater", repository.getNextAbbreviation("2D Mater.").get()); } }