From 26cd572d4e0587ddf763edc3f9be4caafb1844e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bitor=20Tonixa=20Biriato=20Balen=C3=A7a?= Date: Thu, 27 Dec 2018 11:20:29 +0000 Subject: [PATCH 1/8] Cleanup interfaces (#4553) --- .../org/jabref/gui/autocompleter/AutoCompletionStrategy.java | 3 +-- src/main/java/org/jabref/preferences/PreferencesService.java | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompletionStrategy.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompletionStrategy.java index 50e835a3a9f..efde39c6561 100644 --- a/src/main/java/org/jabref/gui/autocompleter/AutoCompletionStrategy.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompletionStrategy.java @@ -1,6 +1,5 @@ package org.jabref.gui.autocompleter; public interface AutoCompletionStrategy { - - public AutoCompletionInput analyze(String input); + AutoCompletionInput analyze(String input); } diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index 00da6820019..97931addffa 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -35,9 +35,9 @@ public interface PreferencesService { void setCustomTabsNameAndFields(String name, String fields, int defNumber); - public void purgeSeries(String prefix, int number); + void purgeSeries(String prefix, int number); - public void updateEntryEditorTabList(); + void updateEntryEditorTabList(); List getCustomExportFormats(JournalAbbreviationLoader loader); From b936ba9c775efb9569f5aac142d19c50e460dcde Mon Sep 17 00:00:00 2001 From: Matthias Geiger Date: Fri, 28 Dec 2018 16:31:13 +0100 Subject: [PATCH 2/8] improve styling of preferences side menu (#4556) --- .../org/jabref/gui/preferences/PreferencesDialog.css | 2 ++ .../org/jabref/gui/preferences/PreferencesDialog.java | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesDialog.css b/src/main/java/org/jabref/gui/preferences/PreferencesDialog.css index 21717a7709c..2b2d8c34859 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesDialog.css +++ b/src/main/java/org/jabref/gui/preferences/PreferencesDialog.css @@ -1,5 +1,7 @@ #sideMenu { -fx-background-color: -jr-white; + -fx-border-color: -fx-outer-border; + -fx-border-width: 1; } #sideMenu > .virtual-flow > .clipped-container > .sheet > .list-cell { diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesDialog.java b/src/main/java/org/jabref/gui/preferences/PreferencesDialog.java index 53a8d561a11..72da827e2e2 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesDialog.java +++ b/src/main/java/org/jabref/gui/preferences/PreferencesDialog.java @@ -116,20 +116,21 @@ private void construct() { VBox buttonContainer = new VBox(); buttonContainer.setAlignment(Pos.BOTTOM_LEFT); + buttonContainer.setSpacing(3.0); Button importPreferences = new Button(Localization.lang("Import preferences")); importPreferences.setTooltip(new Tooltip(Localization.lang("Import preferences from file"))); importPreferences.setOnAction(e -> importPreferences()); - importPreferences.getStyleClass().add("text-button"); + importPreferences.setMaxWidth(Double.MAX_VALUE); Button exportPreferences = new Button(Localization.lang("Export preferences")); exportPreferences.setTooltip(new Tooltip(Localization.lang("Export preferences to file"))); exportPreferences.setOnAction(e -> exportPreferences()); - exportPreferences.getStyleClass().add("text-button"); + exportPreferences.setMaxWidth(Double.MAX_VALUE); Button showPreferences = new Button(Localization.lang("Show preferences")); showPreferences.setOnAction(e -> new PreferencesFilterDialog(new JabRefPreferencesFilter(prefs)).setVisible(true)); - showPreferences.getStyleClass().add("text-button"); + showPreferences.setMaxWidth(Double.MAX_VALUE); Button resetPreferences = new Button(Localization.lang("Reset preferences")); resetPreferences.setOnAction(e -> resetPreferences()); - resetPreferences.getStyleClass().add("text-button"); + resetPreferences.setMaxWidth(Double.MAX_VALUE); buttonContainer.getChildren().addAll( importPreferences, exportPreferences, @@ -138,6 +139,7 @@ private void construct() { ); VBox spacer = new VBox(); + spacer.setPrefHeight(10.0); VBox.setVgrow(tabsList, Priority.ALWAYS); VBox.setVgrow(spacer, Priority.SOMETIMES); vBox.getChildren().addAll( From e86e39600641e241ef19b6bd67c190f52bb0840a Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 28 Dec 2018 18:39:49 +0100 Subject: [PATCH 3/8] fix style file select layout and inline variable' --- .../openoffice/DetectOpenOfficeInstallation.java | 4 +--- .../jabref/gui/openoffice/StyleSelectDialog.fxml | 15 +++++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java b/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java index eefa44742de..8296e553cae 100644 --- a/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java +++ b/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java @@ -31,7 +31,6 @@ public class DetectOpenOfficeInstallation { private final OpenOfficePreferences preferences; private final DialogService dialogService; - private FXDialog progressDialog; public DetectOpenOfficeInstallation(OpenOfficePreferences preferences, DialogService dialogService) { this.preferences = preferences; @@ -52,8 +51,7 @@ public FXDialog initProgressDialog() { DialogPane dialogPane = new DialogPane(); ProgressIndicator indicator = new ProgressIndicator(ProgressIndicator.INDETERMINATE_PROGRESS); dialogPane.setContent(indicator); - - progressDialog = dialogService.showCustomDialog(Localization.lang("Autodetecting paths..."), dialogPane, ButtonType.CANCEL); + FXDialog progressDialog = dialogService.showCustomDialog(Localization.lang("Autodetecting paths..."), dialogPane, ButtonType.CANCEL); progressDialog.show(); return progressDialog; diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.fxml b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.fxml index dc0c7ab210e..f994d348787 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.fxml +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.fxml @@ -8,17 +8,20 @@ - + - - - - + + + + + + + @@ -31,6 +34,6 @@ - + From 404064c49694121fd2ba1c056148deac44185af4 Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Fri, 28 Dec 2018 18:48:24 +0100 Subject: [PATCH 4/8] Add Book as preview as well --- .../gui/openoffice/StyleSelectDialogView.java | 15 ++++++++++----- .../java/org/jabref/logic/util/TestEntry.java | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogView.java b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogView.java index 28778d0d6a3..c629791f0be 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogView.java +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogView.java @@ -44,7 +44,8 @@ public class StyleSelectDialogView extends BaseDialog { private StyleSelectDialogViewModel viewModel; private final DialogService dialogService; private final StyleLoader loader; - private PreviewPanel preview; + private PreviewPanel previewArticle; + private PreviewPanel previewBook; public StyleSelectDialogView(DialogService dialogService, StyleLoader loader) { this.dialogService = dialogService; @@ -70,10 +71,13 @@ private void initialize() { viewModel = new StyleSelectDialogViewModel(dialogService, loader, preferencesService); - preview = new PreviewPanel(null, new BibDatabaseContext(), preferencesService.getKeyBindingRepository(), preferencesService.getPreviewPreferences(), dialogService, ExternalFileTypes.getInstance()); - preview.setEntry(TestEntry.getTestEntry()); + previewArticle = new PreviewPanel(null, new BibDatabaseContext(), preferencesService.getKeyBindingRepository(), preferencesService.getPreviewPreferences(), dialogService, ExternalFileTypes.getInstance()); + previewArticle.setEntry(TestEntry.getTestEntry()); + vbox.getChildren().add(previewArticle); - vbox.getChildren().add(preview); + previewBook = new PreviewPanel(null, new BibDatabaseContext(), preferencesService.getKeyBindingRepository(), preferencesService.getPreviewPreferences(), dialogService, ExternalFileTypes.getInstance()); + previewBook.setEntry(TestEntry.getTestEntryBook()); + vbox.getChildren().add(previewBook); colName.setCellValueFactory(cellData -> cellData.getValue().nameProperty()); colJournals.setCellValueFactory(cellData -> cellData.getValue().journalsProperty()); @@ -115,7 +119,8 @@ private void initialize() { EasyBind.subscribe(viewModel.selectedItemProperty(), style -> { tvStyles.getSelectionModel().select(style); - preview.setLayout(style.getStyle().getReferenceFormat("default")); + previewArticle.setLayout(style.getStyle().getReferenceFormat("default")); + previewBook.setLayout(style.getStyle().getReferenceFormat("default")); }); } diff --git a/src/main/java/org/jabref/logic/util/TestEntry.java b/src/main/java/org/jabref/logic/util/TestEntry.java index 8d2b3920b87..34d920dcf87 100644 --- a/src/main/java/org/jabref/logic/util/TestEntry.java +++ b/src/main/java/org/jabref/logic/util/TestEntry.java @@ -1,6 +1,8 @@ package org.jabref.logic.util; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryType; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.FieldName; public class TestEntry { @@ -29,4 +31,17 @@ public static BibEntry getTestEntry() { "This entry describes a test scenario which may be useful in JabRef. By providing a test entry it is possible to see how certain things will look in this graphical BIB-file mananger."); return entry; } + + public static BibEntry getTestEntryBook() { + BibEntry entry = new BibEntry(BibtexEntryTypes.BOOK); + entry.setCiteKey("Harrer2018"); + entry.setField(FieldName.AUTHOR, "Simon Harrer and Jörg Lenhard and Linus Dietz"); + entry.setField(FieldName.EDITOR, "Andrea Steward"); + entry.setField(FieldName.TITLE, "Java by Comparison"); + entry.setField(FieldName.YEAR, "2018"); + entry.setField(FieldName.MONTH, "March"); + entry.setField(FieldName.PUBLISHER, "Pragmatic Bookshelf"); + entry.setField(FieldName.ADDRESS, "Raleigh, NC"); + return entry; + } } From 3f2ba612185169c85c20064c47915e5fd50e9840 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 28 Dec 2018 19:25:50 +0100 Subject: [PATCH 5/8] change mac default settings to LO path --- .../org/jabref/logic/openoffice/OpenOfficePreferences.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/openoffice/OpenOfficePreferences.java b/src/main/java/org/jabref/logic/openoffice/OpenOfficePreferences.java index 208bf52ca60..f3d6a0b29a0 100644 --- a/src/main/java/org/jabref/logic/openoffice/OpenOfficePreferences.java +++ b/src/main/java/org/jabref/logic/openoffice/OpenOfficePreferences.java @@ -10,8 +10,8 @@ public class OpenOfficePreferences { public static final String DEFAULT_WIN_EXEC_PATH = "C:\\Program Files\\LibreOffice 5\\program"; public static final String WINDOWS_EXECUTABLE = "soffice.exe"; - public static final String DEFAULT_OSX_PATH = "/Applications/OpenOffice.org.app"; - public static final String DEFAULT_OSX_EXEC_PATH = "/Applications/OpenOffice.org.app/Contents/MacOS/soffice"; + public static final String DEFAULT_OSX_PATH = "/Applications/LibreOffice.app"; + public static final String DEFAULT_OSX_EXEC_PATH = "/Applications/LibreOffice.app/Contents/MacOS/soffice"; public static final String OSX_EXECUTABLE = "soffice"; public static final String DEFAULT_LINUX_PATH = "/usr/lib/libreoffice"; From b4ac024549243b6a021d62fac9e7f057fca2fa8d Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 28 Dec 2018 19:44:43 +0100 Subject: [PATCH 6/8] checkstyle --- src/main/java/org/jabref/logic/util/TestEntry.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/util/TestEntry.java b/src/main/java/org/jabref/logic/util/TestEntry.java index 34d920dcf87..1d0e85c1912 100644 --- a/src/main/java/org/jabref/logic/util/TestEntry.java +++ b/src/main/java/org/jabref/logic/util/TestEntry.java @@ -1,7 +1,6 @@ package org.jabref.logic.util; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BibtexEntryType; import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.FieldName; From 3a09fa2e7ca8236670b45c5c4508a05ddae111fc Mon Sep 17 00:00:00 2001 From: conorfos <40298107+conorfos@users.noreply.github.com> Date: Fri, 28 Dec 2018 18:47:17 +0000 Subject: [PATCH 7/8] Added extra stats to be sent with MrDLib recommendations (#4452) --- .../gui/entryeditor/RelatedArticlesTab.java | 24 ++++++++++++++++--- .../logic/importer/fetcher/MrDLibFetcher.java | 22 +++++++++++++---- .../importer/fileformat/MrDLibImporter.java | 4 ++-- .../jabref/preferences/JabRefPreferences.java | 6 +++++ src/main/resources/l10n/JabRef_en.properties | 17 ++++++++++--- .../fileformat/MrDLibImporterTest.java | 2 +- 6 files changed, 62 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java index dbbe9ff096a..4bd30b7c614 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java @@ -4,6 +4,7 @@ import java.util.List; import javafx.scene.control.Button; +import javafx.scene.control.CheckBox; import javafx.scene.control.Hyperlink; import javafx.scene.control.ProgressIndicator; import javafx.scene.control.ScrollPane; @@ -125,10 +126,12 @@ private ScrollPane getPrivacyDialog(BibEntry entry) { Button button = new Button(Localization.lang("I Agree")); button.setDefaultButton(true); - Text line1 = new Text(Localization.lang("Mr. DLib is an external service which provides article recommendations based on the currently selected entry. Data about the selected entry must be sent to Mr. DLib in order to provide these recommendations. Do you agree that this data may be sent?")); + Text line1 = new Text(Localization.lang("JabRef requests recommendations from Mr. DLib, which is an external service. To enable Mr. DLib to calculate recommendations, some of your data must be shared with Mr. DLib. Generally, the more data is shared the better recommendations can be calculated. However, we understand that some of your data in JabRef is sensitive, and you may not want to share it. Therefore, Mr. DLib offers a choice of which data you would like to share.")); line1.setWrappingWidth(1300.0); - Text line2 = new Text(Localization.lang("This setting may be changed in preferences at any time.")); + Text line2 = new Text(Localization.lang("Whatever option you choose, Mr. DLib may share its data with research partners to further improve recommendation quality as part of a 'living lab'. Mr. DLib may also release public datasets that may contain anonymized information about you and the recommendations (sensitive information such as metadata of your articles will be anonymised through e.g. hashing). Research partners are obliged to adhere to the same strict data protection policy as Mr. DLib.")); + line2.setWrappingWidth(1300.0); + Text line3 = new Text(Localization.lang("This setting may be changed in preferences at any time.")); Hyperlink mdlLink = new Hyperlink(Localization.lang("Further information about Mr DLib. for JabRef users.")); mdlLink.setOnAction(event -> { try { @@ -138,15 +141,30 @@ private ScrollPane getPrivacyDialog(BibEntry entry) { dialogService.showErrorDialogAndWait(e); } }); + VBox vb = new VBox(); + CheckBox cbTitle = new CheckBox(Localization.lang("Entry Title (Required to deliver recommendations.)")); + cbTitle.setSelected(true); + cbTitle.setDisable(true); + CheckBox cbVersion = new CheckBox(Localization.lang("JabRef Version (Required to ensure backwards compatibility with Mr. DLib's Web Service)")); + cbVersion.setSelected(true); + cbVersion.setDisable(true); + CheckBox cbLanguage = new CheckBox(Localization.lang("JabRef Language (Provides for better recommendations by giving an indication of user's preferred language.)")); + CheckBox cbOS = new CheckBox(Localization.lang("Operating System (Provides for better recommendations by giving an indication of user's system set-up.)")); + CheckBox cbTimezone = new CheckBox(Localization.lang("Timezone (Provides for better recommendations by indicating the time of day the request is being made.)")); + vb.getChildren().addAll(cbTitle, cbVersion, cbLanguage, cbOS, cbTimezone); + vb.setSpacing(10); button.setOnAction(event -> { JabRefPreferences prefs = JabRefPreferences.getInstance(); prefs.putBoolean(JabRefPreferences.ACCEPT_RECOMMENDATIONS, true); + prefs.putBoolean(JabRefPreferences.SEND_LANGUAGE_DATA, cbLanguage.isSelected()); + prefs.putBoolean(JabRefPreferences.SEND_OS_DATA, cbOS.isSelected()); + prefs.putBoolean(JabRefPreferences.SEND_TIMEZONE_DATA, cbTimezone.isSelected()); dialogService.showWarningDialogAndWait(Localization.lang("Restart"), Localization.lang("Please restart JabRef for preferences to take effect.")); setContent(getRelatedArticlesPane(entry)); }); - vbox.getChildren().addAll(line1, mdlLink, line2, button); + vbox.getChildren().addAll(line1, line2, mdlLink, line3, vb, button); root.setContent(vbox); return root; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java index 2ae7db36e35..0e3e30898bd 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java @@ -4,6 +4,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; import java.util.Optional; @@ -16,6 +17,7 @@ import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; +import org.jabref.preferences.JabRefPreferences; import org.apache.http.client.utils.URIBuilder; import org.slf4j.Logger; @@ -27,6 +29,7 @@ public class MrDLibFetcher implements EntryBasedFetcher { private static final Logger LOGGER = LoggerFactory.getLogger(MrDLibFetcher.class); private static final String NAME = "MDL_FETCHER"; + private static final String MDL_JABREF_PARTNER_ID = "1"; private final String LANGUAGE; private final Version VERSION; @@ -104,11 +107,22 @@ private String constructQuery(String queryWithTitle) { URIBuilder builder = new URIBuilder(); builder.setScheme("http"); builder.setHost(getMdlUrl()); - builder.setPath("/v2/items/" + queryWithTitle + "/related_items"); - builder.addParameter("partner_id", "jabref"); + builder.setPath("/v2/documents/" + queryWithTitle + "/related_documents"); + builder.addParameter("partner_id", MDL_JABREF_PARTNER_ID); builder.addParameter("app_id", "jabref_desktop"); builder.addParameter("app_version", VERSION.getFullVersion()); - builder.addParameter("app_lang", LANGUAGE); + + JabRefPreferences prefs = JabRefPreferences.getInstance(); + if (prefs.getBoolean(JabRefPreferences.SEND_LANGUAGE_DATA)) { + builder.addParameter("app_lang", LANGUAGE); + } + if (prefs.getBoolean(JabRefPreferences.SEND_OS_DATA)) { + builder.addParameter("os", System.getProperty("os.name")); + } + if (prefs.getBoolean(JabRefPreferences.SEND_TIMEZONE_DATA)) { + builder.addParameter("timezone", Calendar.getInstance().getTimeZone().getID()); + } + try { URI uri = builder.build(); LOGGER.trace("Request: " + uri.toString()); @@ -120,6 +134,6 @@ private String constructQuery(String queryWithTitle) { } private String getMdlUrl() { - return VERSION.isDevelopmentVersion() ? "api-dev.darwingoliath.com" : "api.darwingoliath.com"; + return VERSION.isDevelopmentVersion() ? "api-dev.darwingoliath.com" : "api.mr-dlib.org"; } } diff --git a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java index 6320b8d7483..5bc8af04b8c 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java @@ -146,10 +146,10 @@ private RankedBibEntry populateBibEntry(JSONObject recommendation) { // parse each of the relevant fields into variables String authors = isRecommendationFieldPresent(recommendation, "authors") ? getAuthorsString(recommendation) : ""; String title = isRecommendationFieldPresent(recommendation, "title") ? recommendation.getString("title") : ""; - String year = isRecommendationFieldPresent(recommendation, "year_published") ? Integer.toString(recommendation.getInt("year_published")) : ""; + String year = isRecommendationFieldPresent(recommendation, "published_year") ? Integer.toString(recommendation.getInt("published_year")) : ""; String journal = isRecommendationFieldPresent(recommendation, "published_in") ? recommendation.getString("published_in") : ""; String url = isRecommendationFieldPresent(recommendation, "url") ? recommendation.getString("url") : ""; - Integer rank = isRecommendationFieldPresent(recommendation, "url") ? recommendation.getInt("recommendation_id") : 100; + Integer rank = isRecommendationFieldPresent(recommendation, "recommendation_id") ? recommendation.getInt("recommendation_id") : 100; // Populate bib entry with relevant data current.setField(FieldName.AUTHOR, authors); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 692df3eec82..5d3d38d061e 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -297,6 +297,9 @@ public class JabRefPreferences implements PreferencesService { public static final String PUSH_TO_APPLICATION = "pushToApplication"; public static final String SHOW_RECOMMENDATIONS = "showRecommendations"; public static final String ACCEPT_RECOMMENDATIONS = "acceptRecommendations"; + public static final String SEND_LANGUAGE_DATA = "sendLanguageData"; + public static final String SEND_OS_DATA = "sendOSData"; + public static final String SEND_TIMEZONE_DATA = "sendTimezoneData"; public static final String VALIDATE_IN_ENTRY_EDITOR = "validateInEntryEditor"; // Dropped file handler public static final String DROPPEDFILEHANDLER_RENAME = "DroppedFileHandler_RenameFile"; @@ -574,6 +577,9 @@ private JabRefPreferences() { defaults.put(SHOW_RECOMMENDATIONS, Boolean.TRUE); defaults.put(ACCEPT_RECOMMENDATIONS, Boolean.FALSE); + defaults.put(SEND_LANGUAGE_DATA, Boolean.FALSE); + defaults.put(SEND_OS_DATA, Boolean.FALSE); + defaults.put(SEND_TIMEZONE_DATA, Boolean.FALSE); defaults.put(VALIDATE_IN_ENTRY_EDITOR, Boolean.TRUE); defaults.put(EDITOR_EMACS_KEYBINDINGS, Boolean.FALSE); defaults.put(EDITOR_EMACS_KEYBINDINGS_REBIND_CA, Boolean.TRUE); diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 1af3cc0c045..b22353562b3 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -364,6 +364,8 @@ Entry\ table=Entry table Entry\ table\ columns=Entry table columns +Entry\ Title\ (Required\ to\ deliver\ recommendations.)=Entry Title (Required to deliver recommendations.) + Entry\ type=Entry type Entry\ type\ names\ are\ not\ allowed\ to\ contain\ white\ space\ or\ the\ following\ characters=Entry type names are not allowed to contain white space or the following characters @@ -573,8 +575,14 @@ Invalid\ URL=Invalid URL Online\ help=Online help +JabRef\ Language\ (Provides\ for\ better\ recommendations\ by\ giving\ an\ indication\ of\ user's\ preferred\ language.)=JabRef Language (Provides for better recommendations by giving an indication of user's preferred language.) + JabRef\ preferences=JabRef preferences +JabRef\ requests\ recommendations\ from\ Mr.\ DLib,\ which\ is\ an\ external\ service.\ To\ enable\ Mr.\ DLib\ to\ calculate\ recommendations,\ some\ of\ your\ data\ must\ be\ shared\ with\ Mr.\ DLib.\ Generally,\ the\ more\ data\ is\ shared\ the\ better\ recommendations\ can\ be\ calculated.\ However,\ we\ understand\ that\ some\ of\ your\ data\ in\ JabRef\ is\ sensitive,\ and\ you\ may\ not\ want\ to\ share\ it.\ Therefore,\ Mr.\ DLib\ offers\ a\ choice\ of\ which\ data\ you\ would\ like\ to\ share.=JabRef requests recommendations from Mr. DLib, which is an external service. To enable Mr. DLib to calculate recommendations, some of your data must be shared with Mr. DLib. Generally, the more data is shared the better recommendations can be calculated. However, we understand that some of your data in JabRef is sensitive, and you may not want to share it. Therefore, Mr. DLib offers a choice of which data you would like to share. + +JabRef\ Version\ (Required\ to\ ensure\ backwards\ compatibility\ with\ Mr.\ DLib's\ Web\ Service)=JabRef Version (Required to ensure backwards compatibility with Mr. DLib's Web Service) + Join=Join Joins\ selected\ keywords\ and\ deletes\ selected\ keywords.=Joins selected keywords and deletes selected keywords. @@ -653,9 +661,6 @@ Move\ up=Move up Moved\ group\ "%0".=Moved group "%0". -Mr.\ DLib\ is\ an\ external\ service\ which\ provides\ article\ recommendations\ based\ on\ the\ currently\ selected\ entry.\ Data\ about\ the\ selected\ entry\ must\ be\ sent\ to\ Mr.\ DLib\ in\ order\ to\ provide\ these\ recommendations.\ Do\ you\ agree\ that\ this\ data\ may\ be\ sent?=Mr. DLib is an external service which provides article recommendations based on the currently selected entry. Data about the selected entry must be sent to Mr. DLib in order to provide these recommendations. Do you agree that this data may be sent? - - Name=Name Name\ formatter=Name formatter @@ -735,6 +740,8 @@ Opening=Opening Operation\ canceled.=Operation canceled. +Operating\ System\ (Provides\ for\ better\ recommendations\ by\ giving\ an\ indication\ of\ user's\ system\ set-up.)=Operating System (Provides for better recommendations by giving an indication of user's system set-up.) + Optional\ fields=Optional fields Options=Options @@ -1070,6 +1077,8 @@ This\ operation\ requires\ one\ or\ more\ entries\ to\ be\ selected.=This operat This\ setting\ may\ be\ changed\ in\ preferences\ at\ any\ time.=This setting may be changed in preferences at any time. +Timezone\ (Provides\ for\ better\ recommendations\ by\ indicating\ the\ time\ of\ day\ the\ request\ is\ being\ made.)=Timezone (Provides for better recommendations by indicating the time of day the request is being made.) + Toggle\ entry\ preview=Toggle entry preview Toggle\ groups\ interface=Toggle groups interface @@ -1135,6 +1144,8 @@ web\ link=web link What\ do\ you\ want\ to\ do?=What do you want to do? +Whatever\ option\ you\ choose,\ Mr.\ DLib\ may\ share\ its\ data\ with\ research\ partners\ to\ further\ improve\ recommendation\ quality\ as\ part\ of\ a\ 'living\ lab'.\ Mr.\ DLib\ may\ also\ release\ public\ datasets\ that\ may\ contain\ anonymized\ information\ about\ you\ and\ the\ recommendations\ (sensitive\ information\ such\ as\ metadata\ of\ your\ articles\ will\ be\ anonymised\ through\ e.g.\ hashing).\ Research\ partners\ are\ obliged\ to\ adhere\ to\ the\ same\ strict\ data\ protection\ policy\ as\ Mr.\ DLib.=Whatever option you choose, Mr. DLib may share its data with research partners to further improve recommendation quality as part of a 'living lab'. Mr. DLib may also release public datasets that may contain anonymized information about you and the recommendations (sensitive information such as metadata of your articles will be anonymised through e.g. hashing). Research partners are obliged to adhere to the same strict data protection policy as Mr. DLib. + When\ adding/removing\ keywords,\ separate\ them\ by=When adding/removing keywords, separate them by Will\ write\ XMP-metadata\ to\ the\ PDFs\ linked\ from\ selected\ entries.=Will write XMP-metadata to the PDFs linked from selected entries. diff --git a/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java index 5af07b4dfa3..723afd1b6fc 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java @@ -24,7 +24,7 @@ public class MrDLibImporterTest { @BeforeEach public void setUp() { importer = new MrDLibImporter(); - String testInput = "{ \"label\": { \"label-language\": \"en\", \"label-text\": \"Related Items\" }, \"recommendation-set-id\": \"1\", \"recommendations\": { \"74021358\": { \"abstract\": \"abstract\", \"authors\": [ \"Sajovic, Marija\" ], \"year_published\": \"2006\", \"item_id_original\": \"12088644\", \"keywords\": [ \"visoko\\u0161olski program Geodezija - smer Prostorska informatika\" ], \"language_provided\": \"sl\", \"recommendation_id\": \"1\", \"title\": \"The protection of rural lands with the spatial development strategy on the case of Hrastnik commune\", \"url\": \"http://drugg.fgg.uni-lj.si/701/1/GEV_0199_Sajovic.pdf\" }, \"82005804\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"30145702\", \"language_provided\": null, \"recommendation_id\": \"2\", \"title\": \"Engagement of the volunteers in the solution to the accidents in the South-Moravia region\" }, \"82149599\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"97690763\", \"language_provided\": null, \"recommendation_id\": \"3\", \"title\": \"\\\"The only Father's word\\\". The relationship of the Father and the Son in the documents of saint John of the Cross\", \"url\": \"http://www.nusl.cz/ntk/nusl-285711\" }, \"84863921\": { \"abstract\": \"abstract\", \"authors\": [ \"Kaffa, Elena\" ], \"year_published\": null, \"item_id_original\": \"19397104\", \"keywords\": [ \"BX\", \"D111\" ], \"language_provided\": \"en\", \"recommendation_id\": \"4\", \"title\": \"Greek Church of Cyprus, the Morea and Constantinople during the Frankish Era (1196-1303)\" }, \"88950992\": { \"abstract\": \"abstract\", \"authors\": [ \"Yasui, Kono\" ], \"year_published\": null, \"item_id_original\": \"38763657\", \"language_provided\": null, \"recommendation_id\": \"5\", \"title\": \"A Phylogenetic Consideration on the Vascular Plants, Cotyledonary Node Including Hypocotyl Being Taken as the Ancestral Form : A Preliminary Note\" } }}"; + String testInput = "{ \"label\": { \"label-language\": \"en\", \"label-text\": \"Related Items\" }, \"recommendation-set-id\": \"1\", \"recommendations\": { \"74021358\": { \"abstract\": \"abstract\", \"authors\": [ \"Sajovic, Marija\" ], \"published_year\": \"2006\", \"item_id_original\": \"12088644\", \"keywords\": [ \"visoko\\u0161olski program Geodezija - smer Prostorska informatika\" ], \"language_provided\": \"sl\", \"recommendation_id\": \"1\", \"title\": \"The protection of rural lands with the spatial development strategy on the case of Hrastnik commune\", \"url\": \"http://drugg.fgg.uni-lj.si/701/1/GEV_0199_Sajovic.pdf\" }, \"82005804\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"30145702\", \"language_provided\": null, \"recommendation_id\": \"2\", \"title\": \"Engagement of the volunteers in the solution to the accidents in the South-Moravia region\" }, \"82149599\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"97690763\", \"language_provided\": null, \"recommendation_id\": \"3\", \"title\": \"\\\"The only Father's word\\\". The relationship of the Father and the Son in the documents of saint John of the Cross\", \"url\": \"http://www.nusl.cz/ntk/nusl-285711\" }, \"84863921\": { \"abstract\": \"abstract\", \"authors\": [ \"Kaffa, Elena\" ], \"year_published\": null, \"item_id_original\": \"19397104\", \"keywords\": [ \"BX\", \"D111\" ], \"language_provided\": \"en\", \"recommendation_id\": \"4\", \"title\": \"Greek Church of Cyprus, the Morea and Constantinople during the Frankish Era (1196-1303)\" }, \"88950992\": { \"abstract\": \"abstract\", \"authors\": [ \"Yasui, Kono\" ], \"year_published\": null, \"item_id_original\": \"38763657\", \"language_provided\": null, \"recommendation_id\": \"5\", \"title\": \"A Phylogenetic Consideration on the Vascular Plants, Cotyledonary Node Including Hypocotyl Being Taken as the Ancestral Form : A Preliminary Note\" } }}"; input = new BufferedReader(new StringReader(testInput)); } From cd1e795e91a0f36ea33386c47f06e31e7f812481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bitor=20Tonixa=20Biriato=20Balen=C3=A7a?= Date: Fri, 28 Dec 2018 22:39:28 +0000 Subject: [PATCH 8/8] Refactor BibEntry deprecated method (#4554) * Refactor BibEntry deprecated method * Fixed error * More on checkstyle fixing * Fixed checkstyle issues * Added custom entrytype for types not registered in the enumerator. * Added getTypeOrDefault method refactor code to use it and fix NPE problem * Fixing checkstyle rules * More on checkstyle * More on getType getTypeOrDefault replacement * Revert Article EntryType into Electronic * Added break line between different packages * Refactor BibtextEntryTypes.getTypeOrDefault method * Removed unused import * Removed extra new line, checkstyle error fixing --- .../fileformat/BiblioscapeImporter.java | 3 +- .../importer/fileformat/BibtexParser.java | 4 ++- .../importer/fileformat/CopacImporter.java | 3 +- .../importer/fileformat/EndnoteImporter.java | 3 +- .../logic/importer/fileformat/GvkParser.java | 3 +- .../importer/fileformat/InspecImporter.java | 3 +- .../importer/fileformat/IsiImporter.java | 3 +- .../importer/fileformat/MedlineImporter.java | 5 ++-- .../fileformat/MedlinePlainImporter.java | 3 +- .../importer/fileformat/OvidImporter.java | 3 +- .../importer/fileformat/RisImporter.java | 3 +- .../fileformat/SilverPlatterImporter.java | 3 +- .../jabref/logic/msbib/BibTeXConverter.java | 3 +- .../java/org/jabref/logic/util/TestEntry.java | 3 +- .../java/org/jabref/model/entry/BibEntry.java | 4 +-- .../jabref/model/entry/BibtexEntryTypes.java | 4 +++ .../AutoSetFileLinksUtilTest.java | 3 +- .../org/jabref/logic/TypedBibEntryTest.java | 11 ++++---- .../logic/bibtex/BibEntryWriterTest.java | 9 +++--- .../logic/bibtex/DuplicateCheckTest.java | 28 +++++++++---------- .../comparator/FieldComparatorTest.java | 15 +++++----- .../cleanup/BibtexBiblatexRoundtripTest.java | 5 ++-- .../fetcher/ACMPortalFetcherTest.java | 2 +- .../importer/fetcher/INSPIREFetcherTest.java | 2 +- .../importer/fileformat/BibtexParserTest.java | 5 ++-- .../org/jabref/logic/layout/LayoutTest.java | 3 +- .../pdf/EntryAnnotationImporterTest.java | 3 +- .../jabref/logic/search/SearchQueryTest.java | 12 ++++---- .../util/io/CiteKeyBasedFileFinderTest.java | 2 +- .../util/io/RegExpBasedFileFinderTests.java | 8 +++--- .../jabref/model/BibDatabaseContextTest.java | 3 +- .../BibDatabaseModeDetectionTest.java | 22 +++++++-------- .../model/database/BibDatabaseTest.java | 9 ++++-- .../org/jabref/model/entry/BibEntryTests.java | 8 +++--- .../model/entry/CanonicalBibEntryTest.java | 4 +-- .../rules/ContainBasedSearchRuleTest.java | 2 +- 36 files changed, 120 insertions(+), 89 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/fileformat/BiblioscapeImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/BiblioscapeImporter.java index 99e0e0a6ab1..f1a847bf5a0 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/BiblioscapeImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/BiblioscapeImporter.java @@ -13,6 +13,7 @@ import org.jabref.logic.importer.ParserResult; import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.FieldName; /** @@ -255,7 +256,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { if (!comments.isEmpty()) { // set comment if present hm.put(FieldName.COMMENT, String.join(";", comments)); } - BibEntry b = new BibEntry(bibtexType); + BibEntry b = new BibEntry(BibtexEntryTypes.getTypeOrDefault(bibtexType)); b.setField(hm); bibItems.add(b); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java b/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java index 16093dca0b3..06accaed956 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java @@ -29,6 +29,7 @@ import org.jabref.model.database.BibDatabase; import org.jabref.model.database.KeyCollisionException; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.BibtexString; import org.jabref.model.entry.CustomEntryType; import org.jabref.model.entry.EntryType; @@ -504,7 +505,8 @@ private String parsePreamble() throws IOException { } private BibEntry parseEntry(String entryType) throws IOException { - BibEntry result = new BibEntry(entryType); + BibEntry result = new BibEntry(BibtexEntryTypes.getTypeOrDefault(entryType)); + skipWhitespace(); consume('{', '('); int character = peek(); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/CopacImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/CopacImporter.java index 5ed722b8bb2..a3c09f6ae2f 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/CopacImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/CopacImporter.java @@ -11,6 +11,7 @@ import org.jabref.logic.importer.ParserResult; import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.FieldName; /** @@ -98,7 +99,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { // Copac does not contain enough information on the type of the // document. A book is assumed. - BibEntry b = new BibEntry("book"); + BibEntry b = new BibEntry(BibtexEntryTypes.BOOK); String[] lines = entry.split("\n"); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/EndnoteImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/EndnoteImporter.java index 2f51300d43d..119f947d3ec 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/EndnoteImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/EndnoteImporter.java @@ -15,6 +15,7 @@ import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.AuthorList; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.FieldName; /** @@ -253,7 +254,7 @@ else if ("P".equals(prefix)) { hm.put(FieldName.PAGES, artnum); } - BibEntry b = new BibEntry(type); + BibEntry b = new BibEntry(BibtexEntryTypes.getTypeOrDefault(type)); b.setField(hm); if (!b.getFieldNames().isEmpty()) { bibitems.add(b); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/GvkParser.java b/src/main/java/org/jabref/logic/importer/fileformat/GvkParser.java index a13fed8d53d..99b01ba20e7 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/GvkParser.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/GvkParser.java @@ -12,6 +12,7 @@ import org.jabref.logic.importer.ParseException; import org.jabref.logic.importer.Parser; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.FieldName; import com.google.common.base.Strings; @@ -360,7 +361,7 @@ private BibEntry parseEntry(Element e) { * dann @incollection annehmen, wenn weder ISBN noch * ZDB-ID vorhanden sind. */ - BibEntry result = new BibEntry(entryType); + BibEntry result = new BibEntry(BibtexEntryTypes.getTypeOrDefault(entryType)); // Zuordnung der Felder in Abhängigkeit vom Dokumenttyp if (author != null) { diff --git a/src/main/java/org/jabref/logic/importer/fileformat/InspecImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/InspecImporter.java index 1b47f8bde40..36009366535 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/InspecImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/InspecImporter.java @@ -13,6 +13,7 @@ import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.AuthorList; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.FieldName; /** @@ -120,7 +121,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { } } } - BibEntry b = new BibEntry(type); + BibEntry b = new BibEntry(BibtexEntryTypes.getTypeOrDefault(type)); b.setField(h); bibitems.add(b); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/IsiImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/IsiImporter.java index db686fcd1a3..1db5b39feeb 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/IsiImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/IsiImporter.java @@ -17,6 +17,7 @@ import org.jabref.logic.importer.ParserResult; import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.FieldName; import org.jabref.model.entry.Month; @@ -301,7 +302,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { continue; } - BibEntry b = new BibEntry(Type); + BibEntry b = new BibEntry(BibtexEntryTypes.getTypeOrDefault(Type)); // id assumes an existing database so don't // Remove empty fields: diff --git a/src/main/java/org/jabref/logic/importer/fileformat/MedlineImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/MedlineImporter.java index 8adf2a0a142..934219824cd 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/MedlineImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/MedlineImporter.java @@ -74,6 +74,7 @@ import org.jabref.logic.importer.fileformat.medline.Text; import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.FieldName; import org.jabref.model.strings.StringUtil; @@ -262,7 +263,7 @@ private void parseBookArticle(PubmedBookArticle currentArticle, List b putIfValueNotNull(fields, "pubstatus", bookData.getPublicationStatus()); } - BibEntry entry = new BibEntry("article"); + BibEntry entry = new BibEntry(BibtexEntryTypes.ARTICLE); entry.setField(fields); bibItems.add(entry); @@ -410,7 +411,7 @@ private void parseArticle(PubmedArticle article, List bibItems) { } } - BibEntry entry = new BibEntry("article"); + BibEntry entry = new BibEntry(BibtexEntryTypes.ARTICLE); entry.setField(fields); bibItems.add(entry); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/MedlinePlainImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/MedlinePlainImporter.java index dcaf590cbfe..1389c15d40e 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/MedlinePlainImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/MedlinePlainImporter.java @@ -16,6 +16,7 @@ import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.AuthorList; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.FieldName; /** @@ -208,7 +209,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { fields.put(FieldName.COMMENT, comment); } - BibEntry b = new BibEntry(type); + BibEntry b = new BibEntry(BibtexEntryTypes.getTypeOrDefault(type)); // Remove empty fields: fields.entrySet().stream().filter(n -> n.getValue().trim().isEmpty()).forEach(fields::remove); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/OvidImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/OvidImporter.java index 26ec3309987..23107e695cf 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/OvidImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/OvidImporter.java @@ -14,6 +14,7 @@ import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.AuthorList; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.FieldName; /** @@ -207,7 +208,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { // Move the "chaptertitle" to just "title": h.put(FieldName.TITLE, h.remove("chaptertitle")); } - BibEntry b = new BibEntry(entryType); + BibEntry b = new BibEntry(BibtexEntryTypes.getTypeOrDefault(entryType)); b.setField(h); bibitems.add(b); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java index 116e08e5539..d778dd3d357 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java @@ -16,6 +16,7 @@ import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.AuthorList; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.FieldName; import org.jabref.model.entry.Month; @@ -265,7 +266,7 @@ else if ("AV".equals(tag)) { // create one here // type is set in the loop above - BibEntry entry = new BibEntry(type); + BibEntry entry = new BibEntry(BibtexEntryTypes.getTypeOrDefault(type)); entry.setField(fields); // month has a special treatment as we use the separate method "setMonth" of BibEntry instead of directly setting the value month.ifPresent(entry::setMonth); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/SilverPlatterImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/SilverPlatterImporter.java index e3cea08b106..1b1d0f96559 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/SilverPlatterImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/SilverPlatterImporter.java @@ -14,6 +14,7 @@ import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.AuthorList; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.FieldName; /** @@ -180,7 +181,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { } - BibEntry b = new BibEntry(type); + BibEntry b = new BibEntry(BibtexEntryTypes.getTypeOrDefault(type)); // create one here b.setField(h); diff --git a/src/main/java/org/jabref/logic/msbib/BibTeXConverter.java b/src/main/java/org/jabref/logic/msbib/BibTeXConverter.java index 42b36413a82..a95721fedd7 100644 --- a/src/main/java/org/jabref/logic/msbib/BibTeXConverter.java +++ b/src/main/java/org/jabref/logic/msbib/BibTeXConverter.java @@ -9,6 +9,7 @@ import java.util.stream.Collectors; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.FieldName; import org.jabref.model.entry.Month; @@ -29,7 +30,7 @@ public static BibEntry convert(MSBibEntry entry) { Map fieldValues = new HashMap<>(); String bibTexEntryType = MSBibMapping.getBiblatexEntryType(entry.getType()); - result = new BibEntry(bibTexEntryType); + result = new BibEntry(BibtexEntryTypes.getTypeOrDefault(bibTexEntryType)); // add String fields for (Map.Entry field : entry.fields.entrySet()) { diff --git a/src/main/java/org/jabref/logic/util/TestEntry.java b/src/main/java/org/jabref/logic/util/TestEntry.java index 8d2b3920b87..6c98136c848 100644 --- a/src/main/java/org/jabref/logic/util/TestEntry.java +++ b/src/main/java/org/jabref/logic/util/TestEntry.java @@ -1,6 +1,7 @@ package org.jabref.logic.util; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.FieldName; public class TestEntry { @@ -10,7 +11,7 @@ private TestEntry() { public static BibEntry getTestEntry() { - BibEntry entry = new BibEntry("article"); + BibEntry entry = new BibEntry(BibtexEntryTypes.ARTICLE); entry.setCiteKey("Smith2016"); entry.setField(FieldName.AUTHOR, "Smith, Bill and Jones, Bob and Williams, Jeff"); entry.setField(FieldName.EDITOR, "Taylor, Phil"); diff --git a/src/main/java/org/jabref/model/entry/BibEntry.java b/src/main/java/org/jabref/model/entry/BibEntry.java index 370b3d655df..5a59a45fc6c 100644 --- a/src/main/java/org/jabref/model/entry/BibEntry.java +++ b/src/main/java/org/jabref/model/entry/BibEntry.java @@ -111,7 +111,7 @@ private BibEntry(String id, String type) { * Constructs a new BibEntry. The internal ID is set to IdGenerator.next() */ public BibEntry(EntryType type) { - this(type.getName()); + this(IdGenerator.next(),type.getName()); } public Optional setMonth(Month parsedMonth) { @@ -544,7 +544,7 @@ private boolean atLeastOnePresent(String[] fieldsToCheck, BibDatabase database) */ @Override public Object clone() { - BibEntry clone = new BibEntry(type.getValue()); + BibEntry clone = new BibEntry(IdGenerator.next(),type.getValue()); clone.fields = FXCollections.observableMap(new ConcurrentHashMap<>(fields)); return clone; } diff --git a/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java b/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java index 352411976e5..04909d1b954 100644 --- a/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java +++ b/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java @@ -287,4 +287,8 @@ private BibtexEntryTypes() { public static Optional getType(String name) { return ALL.stream().filter(e -> e.getName().equalsIgnoreCase(name)).findFirst(); } + + public static EntryType getTypeOrDefault(String name) { + return getType(name).orElseGet(() -> new CustomEntryType(name, "required", "optional")); + } } diff --git a/src/test/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtilTest.java b/src/test/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtilTest.java index e25495e99f2..ae1b46fe557 100644 --- a/src/test/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtilTest.java +++ b/src/test/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtilTest.java @@ -10,6 +10,7 @@ import org.jabref.logic.util.io.AutoLinkPreferences; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.LinkedFile; import org.jabref.model.metadata.FilePreferences; @@ -30,7 +31,7 @@ public class AutoSetFileLinksUtilTest { private final AutoLinkPreferences autoLinkPrefs = new AutoLinkPreferences(false, "", true, ';'); private final BibDatabaseContext databaseContext = mock(BibDatabaseContext.class); private final ExternalFileTypes externalFileTypes = mock(ExternalFileTypes.class); - private final BibEntry entry = new BibEntry("article"); + private final BibEntry entry = new BibEntry(BibtexEntryTypes.ARTICLE); @BeforeEach public void setUp(@TempDirectory.TempDir Path folder) throws Exception { diff --git a/src/test/java/org/jabref/logic/TypedBibEntryTest.java b/src/test/java/org/jabref/logic/TypedBibEntryTest.java index 8b72810ecc9..9415bdcd28c 100644 --- a/src/test/java/org/jabref/logic/TypedBibEntryTest.java +++ b/src/test/java/org/jabref/logic/TypedBibEntryTest.java @@ -3,6 +3,7 @@ import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibtexEntryTypes; +import org.jabref.model.entry.CustomEntryType; import org.junit.jupiter.api.Test; @@ -14,7 +15,7 @@ public class TypedBibEntryTest { @Test public void hasAllRequiredFieldsFail() { - BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE); e.setField("author", "abc"); e.setField("title", "abc"); e.setField("journal", "abc"); @@ -25,7 +26,7 @@ public void hasAllRequiredFieldsFail() { @Test public void hasAllRequiredFields() { - BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE); e.setField("author", "abc"); e.setField("title", "abc"); e.setField("journal", "abc"); @@ -37,7 +38,7 @@ public void hasAllRequiredFields() { @Test public void hasAllRequiredFieldsForUnknownTypeReturnsTrue() { - BibEntry e = new BibEntry("articlllleeeee"); + BibEntry e = new BibEntry(new CustomEntryType("articlllleeeee","required","optional")); TypedBibEntry typedEntry = new TypedBibEntry(e, BibDatabaseMode.BIBTEX); assertTrue(typedEntry.hasAllRequiredFields()); @@ -45,7 +46,7 @@ public void hasAllRequiredFieldsForUnknownTypeReturnsTrue() { @Test public void getTypeForDisplayReturnsTypeName() { - BibEntry e = new BibEntry(BibtexEntryTypes.INPROCEEDINGS.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.INPROCEEDINGS); TypedBibEntry typedEntry = new TypedBibEntry(e, BibDatabaseMode.BIBTEX); assertEquals("InProceedings", typedEntry.getTypeForDisplay()); @@ -53,7 +54,7 @@ public void getTypeForDisplayReturnsTypeName() { @Test public void getTypeForDisplayForUnknownTypeCapitalizeFirstLetter() { - BibEntry e = new BibEntry("articlllleeeee"); + BibEntry e = new BibEntry(new CustomEntryType("articlllleeeee","required","optional")); TypedBibEntry typedEntry = new TypedBibEntry(e, BibDatabaseMode.BIBTEX); assertEquals("Articlllleeeee", typedEntry.getTypeForDisplay()); diff --git a/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java b/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java index a340fdc7b59..e7e9808bc8a 100644 --- a/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java +++ b/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java @@ -13,6 +13,7 @@ import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BiblatexEntryTypes; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.LinkedFile; import org.jabref.model.util.DummyFileUpdateMonitor; import org.jabref.model.util.FileUpdateMonitor; @@ -43,7 +44,7 @@ public void setUpWriter() { public void testSerialization() throws IOException { StringWriter stringWriter = new StringWriter(); - BibEntry entry = new BibEntry("article"); + BibEntry entry = new BibEntry(BibtexEntryTypes.ARTICLE); //set a required field entry.setField("author", "Foo Bar"); entry.setField("journal", "International Journal of Something"); @@ -405,7 +406,7 @@ public void addFieldWithLongerLength() throws IOException { public void doNotWriteEmptyFields() throws IOException { StringWriter stringWriter = new StringWriter(); - BibEntry entry = new BibEntry("article"); + BibEntry entry = new BibEntry(BibtexEntryTypes.ARTICLE); entry.setField("author", " "); entry.setField("note", "some note"); @@ -424,7 +425,7 @@ public void doNotWriteEmptyFields() throws IOException { public void trimFieldContents() throws IOException { StringWriter stringWriter = new StringWriter(); - BibEntry entry = new BibEntry("article"); + BibEntry entry = new BibEntry(BibtexEntryTypes.ARTICLE); entry.setField("note", " some note \t"); writer.write(entry, stringWriter, BibDatabaseMode.BIBTEX); @@ -442,7 +443,7 @@ public void trimFieldContents() throws IOException { public void writeThrowsErrorIfFieldContainsUnbalancedBraces() { StringWriter stringWriter = new StringWriter(); - BibEntry entry = new BibEntry("article"); + BibEntry entry = new BibEntry(BibtexEntryTypes.ARTICLE); entry.setField("note", "some text with unbalanced { braces"); assertThrows(IOException.class, () -> writer.write(entry, stringWriter, BibDatabaseMode.BIBTEX)); diff --git a/src/test/java/org/jabref/logic/bibtex/DuplicateCheckTest.java b/src/test/java/org/jabref/logic/bibtex/DuplicateCheckTest.java index ace796173fe..7f3dbfcdd55 100644 --- a/src/test/java/org/jabref/logic/bibtex/DuplicateCheckTest.java +++ b/src/test/java/org/jabref/logic/bibtex/DuplicateCheckTest.java @@ -21,22 +21,22 @@ public class DuplicateCheckTest { @BeforeEach public void setUp() { - simpleArticle = new BibEntry(BibtexEntryTypes.ARTICLE.getName()) + simpleArticle = new BibEntry(BibtexEntryTypes.ARTICLE) .withField(FieldName.AUTHOR, "Single Author") .withField(FieldName.TITLE, "A serious paper about something") .withField(FieldName.YEAR, "2017"); - unrelatedArticle = new BibEntry(BibtexEntryTypes.ARTICLE.getName()) + unrelatedArticle = new BibEntry(BibtexEntryTypes.ARTICLE) .withField(FieldName.AUTHOR, "Completely Different") .withField(FieldName.TITLE, "Holy Moly Uffdada und Trallalla") .withField(FieldName.YEAR, "1992"); - simpleInbook = new BibEntry(BibtexEntryTypes.INBOOK.getName()) + simpleInbook = new BibEntry(BibtexEntryTypes.INBOOK) .withField(FieldName.TITLE, "Alice in Wonderland") .withField(FieldName.AUTHOR, "Charles Lutwidge Dodgson") .withField(FieldName.CHAPTER, "Chapter One – Down the Rabbit Hole") .withField(FieldName.LANGUAGE, "English") .withField(FieldName.PUBLISHER, "Macmillan") .withField(FieldName.YEAR, "1865"); - simpleIncollection = new BibEntry(BibtexEntryTypes.INCOLLECTION.getName()) + simpleIncollection = new BibEntry(BibtexEntryTypes.INCOLLECTION) .withField(FieldName.TITLE, "Innovation and Intellectual Property Rights") .withField(FieldName.AUTHOR, "Ove Grandstrand") .withField(FieldName.BOOKTITLE, "The Oxford Handbook of Innovation") @@ -46,9 +46,9 @@ public void setUp() { @Test public void testDuplicateDetection() { - BibEntry one = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry one = new BibEntry(BibtexEntryTypes.ARTICLE); - BibEntry two = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry two = new BibEntry(BibtexEntryTypes.ARTICLE); one.setField("author", "Billy Bob"); two.setField("author", "Billy Bob"); @@ -204,14 +204,14 @@ public void inbookWithoutChapterCouldBeDuplicateOfInbookWithChapter() { @Test public void twoBooksWithDifferentEditionsAreNotDuplicates() { - BibEntry editionOne = new BibEntry(BibtexEntryTypes.BOOK.getName()); + BibEntry editionOne = new BibEntry(BibtexEntryTypes.BOOK); editionOne.setField(FieldName.TITLE, "Effective Java"); editionOne.setField(FieldName.AUTHOR, "Bloch, Joshua"); editionOne.setField(FieldName.PUBLISHER, "Prentice Hall"); editionOne.setField(FieldName.DATE, "2001"); editionOne.setField(FieldName.EDITION, "1"); - BibEntry editionTwo = new BibEntry(BibtexEntryTypes.BOOK.getName()); + BibEntry editionTwo = new BibEntry(BibtexEntryTypes.BOOK); editionTwo.setField(FieldName.TITLE, "Effective Java"); editionTwo.setField(FieldName.AUTHOR, "Bloch, Joshua"); editionTwo.setField(FieldName.PUBLISHER, "Prentice Hall"); @@ -223,13 +223,13 @@ public void twoBooksWithDifferentEditionsAreNotDuplicates() { @Test public void sameBooksWithMissingEditionAreDuplicates() { - BibEntry editionOne = new BibEntry(BibtexEntryTypes.BOOK.getName()); + BibEntry editionOne = new BibEntry(BibtexEntryTypes.BOOK); editionOne.setField(FieldName.TITLE, "Effective Java"); editionOne.setField(FieldName.AUTHOR, "Bloch, Joshua"); editionOne.setField(FieldName.PUBLISHER, "Prentice Hall"); editionOne.setField(FieldName.DATE, "2001"); - BibEntry editionTwo = new BibEntry(BibtexEntryTypes.BOOK.getName()); + BibEntry editionTwo = new BibEntry(BibtexEntryTypes.BOOK); editionTwo.setField(FieldName.TITLE, "Effective Java"); editionTwo.setField(FieldName.AUTHOR, "Bloch, Joshua"); editionTwo.setField(FieldName.PUBLISHER, "Prentice Hall"); @@ -240,13 +240,13 @@ public void sameBooksWithMissingEditionAreDuplicates() { @Test public void sameBooksWithPartiallyMissingEditionAreDuplicates() { - BibEntry editionOne = new BibEntry(BibtexEntryTypes.BOOK.getName()); + BibEntry editionOne = new BibEntry(BibtexEntryTypes.BOOK); editionOne.setField(FieldName.TITLE, "Effective Java"); editionOne.setField(FieldName.AUTHOR, "Bloch, Joshua"); editionOne.setField(FieldName.PUBLISHER, "Prentice Hall"); editionOne.setField(FieldName.DATE, "2001"); - BibEntry editionTwo = new BibEntry(BibtexEntryTypes.BOOK.getName()); + BibEntry editionTwo = new BibEntry(BibtexEntryTypes.BOOK); editionTwo.setField(FieldName.TITLE, "Effective Java"); editionTwo.setField(FieldName.AUTHOR, "Bloch, Joshua"); editionTwo.setField(FieldName.PUBLISHER, "Prentice Hall"); @@ -258,7 +258,7 @@ public void sameBooksWithPartiallyMissingEditionAreDuplicates() { @Test public void sameBooksWithDifferentEditionsAreNotDuplicates() { - BibEntry editionTwo = new BibEntry(BibtexEntryTypes.BOOK.getName()); + BibEntry editionTwo = new BibEntry(BibtexEntryTypes.BOOK); editionTwo.setCiteKey("Sutton17reinfLrnIntroBook"); editionTwo.setField(FieldName.TITLE, "Reinforcement learning:An introduction"); editionTwo.setField(FieldName.PUBLISHER, "MIT Press"); @@ -269,7 +269,7 @@ public void sameBooksWithDifferentEditionsAreNotDuplicates() { editionTwo.setField(FieldName.JOURNAL, "MIT Press"); editionTwo.setField(FieldName.URL, "https://webdocs.cs.ualberta.ca/~sutton/book/the-book-2nd.html"); - BibEntry editionOne = new BibEntry(BibtexEntryTypes.BOOK.getName()); + BibEntry editionOne = new BibEntry(BibtexEntryTypes.BOOK); editionOne.setCiteKey("Sutton98reinfLrnIntroBook"); editionOne.setField(FieldName.TITLE, "Reinforcement learning: An introduction"); editionOne.setField(FieldName.PUBLISHER, "MIT press Cambridge"); diff --git a/src/test/java/org/jabref/logic/bibtex/comparator/FieldComparatorTest.java b/src/test/java/org/jabref/logic/bibtex/comparator/FieldComparatorTest.java index 80742aff2ab..02ee8ea0907 100644 --- a/src/test/java/org/jabref/logic/bibtex/comparator/FieldComparatorTest.java +++ b/src/test/java/org/jabref/logic/bibtex/comparator/FieldComparatorTest.java @@ -1,6 +1,7 @@ package org.jabref.logic.bibtex.comparator; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.junit.jupiter.api.Test; @@ -94,7 +95,7 @@ public void compareYearFieldBiggerDescending() throws Exception { @Test public void compareTypeFieldIdentity() throws Exception { FieldComparator comparator = new FieldComparator("entrytype"); - BibEntry equal = new BibEntry("article"); + BibEntry equal = new BibEntry(BibtexEntryTypes.ARTICLE); assertEquals(0, comparator.compare(equal, equal)); } @@ -102,9 +103,9 @@ public void compareTypeFieldIdentity() throws Exception { @Test public void compareTypeFieldEquality() throws Exception { FieldComparator comparator = new FieldComparator("entrytype"); - BibEntry equal = new BibEntry("article"); + BibEntry equal = new BibEntry(BibtexEntryTypes.ARTICLE); equal.setId("1"); - BibEntry equal2 = new BibEntry("article"); + BibEntry equal2 = new BibEntry(BibtexEntryTypes.ARTICLE); equal2.setId("1"); assertEquals(0, comparator.compare(equal, equal2)); @@ -113,8 +114,8 @@ public void compareTypeFieldEquality() throws Exception { @Test public void compareTypeFieldBiggerAscending() throws Exception { FieldComparator comparator = new FieldComparator("entrytype"); - BibEntry smaller = new BibEntry("article"); - BibEntry bigger = new BibEntry("book"); + BibEntry smaller = new BibEntry(BibtexEntryTypes.ARTICLE); + BibEntry bigger = new BibEntry(BibtexEntryTypes.BOOK); assertEquals(1, comparator.compare(bigger, smaller)); } @@ -122,8 +123,8 @@ public void compareTypeFieldBiggerAscending() throws Exception { @Test public void compareTypeFieldBiggerDescending() throws Exception { FieldComparator comparator = new FieldComparator("entrytype", true); - BibEntry bigger = new BibEntry("article"); - BibEntry smaller = new BibEntry("book"); + BibEntry bigger = new BibEntry(BibtexEntryTypes.ARTICLE); + BibEntry smaller = new BibEntry(BibtexEntryTypes.BOOK); assertEquals(1, comparator.compare(bigger, smaller)); } diff --git a/src/test/java/org/jabref/logic/cleanup/BibtexBiblatexRoundtripTest.java b/src/test/java/org/jabref/logic/cleanup/BibtexBiblatexRoundtripTest.java index 1a2e903673f..01da069febd 100644 --- a/src/test/java/org/jabref/logic/cleanup/BibtexBiblatexRoundtripTest.java +++ b/src/test/java/org/jabref/logic/cleanup/BibtexBiblatexRoundtripTest.java @@ -1,6 +1,7 @@ package org.jabref.logic.cleanup; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -13,7 +14,7 @@ class BibtexBiblatexRoundtripTest { @BeforeEach void setUp() { - bibtex = new BibEntry("article"); + bibtex = new BibEntry(BibtexEntryTypes.ARTICLE); bibtex.setField("author", "Frame, J. S. and Robinson, G. de B. and Thrall, R. M."); bibtex.setField("title", "The hook graphs of the symmetric groups"); bibtex.setField("journal", "Canadian J. Math."); @@ -26,7 +27,7 @@ void setUp() { bibtex.setField("mrnumber", "0062127"); bibtex.setField("mrreviewer", "D. E. Littlewood"); - biblatex = new BibEntry("article"); + biblatex = new BibEntry(BibtexEntryTypes.ARTICLE); biblatex.setField("author", "Frame, J. S. and Robinson, G. de B. and Thrall, R. M."); biblatex.setField("title", "The hook graphs of the symmetric groups"); biblatex.setField("journaltitle", "Canadian J. Math."); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java index df85c30857f..8ab746da3d2 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java @@ -29,7 +29,7 @@ void setUp() { @Test void searchByQueryFindsEntry() throws Exception { - BibEntry expected = new BibEntry(BibtexEntryTypes.INPROCEEDINGS.getName()); + BibEntry expected = new BibEntry(BibtexEntryTypes.INPROCEEDINGS); expected.setCiteKey("Olsson:2017:RCC:3129790.3129810"); expected.setField("acmid", "3129810"); expected.setField("address", "New York, NY, USA"); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java index d919f96ce1d..fba34218798 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java @@ -29,7 +29,7 @@ void setUp() { @Test void searchByQueryFindsEntry() throws Exception { - BibEntry expected = new BibEntry(BibtexEntryTypes.MASTERSTHESIS.getName()); + BibEntry expected = new BibEntry(BibtexEntryTypes.MASTERSTHESIS); expected.setCiteKey("Diez:2014ppa"); expected.setField("author", "Diez, Tobias"); expected.setField("title", "Slice theorem for Fr\\'echet group actions and covariant symplectic field theory"); diff --git a/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java b/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java index 866a5a39e57..98c3a8cc2f8 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java @@ -25,6 +25,7 @@ import org.jabref.model.cleanup.FieldFormatterCleanups; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.BibtexString; import org.jabref.model.entry.Date; import org.jabref.model.entry.EntryType; @@ -325,7 +326,7 @@ void parseRecognizesEntryWithAtInField() throws IOException { List parsed = result.getDatabase().getEntries(); - BibEntry expected = new BibEntry("article").withField(BibEntry.KEY_FIELD, "test") + BibEntry expected = new BibEntry(BibtexEntryTypes.ARTICLE).withField(BibEntry.KEY_FIELD, "test") .withField("author", "Ed von T@st"); assertEquals(Collections.singletonList(expected), parsed); @@ -336,7 +337,7 @@ void parseRecognizesEntryPrecedingComment() throws IOException { String comment = "@Comment{@article{myarticle,}" + OS.NEWLINE + "@inproceedings{blabla, title={the proceedings of bl@bl@}; }" + OS.NEWLINE + "}"; String entryWithComment = comment + OS.NEWLINE + "@article{test,author={Ed von T@st}}"; - BibEntry expected = new BibEntry("article") + BibEntry expected = new BibEntry(BibtexEntryTypes.ARTICLE) .withField(BibEntry.KEY_FIELD, "test") .withField("author", "Ed von T@st"); expected.setCommentsBeforeEntry(comment); diff --git a/src/test/java/org/jabref/logic/layout/LayoutTest.java b/src/test/java/org/jabref/logic/layout/LayoutTest.java index 34c8ae2418f..1e737784520 100644 --- a/src/test/java/org/jabref/logic/layout/LayoutTest.java +++ b/src/test/java/org/jabref/logic/layout/LayoutTest.java @@ -8,6 +8,7 @@ import org.jabref.logic.layout.format.FileLinkPreferences; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibtexEntryTypes; +import org.jabref.model.entry.CustomEntryType; import org.jabref.model.entry.LinkedFile; import org.junit.jupiter.api.BeforeEach; @@ -37,7 +38,7 @@ private String layout(String layout, BibEntry entry) throws IOException { @Test void entryTypeForUnknown() throws IOException { - BibEntry entry = new BibEntry("unknown").withField("author", "test"); + BibEntry entry = new BibEntry(new CustomEntryType("unknown","required","optional")).withField("author", "test"); assertEquals("Unknown", layout("\\bibtextype", entry)); } diff --git a/src/test/java/org/jabref/logic/pdf/EntryAnnotationImporterTest.java b/src/test/java/org/jabref/logic/pdf/EntryAnnotationImporterTest.java index 1a94f42a49a..0ad5b9bca30 100644 --- a/src/test/java/org/jabref/logic/pdf/EntryAnnotationImporterTest.java +++ b/src/test/java/org/jabref/logic/pdf/EntryAnnotationImporterTest.java @@ -8,6 +8,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.CustomEntryType; import org.jabref.model.entry.FieldName; import org.jabref.model.metadata.FilePreferences; import org.jabref.model.pdf.FileAnnotation; @@ -23,7 +24,7 @@ public class EntryAnnotationImporterTest { private final BibDatabaseContext databaseContext = mock(BibDatabaseContext.class); - private final BibEntry entry = new BibEntry("EntryKey"); + private final BibEntry entry = new BibEntry(new CustomEntryType("EntryKey","required","optional")); @BeforeEach public void setUp() { diff --git a/src/test/java/org/jabref/logic/search/SearchQueryTest.java b/src/test/java/org/jabref/logic/search/SearchQueryTest.java index 2718943d6a6..e4463f75155 100644 --- a/src/test/java/org/jabref/logic/search/SearchQueryTest.java +++ b/src/test/java/org/jabref/logic/search/SearchQueryTest.java @@ -58,7 +58,7 @@ public void testGrammarSearchFullEntry() { @Test public void testSearchingForOpenBraketInBooktitle() { - BibEntry e = new BibEntry(BibtexEntryTypes.INPROCEEDINGS.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.INPROCEEDINGS); e.setField(FieldName.BOOKTITLE, "Super Conference (SC)"); SearchQuery searchQuery = new SearchQuery("booktitle=\"(\"", false, false); @@ -67,7 +67,7 @@ public void testSearchingForOpenBraketInBooktitle() { @Test public void testSearchMatchesSingleKeywordNotPart() { - BibEntry e = new BibEntry(BibtexEntryTypes.INPROCEEDINGS.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.INPROCEEDINGS); e.setField("keywords", "banana, pineapple, orange"); SearchQuery searchQuery = new SearchQuery("anykeyword==apple", false, false); @@ -76,7 +76,7 @@ public void testSearchMatchesSingleKeywordNotPart() { @Test public void testSearchMatchesSingleKeyword() { - BibEntry e = new BibEntry(BibtexEntryTypes.INPROCEEDINGS.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.INPROCEEDINGS); e.setField("keywords", "banana, pineapple, orange"); SearchQuery searchQuery = new SearchQuery("anykeyword==pineapple", false, false); @@ -85,7 +85,7 @@ public void testSearchMatchesSingleKeyword() { @Test public void testSearchAllFields() { - BibEntry e = new BibEntry(BibtexEntryTypes.INPROCEEDINGS.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.INPROCEEDINGS); e.setField("title", "Fruity features"); e.setField("keywords", "banana, pineapple, orange"); @@ -95,7 +95,7 @@ public void testSearchAllFields() { @Test public void testSearchAllFieldsNotForSpecificField() { - BibEntry e = new BibEntry(BibtexEntryTypes.INPROCEEDINGS.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.INPROCEEDINGS); e.setField("title", "Fruity features"); e.setField("keywords", "banana, pineapple, orange"); @@ -105,7 +105,7 @@ public void testSearchAllFieldsNotForSpecificField() { @Test public void testSearchAllFieldsAndSpecificField() { - BibEntry e = new BibEntry(BibtexEntryTypes.INPROCEEDINGS.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.INPROCEEDINGS); e.setField("title", "Fruity features"); e.setField("keywords", "banana, pineapple, orange"); diff --git a/src/test/java/org/jabref/logic/util/io/CiteKeyBasedFileFinderTest.java b/src/test/java/org/jabref/logic/util/io/CiteKeyBasedFileFinderTest.java index 0629afe3a97..70c8ea51941 100644 --- a/src/test/java/org/jabref/logic/util/io/CiteKeyBasedFileFinderTest.java +++ b/src/test/java/org/jabref/logic/util/io/CiteKeyBasedFileFinderTest.java @@ -29,7 +29,7 @@ class CiteKeyBasedFileFinderTest { @BeforeEach void setUp(@TempDirectory.TempDir Path temporaryFolder) throws IOException { - entry = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + entry = new BibEntry(BibtexEntryTypes.ARTICLE); entry.setCiteKey("HipKro03"); rootDir = temporaryFolder; diff --git a/src/test/java/org/jabref/logic/util/io/RegExpBasedFileFinderTests.java b/src/test/java/org/jabref/logic/util/io/RegExpBasedFileFinderTests.java index d024017ff34..4e5edbc0322 100644 --- a/src/test/java/org/jabref/logic/util/io/RegExpBasedFileFinderTests.java +++ b/src/test/java/org/jabref/logic/util/io/RegExpBasedFileFinderTests.java @@ -46,7 +46,7 @@ public void setUp() { @Test public void testFindFiles() throws Exception { //given - BibEntry localEntry = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry localEntry = new BibEntry(BibtexEntryTypes.ARTICLE); localEntry.setCiteKey("pdfInDatabase"); localEntry.setField("year", "2001"); @@ -82,7 +82,7 @@ public void testYearAuthFirspageFindFiles() throws Exception { @Test public void testAuthorWithDiacritics() throws Exception { //given - BibEntry localEntry = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry localEntry = new BibEntry(BibtexEntryTypes.ARTICLE); localEntry.setCiteKey("Grazulis2017"); localEntry.setField("year", "2017"); localEntry.setField("author", "Gražulis, Saulius and O. Kitsune"); @@ -104,7 +104,7 @@ public void testAuthorWithDiacritics() throws Exception { @Test public void testFindFileInSubdirectory() throws Exception { //given - BibEntry localEntry = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry localEntry = new BibEntry(BibtexEntryTypes.ARTICLE); localEntry.setCiteKey("pdfInSubdirectory"); localEntry.setField("year", "2017"); @@ -124,7 +124,7 @@ public void testFindFileInSubdirectory() throws Exception { @Test public void testFindFileNonRecursive() throws Exception { //given - BibEntry localEntry = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry localEntry = new BibEntry(BibtexEntryTypes.ARTICLE); localEntry.setCiteKey("pdfInSubdirectory"); localEntry.setField("year", "2017"); diff --git a/src/test/java/org/jabref/model/BibDatabaseContextTest.java b/src/test/java/org/jabref/model/BibDatabaseContextTest.java index 701833e223d..42fc88abab6 100644 --- a/src/test/java/org/jabref/model/BibDatabaseContextTest.java +++ b/src/test/java/org/jabref/model/BibDatabaseContextTest.java @@ -4,6 +4,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.IEEETranEntryTypes; import org.jabref.model.metadata.MetaData; import org.junit.jupiter.api.Test; @@ -42,7 +43,7 @@ public void testTypeBasedOnInferredModeBibTeX() { @Test public void testTypeBasedOnInferredModeBiblatex() { BibDatabase db = new BibDatabase(); - BibEntry e1 = new BibEntry("electronic"); + BibEntry e1 = new BibEntry(IEEETranEntryTypes.ELECTRONIC); db.insertEntry(e1); BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(db); diff --git a/src/test/java/org/jabref/model/database/BibDatabaseModeDetectionTest.java b/src/test/java/org/jabref/model/database/BibDatabaseModeDetectionTest.java index 3902da07a58..5a82943b0e0 100644 --- a/src/test/java/org/jabref/model/database/BibDatabaseModeDetectionTest.java +++ b/src/test/java/org/jabref/model/database/BibDatabaseModeDetectionTest.java @@ -16,14 +16,14 @@ public class BibDatabaseModeDetectionTest { @Test public void detectBiblatex() { - Collection entries = Arrays.asList(new BibEntry(BiblatexEntryTypes.MVBOOK.getName())); + Collection entries = Arrays.asList(new BibEntry(BiblatexEntryTypes.MVBOOK)); assertEquals(BibDatabaseMode.BIBLATEX, BibDatabaseModeDetection.inferMode(BibDatabases.createDatabase(entries))); } @Test public void detectUndistinguishableAsBibtex() { - BibEntry entry = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry entry = new BibEntry(BibtexEntryTypes.ARTICLE); entry.setField("title", "My cool paper"); Collection entries = Arrays.asList(entry); @@ -32,9 +32,9 @@ public void detectUndistinguishableAsBibtex() { @Test public void detectMixedModeAsBiblatex() { - BibEntry bibtex = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry bibtex = new BibEntry(BibtexEntryTypes.ARTICLE); bibtex.setField("journal", "IEEE Trans. Services Computing"); - BibEntry biblatex = new BibEntry(BiblatexEntryTypes.ARTICLE.getName()); + BibEntry biblatex = new BibEntry(BiblatexEntryTypes.ARTICLE); biblatex.setField("translator", "Stefan Kolb"); Collection entries = Arrays.asList(bibtex, biblatex); @@ -43,7 +43,7 @@ public void detectMixedModeAsBiblatex() { @Test public void detectUnknownTypeAsBibtex() { - BibEntry entry = new BibEntry(new CustomEntryType("unknowntype", new ArrayList<>(0), new ArrayList<>(0)).getName()); + BibEntry entry = new BibEntry(new CustomEntryType("unknowntype", new ArrayList<>(0), new ArrayList<>(0))); Collection entries = Arrays.asList(entry); assertEquals(BibDatabaseMode.BIBTEX, BibDatabaseModeDetection.inferMode(BibDatabases.createDatabase(entries))); @@ -51,9 +51,9 @@ public void detectUnknownTypeAsBibtex() { @Test public void ignoreUnknownTypesForBibtexDecision() { - BibEntry custom = new BibEntry(new CustomEntryType("unknowntype", new ArrayList<>(0), new ArrayList<>(0)).getName()); - BibEntry bibtex = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); - BibEntry biblatex = new BibEntry(BiblatexEntryTypes.ARTICLE.getName()); + BibEntry custom = new BibEntry(new CustomEntryType("unknowntype", new ArrayList<>(0), new ArrayList<>(0))); + BibEntry bibtex = new BibEntry(BibtexEntryTypes.ARTICLE); + BibEntry biblatex = new BibEntry(BiblatexEntryTypes.ARTICLE); Collection entries = Arrays.asList(custom, bibtex, biblatex); assertEquals(BibDatabaseMode.BIBTEX, BibDatabaseModeDetection.inferMode(BibDatabases.createDatabase(entries))); @@ -61,9 +61,9 @@ public void ignoreUnknownTypesForBibtexDecision() { @Test public void ignoreUnknownTypesForBiblatexDecision() { - BibEntry custom = new BibEntry(new CustomEntryType("unknowntype", new ArrayList<>(0), new ArrayList<>(0)).getName()); - BibEntry bibtex = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); - BibEntry biblatex = new BibEntry(BiblatexEntryTypes.MVBOOK.getName()); + BibEntry custom = new BibEntry(new CustomEntryType("unknowntype", new ArrayList<>(0), new ArrayList<>(0))); + BibEntry bibtex = new BibEntry(BibtexEntryTypes.ARTICLE); + BibEntry biblatex = new BibEntry(BiblatexEntryTypes.MVBOOK); Collection entries = Arrays.asList(custom, bibtex, biblatex); assertEquals(BibDatabaseMode.BIBLATEX, BibDatabaseModeDetection.inferMode(BibDatabases.createDatabase(entries))); diff --git a/src/test/java/org/jabref/model/database/BibDatabaseTest.java b/src/test/java/org/jabref/model/database/BibDatabaseTest.java index 84fcbb426e7..8e3f3b89194 100644 --- a/src/test/java/org/jabref/model/database/BibDatabaseTest.java +++ b/src/test/java/org/jabref/model/database/BibDatabaseTest.java @@ -11,7 +11,10 @@ import java.util.Set; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BiblatexEntryTypes; +import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.BibtexString; +import org.jabref.model.entry.CustomEntryType; import org.jabref.model.entry.IdGenerator; import org.jabref.model.event.TestEventListener; @@ -250,7 +253,7 @@ public void resolveForStringsOddHashMarkAtTheEnd() { @Test public void getUsedStrings() { - BibEntry entry = new BibEntry(IdGenerator.next()); + BibEntry entry = new BibEntry(new CustomEntryType(IdGenerator.next(),"required","optional")); entry.setField("author", "#AAA#"); BibtexString tripleA = new BibtexString("AAA", "Some other #BBB#"); BibtexString tripleB = new BibtexString("BBB", "Some more text"); @@ -298,9 +301,9 @@ public void getUsedStringsNoString() { @Test public void getEntriesSortedWithTwoEntries() { - BibEntry entryB = new BibEntry("article"); + BibEntry entryB = new BibEntry(BibtexEntryTypes.ARTICLE); entryB.setId("2"); - BibEntry entryA = new BibEntry("article"); + BibEntry entryA = new BibEntry(BiblatexEntryTypes.ARTICLE); entryB.setId("1"); database.insertEntries(entryB, entryA); assertEquals(Arrays.asList(entryA, entryB), database.getEntriesSorted(Comparator.comparing(BibEntry::getId))); diff --git a/src/test/java/org/jabref/model/entry/BibEntryTests.java b/src/test/java/org/jabref/model/entry/BibEntryTests.java index 2f39ddb131c..872ba189f65 100644 --- a/src/test/java/org/jabref/model/entry/BibEntryTests.java +++ b/src/test/java/org/jabref/model/entry/BibEntryTests.java @@ -49,7 +49,7 @@ public void testDefaultConstructor() { @Test public void allFieldsPresentDefault() { - BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE); e.setField("author", "abc"); e.setField("title", "abc"); e.setField("journal", "abc"); @@ -65,7 +65,7 @@ public void allFieldsPresentDefault() { @Test public void allFieldsPresentOr() { - BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE); e.setField("author", "abc"); e.setField("title", "abc"); e.setField("journal", "abc"); @@ -81,13 +81,13 @@ public void allFieldsPresentOr() { @Test public void isNullCiteKeyThrowsNPE() { - BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE); assertThrows(NullPointerException.class, () -> e.setCiteKey(null)); } @Test public void isEmptyCiteKey() { - BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE); assertFalse(e.hasCiteKey()); e.setCiteKey(""); diff --git a/src/test/java/org/jabref/model/entry/CanonicalBibEntryTest.java b/src/test/java/org/jabref/model/entry/CanonicalBibEntryTest.java index 8a3eb16d7c9..88fa45d2224 100644 --- a/src/test/java/org/jabref/model/entry/CanonicalBibEntryTest.java +++ b/src/test/java/org/jabref/model/entry/CanonicalBibEntryTest.java @@ -8,7 +8,7 @@ public class CanonicalBibEntryTest { @Test public void simpleCanonicalRepresentation() { - BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE); e.setCiteKey("key"); e.setField("author", "abc"); e.setField("title", "def"); @@ -20,7 +20,7 @@ public void simpleCanonicalRepresentation() { @Test public void canonicalRepresentationWithNewlines() { - BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.ARTICLE); e.setCiteKey("key"); e.setField("abstract", "line 1\nline 2"); String canonicalRepresentation = CanonicalBibtexEntry.getCanonicalRepresentation(e); diff --git a/src/test/java/org/jabref/model/search/rules/ContainBasedSearchRuleTest.java b/src/test/java/org/jabref/model/search/rules/ContainBasedSearchRuleTest.java index b60ec5ebc83..20948435422 100644 --- a/src/test/java/org/jabref/model/search/rules/ContainBasedSearchRuleTest.java +++ b/src/test/java/org/jabref/model/search/rules/ContainBasedSearchRuleTest.java @@ -43,7 +43,7 @@ public void testBasicSearchParsing() { } public BibEntry makeBibtexEntry() { - BibEntry e = new BibEntry(BibtexEntryTypes.INCOLLECTION.getName()); + BibEntry e = new BibEntry(BibtexEntryTypes.INCOLLECTION); e.setField("title", "Marine finfish larviculture in Europe"); e.setField("bibtexkey", "shields01"); e.setField("year", "2001");