-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Support customized entry types in BibliographyConsistencyCheck #13799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
94e1770
b42b7c8
274d859
b9d69c2
b2bc3a4
8128685
831ed3b
9942817
ff8006e
d453516
53b83d9
b7145af
baeff03
3a79c98
d302f7c
76394d7
3f97a75
37416ff
66b2bbf
2031f0e
ad131c6
9c24a2f
ff9a529
d6d8278
0d7e37d
1fc3810
d30b731
462657a
704885f
c321b78
79af35f
3befca7
7125b76
e580f9a
d3bfbd8
6ed613a
6cc90e2
f1adef0
6cea857
c899efa
3e6c4b1
d681cd8
5040b0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| import org.jabref.logic.util.BuildInfo; | ||
| import org.jabref.logic.util.Directories; | ||
| import org.jabref.migrations.PreferencesMigrations; | ||
| import org.jabref.model.entry.BibEntryTypesManager; | ||
|
|
||
| import com.airhacks.afterburner.injection.Injector; | ||
| import org.slf4j.Logger; | ||
|
|
@@ -56,6 +57,7 @@ public static void main(String[] args) { | |
| Injector.setModelOrService(BuildInfo.class, new BuildInfo()); | ||
|
|
||
| final JabRefGuiPreferences preferences = JabRefGuiPreferences.getInstance(); | ||
| final BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager(); | ||
|
|
||
| ArgumentProcessor argumentProcessor = new ArgumentProcessor( | ||
| args, | ||
|
|
@@ -87,7 +89,7 @@ public static void main(String[] args) { | |
| systemExit(); | ||
| } | ||
|
|
||
| PreferencesMigrations.runMigrations(preferences); | ||
| PreferencesMigrations.runMigrations(preferences, bibEntryTypesManager); | ||
|
||
|
|
||
| PostgreServer postgreServer = new PostgreServer(); | ||
| Injector.setModelOrService(PostgreServer.class, postgreServer); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ | |
| import org.jabref.logic.l10n.Localization; | ||
| import org.jabref.logic.net.ProxyRegisterer; | ||
| import org.jabref.logic.os.OS; | ||
| import org.jabref.logic.preferences.CliPreferences; | ||
| import org.jabref.logic.protectedterms.ProtectedTermsLoader; | ||
| import org.jabref.logic.remote.RemotePreferences; | ||
| import org.jabref.logic.remote.server.RemoteListenerServerManager; | ||
|
|
@@ -70,6 +71,7 @@ public class JabRefGUI extends Application { | |
|
|
||
| private static List<UiCommand> uiCommands; | ||
| private static GuiPreferences preferences; | ||
| private static CliPreferences cliPreferences; | ||
|
|
||
| // AI Service handles chat messages etc. Therefore, it is tightly coupled to the GUI. | ||
| private static AiService aiService; | ||
|
|
@@ -84,6 +86,7 @@ public class JabRefGUI extends Application { | |
| private static ClipBoardManager clipBoardManager; | ||
| private static DialogService dialogService; | ||
| private static JabRefFrame mainFrame; | ||
| private static BibEntryTypesManager bibEntryTypesManager; | ||
|
|
||
| private static RemoteListenerServerManager remoteListenerServerManager; | ||
| private static HttpServerManager httpServerManager; | ||
|
|
@@ -114,6 +117,7 @@ public void start(Stage stage) { | |
| dialogService, | ||
| fileUpdateMonitor, | ||
| preferences, | ||
| cliPreferences, | ||
|
||
| aiService, | ||
| stateManager, | ||
| countingUndoManager, | ||
|
|
@@ -157,7 +161,7 @@ public void initialize() { | |
| DirectoryMonitor directoryMonitor = new DirectoryMonitor(); | ||
| Injector.setModelOrService(DirectoryMonitor.class, directoryMonitor); | ||
|
|
||
| BibEntryTypesManager entryTypesManager = preferences.getCustomEntryTypesRepository(); | ||
| BibEntryTypesManager entryTypesManager = preferences.getCustomEntryTypesRepository(bibEntryTypesManager); | ||
| JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadRepository(preferences.getJournalAbbreviationPreferences()); | ||
| Injector.setModelOrService(BibEntryTypesManager.class, entryTypesManager); | ||
| Injector.setModelOrService(JournalAbbreviationRepository.class, journalAbbreviationRepository); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,10 +54,12 @@ public class PreferencesDialogViewModel extends AbstractViewModel { | |
| private final DialogService dialogService; | ||
| private final GuiPreferences preferences; | ||
| private final ObservableList<PreferencesTab> preferenceTabs; | ||
| private final BibEntryTypesManager bibEntryTypesManager; | ||
|
|
||
| public PreferencesDialogViewModel(DialogService dialogService, GuiPreferences preferences) { | ||
| public PreferencesDialogViewModel(DialogService dialogService, GuiPreferences preferences, BibEntryTypesManager bibEntryTypesManager) { | ||
| this.dialogService = dialogService; | ||
| this.preferences = preferences; | ||
| this.bibEntryTypesManager = bibEntryTypesManager; | ||
|
|
||
| // This enables passing unsaved preference values from the AI tab to the "web search" tab. | ||
| AiTab aiTab = new AiTab(); | ||
|
|
@@ -190,9 +192,9 @@ public void storeAllSettings() { | |
| + Localization.lang("You must restart JabRef for this to come into effect.")); | ||
| } | ||
|
|
||
| Injector.setModelOrService(BibEntryTypesManager.class, preferences.getCustomEntryTypesRepository()); | ||
| Injector.setModelOrService(BibEntryTypesManager.class, preferences.getCustomEntryTypesRepository(bibEntryTypesManager)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Direct dependency injection manipulation in GUI code violates layered architecture principle. This logic should be moved to a service layer in org.jabref.logic. |
||
| dialogService.notify(Localization.lang("Preferences recorded.")); | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Inserts the preference values into the Properties of the ViewModel | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1222,8 +1222,7 @@ public JournalAbbreviationPreferences getJournalAbbreviationPreferences() { | |
| //************************************************************************************************************* | ||
|
|
||
| @Override | ||
| public BibEntryTypesManager getCustomEntryTypesRepository() { | ||
| BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager(); | ||
| public BibEntryTypesManager getCustomEntryTypesRepository(BibEntryTypesManager bibEntryTypesManager) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please undo this - the point here is that a new repository is generated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohhh I should implement both, the one without the parameter and then override with the parameter did I get it right? |
||
| EnumSet.allOf(BibDatabaseMode.class).forEach(mode -> | ||
| bibEntryTypesManager.addCustomOrModifiedTypes(getBibEntryTypes(mode), mode)); | ||
| return bibEntryTypesManager; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,16 +17,14 @@ | |
| import org.jabref.logic.bibtex.comparator.BibEntryByFieldsComparator; | ||
| import org.jabref.logic.bibtex.comparator.FieldComparatorStack; | ||
| import org.jabref.model.database.BibDatabaseContext; | ||
| import org.jabref.model.database.BibDatabaseMode; | ||
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.entry.BibEntryType; | ||
| import org.jabref.model.entry.BibEntryTypesManager; | ||
| import org.jabref.model.entry.field.Field; | ||
| import org.jabref.model.entry.field.InternalField; | ||
| import org.jabref.model.entry.field.SpecialField; | ||
| import org.jabref.model.entry.field.StandardField; | ||
| import org.jabref.model.entry.field.UserSpecificCommentField; | ||
| import org.jabref.model.entry.types.BiblatexEntryTypeDefinitions; | ||
| import org.jabref.model.entry.types.BibtexEntryTypeDefinitions; | ||
| import org.jabref.model.entry.types.EntryType; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
|
|
@@ -55,6 +53,12 @@ public class BibliographyConsistencyCheck { | |
| StandardField.MODIFICATIONDATE | ||
| ); | ||
|
|
||
| private final BibEntryTypesManager bibEntryTypesManager; | ||
|
|
||
| public BibliographyConsistencyCheck(org.jabref.logic.preferences.CliPreferences cliPreferences, BibEntryTypesManager bibEntryTypesManager) { | ||
| this.bibEntryTypesManager = cliPreferences.getCustomEntryTypesRepository(bibEntryTypesManager); | ||
| } | ||
|
|
||
| private static Set<Field> filterExcludedFields(Collection<Field> fields) { | ||
| return fields.stream() | ||
| .filter(field -> !EXPLICITLY_EXCLUDED_FIELDS.contains(field)) | ||
|
|
@@ -112,12 +116,10 @@ public Result check(BibDatabaseContext bibContext, BiConsumer<Integer, Integer> | |
|
|
||
| collectEntriesIntoMaps(bibContext, entryTypeToFieldsInAnyEntryMap, entryTypeToFieldsInAllEntriesMap, entryTypeToEntriesMap); | ||
|
|
||
| List<BibEntryType> entryTypeDefinitions; | ||
| if (bibContext.getMode() == BibDatabaseMode.BIBLATEX) { | ||
| entryTypeDefinitions = BiblatexEntryTypeDefinitions.ALL; | ||
| } else { | ||
| entryTypeDefinitions = BibtexEntryTypeDefinitions.ALL; | ||
| } | ||
| List<BibEntryType> entryTypeDefinitions = bibEntryTypesManager | ||
| .getAllTypes(bibContext.getMode()) | ||
| .stream() | ||
| .toList(); | ||
|
Comment on lines
+124
to
+127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to convert to a list - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Collection is a interface though–i need some class to implement it right? For example HashSet class implement the Set interface. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant, below, there is Optional typeDefOpt = entryTypeDefinitions.stream() which does not require the total ordering. |
||
|
|
||
| // Use LinkedHashMap to preserve the order of Bib(tex|latex)EntryTypeDefinitions.ALL | ||
| Map<EntryType, EntryTypeResult> resultMap = new LinkedHashMap<>(); | ||
|
|
@@ -161,7 +163,6 @@ public Result check(BibDatabaseContext bibContext, BiConsumer<Integer, Integer> | |
| } | ||
|
|
||
| private static void collectEntriesIntoMaps(BibDatabaseContext bibContext, Map<EntryType, Set<Field>> entryTypeToFieldsInAnyEntryMap, Map<EntryType, Set<Field>> entryTypeToFieldsInAllEntriesMap, Map<EntryType, Set<BibEntry>> entryTypeToEntriesMap) { | ||
| BibDatabaseMode mode = bibContext.getMode(); | ||
| List<BibEntry> entries = bibContext.getEntries(); | ||
|
|
||
| for (BibEntry entry : entries) { | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not store it as variable - you only need it once below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.