Skip to content

Commit 4b39b78

Browse files
authored
Move to extended enums for fields and entry types (#5148)
* Introduce interface for fields * Continue using fields interface instead of strings * Introduce OrFields class * Move FieldProperty * Convert entry types to extended enum * Start fixing build * Fix build * Start fixing tests * Everything compiles again * Make model tests pass * Fix most tests * Fix build * Fix a few more tests * Fix a few more tests * Fix a few more tests * Fix a few more tests * Fix checkstyle issues * Fix more tests * Fix more tests * Disable test that fails on CI * Disable test that fails on CI
1 parent 651b545 commit 4b39b78

File tree

495 files changed

+8629
-9599
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

495 files changed

+8629
-9599
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
1111
## [Unreleased]
1212

1313
### Changed
14+
- All fields are now properly sorted alphabetically (in the subgroups of required/optional fields) when the entry is written to the bib file.
15+
- We fixed an issue where some importers used the field `pubstatus` instead of the standard BibTeX field `pubstate`.
1416
- We changed the latex command removal for docbook exporter. [#3838](https://github.com/JabRef/jabref/issues/3838)
1517
- We changed the location of some fields in the entry editor (you might need to reset your preferences for these changes to come into effect)
1618
- Journal/Year/Month in biblatex mode -> Deprecated (if filled)

src/jmh/java/org/jabref/benchmarks/Benchmarks.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import org.jabref.model.database.BibDatabaseMode;
2323
import org.jabref.model.database.BibDatabaseModeDetection;
2424
import org.jabref.model.entry.BibEntry;
25+
import org.jabref.model.entry.BibEntryTypesManager;
26+
import org.jabref.model.entry.field.StandardField;
27+
import org.jabref.model.entry.field.UnknownField;
2528
import org.jabref.model.groups.GroupHierarchyType;
2629
import org.jabref.model.groups.KeywordGroup;
2730
import org.jabref.model.groups.WordKeywordGroup;
@@ -54,12 +57,12 @@ public void init() throws Exception {
5457
for (int i = 0; i < 1000; i++) {
5558
BibEntry entry = new BibEntry();
5659
entry.setCiteKey("id" + i);
57-
entry.setField("title", "This is my title " + i);
58-
entry.setField("author", "Firstname Lastname and FirstnameA LastnameA and FirstnameB LastnameB" + i);
59-
entry.setField("journal", "Journal Title " + i);
60-
entry.setField("keyword", "testkeyword");
61-
entry.setField("year", "1" + i);
62-
entry.setField("rnd", "2" + randomizer.nextInt());
60+
entry.setField(StandardField.TITLE, "This is my title " + i);
61+
entry.setField(StandardField.AUTHOR, "Firstname Lastname and FirstnameA LastnameA and FirstnameB LastnameB" + i);
62+
entry.setField(StandardField.JOURNAL, "Journal Title " + i);
63+
entry.setField(StandardField.KEYWORDS, "testkeyword");
64+
entry.setField(StandardField.YEAR, "1" + i);
65+
entry.setField(new UnknownField("rnd"), "2" + randomizer.nextInt());
6366
database.insertEntry(entry);
6467
}
6568

@@ -72,7 +75,7 @@ public void init() throws Exception {
7275

7376
private StringWriter getOutputWriter() throws IOException {
7477
StringWriter outputWriter = new StringWriter();
75-
BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(outputWriter, mock(SavePreferences.class));
78+
BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(outputWriter, mock(SavePreferences.class), new BibEntryTypesManager());
7679
databaseWriter.savePartOfDatabase(
7780
new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries());
7881
return outputWriter;
@@ -128,7 +131,7 @@ public String htmlToLatexConversion() {
128131

129132
@Benchmark
130133
public boolean keywordGroupContains() {
131-
KeywordGroup group = new WordKeywordGroup("testGroup", GroupHierarchyType.INDEPENDENT, "keyword", "testkeyword", false, ',', false);
134+
KeywordGroup group = new WordKeywordGroup("testGroup", GroupHierarchyType.INDEPENDENT, StandardField.KEYWORDS, "testkeyword", false, ',', false);
132135
return group.containsAll(database.getEntries());
133136
}
134137

src/main/java/org/jabref/Globals.java

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
2222
import org.jabref.logic.remote.server.RemoteListenerServerLifecycle;
2323
import org.jabref.logic.util.BuildInfo;
24+
import org.jabref.model.entry.BibEntryTypesManager;
2425
import org.jabref.model.util.FileUpdateMonitor;
2526
import org.jabref.preferences.JabRefPreferences;
2627

@@ -61,6 +62,7 @@ public class Globals {
6162
public static StateManager stateManager = new StateManager();
6263
public static ExporterFactory exportFactory;
6364
public static CountingUndoManager undoManager = new CountingUndoManager();
65+
public static BibEntryTypesManager entryTypesManager = new BibEntryTypesManager();
6466
// Key binding preferences
6567
private static KeyBindingRepository keyBindingRepository;
6668
private static DefaultFileUpdateMonitor fileUpdateMonitor;

src/main/java/org/jabref/JabRefMain.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
import org.jabref.logic.util.JavaVersion;
2323
import org.jabref.logic.util.OS;
2424
import org.jabref.migrations.PreferencesMigrations;
25-
import org.jabref.model.EntryTypes;
2625
import org.jabref.model.database.BibDatabaseMode;
27-
import org.jabref.model.entry.InternalBibtexFields;
2826
import org.jabref.preferences.JabRefPreferences;
2927

3028
import org.slf4j.Logger;
@@ -153,21 +151,14 @@ private static boolean handleMultipleAppInstances(String[] args) {
153151
}
154152

155153
private static void applyPreferences(JabRefPreferences preferences) {
156-
// Update handling of special fields based on preferences
157-
InternalBibtexFields.updateSpecialFields(Globals.prefs.getBoolean(JabRefPreferences.SERIALIZESPECIALFIELDS));
158-
// Update name of the time stamp field based on preferences
159-
InternalBibtexFields.updateTimeStampField(Globals.prefs.getTimestampPreferences().getTimestampField());
160-
// Update which fields should be treated as numeric, based on preferences:
161-
InternalBibtexFields.setNumericFields(Globals.prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS));
162-
163154
// Read list(s) of journal names and abbreviations
164155
Globals.journalAbbreviationLoader = new JournalAbbreviationLoader();
165156

166157
// Build list of Import and Export formats
167158
Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(),
168159
Globals.prefs.getXMPPreferences(), Globals.getFileUpdateMonitor());
169-
EntryTypes.loadCustomEntryTypes(preferences.loadCustomEntryTypes(BibDatabaseMode.BIBTEX),
170-
preferences.loadCustomEntryTypes(BibDatabaseMode.BIBLATEX));
160+
Globals.entryTypesManager.addCustomizedEntryTypes(preferences.loadBibEntryTypes(BibDatabaseMode.BIBTEX),
161+
preferences.loadBibEntryTypes(BibDatabaseMode.BIBLATEX));
171162
Globals.exportFactory = Globals.prefs.getExporterFactory(Globals.journalAbbreviationLoader);
172163

173164
// Initialize protected terms loader

src/main/java/org/jabref/cli/ArgumentProcessor.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.jabref.logic.util.OS;
4545
import org.jabref.logic.xmp.XmpPreferences;
4646
import org.jabref.model.Defaults;
47-
import org.jabref.model.EntryTypes;
4847
import org.jabref.model.database.BibDatabase;
4948
import org.jabref.model.database.BibDatabaseContext;
5049
import org.jabref.model.database.BibDatabaseMode;
@@ -391,7 +390,7 @@ private void saveDatabase(BibDatabase newBase, String subName) {
391390
System.out.println(Localization.lang("Saving") + ": " + subName);
392391
SavePreferences prefs = Globals.prefs.loadForSaveFromPreferences();
393392
AtomicFileWriter fileWriter = new AtomicFileWriter(Paths.get(subName), prefs.getEncoding());
394-
BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(fileWriter, prefs);
393+
BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(fileWriter, prefs, Globals.entryTypesManager);
395394
Defaults defaults = new Defaults(Globals.prefs.getDefaultBibDatabaseMode());
396395
databaseWriter.saveDatabase(new BibDatabaseContext(newBase, defaults));
397396

@@ -458,8 +457,8 @@ private void exportFile(List<ParserResult> loaded, String[] data) {
458457
private void importPreferences() {
459458
try {
460459
Globals.prefs.importPreferences(cli.getPreferencesImport());
461-
EntryTypes.loadCustomEntryTypes(Globals.prefs.loadCustomEntryTypes(BibDatabaseMode.BIBTEX),
462-
Globals.prefs.loadCustomEntryTypes(BibDatabaseMode.BIBLATEX));
460+
Globals.entryTypesManager.addCustomizedEntryTypes(Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBTEX),
461+
Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBLATEX));
463462
List<TemplateExporter> customExporters = Globals.prefs.getCustomExportFormats(Globals.journalAbbreviationLoader);
464463
LayoutFormatterPreferences layoutPreferences = Globals.prefs
465464
.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);

src/main/java/org/jabref/cli/CrossrefFetcherEvaluator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import org.jabref.logic.importer.fileformat.BibtexParser;
1717
import org.jabref.model.database.BibDatabase;
1818
import org.jabref.model.entry.BibEntry;
19-
import org.jabref.model.entry.FieldName;
19+
import org.jabref.model.entry.field.StandardField;
2020
import org.jabref.model.entry.identifier.DOI;
2121
import org.jabref.preferences.JabRefPreferences;
2222

@@ -53,7 +53,7 @@ public static void main(String[] args) throws IOException, InterruptedException
5353

5454
@Override
5555
public void run() {
56-
Optional<DOI> origDOI = entry.getField(FieldName.DOI).flatMap(DOI::parse);
56+
Optional<DOI> origDOI = entry.getField(StandardField.DOI).flatMap(DOI::parse);
5757
if (origDOI.isPresent()) {
5858
dois.incrementAndGet();
5959
try {

src/main/java/org/jabref/gui/BasePanel.java

+19-18
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,14 @@
9292
import org.jabref.model.database.shared.DatabaseLocation;
9393
import org.jabref.model.database.shared.DatabaseSynchronizer;
9494
import org.jabref.model.entry.BibEntry;
95-
import org.jabref.model.entry.FieldName;
96-
import org.jabref.model.entry.InternalBibtexFields;
9795
import org.jabref.model.entry.LinkedFile;
9896
import org.jabref.model.entry.event.EntryChangedEvent;
9997
import org.jabref.model.entry.event.EntryEventSource;
100-
import org.jabref.model.entry.specialfields.SpecialField;
101-
import org.jabref.model.entry.specialfields.SpecialFieldValue;
98+
import org.jabref.model.entry.field.Field;
99+
import org.jabref.model.entry.field.FieldFactory;
100+
import org.jabref.model.entry.field.SpecialField;
101+
import org.jabref.model.entry.field.SpecialFieldValue;
102+
import org.jabref.model.entry.field.StandardField;
102103
import org.jabref.preferences.JabRefPreferences;
103104
import org.jabref.preferences.PreviewPreferences;
104105

@@ -573,13 +574,13 @@ private void openExternalFile() {
573574
}
574575
JabRefExecutorService.INSTANCE.execute(() -> {
575576
final BibEntry entry = selectedEntries.get(0);
576-
if (!entry.hasField(FieldName.FILE)) {
577+
if (!entry.hasField(StandardField.FILE)) {
577578
// no bibtex field
578579
new SearchAndOpenFile(entry, BasePanel.this).searchAndOpen();
579580
return;
580581
}
581582
FileListTableModel fileListTableModel = new FileListTableModel();
582-
entry.getField(FieldName.FILE).ifPresent(fileListTableModel::setContent);
583+
entry.getField(StandardField.FILE).ifPresent(fileListTableModel::setContent);
583584
if (fileListTableModel.getRowCount() == 0) {
584585
// content in BibTeX field is not readable
585586
new SearchAndOpenFile(entry, BasePanel.this).searchAndOpen();
@@ -637,7 +638,7 @@ public void insertEntry(final BibEntry bibEntry) {
637638

638639
// Create an UndoableInsertEntry object.
639640
getUndoManager().addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), bibEntry));
640-
output(Localization.lang("Added new '%0' entry.", bibEntry.getType()));
641+
output(Localization.lang("Added new '%0' entry.", bibEntry.getType().getDisplayName()));
641642

642643
markBaseChanged(); // The database just changed.
643644
if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_OPEN_FORM)) {
@@ -650,11 +651,11 @@ public void insertEntry(final BibEntry bibEntry) {
650651
}
651652
}
652653

653-
public void editEntryAndFocusField(BibEntry entry, String fieldName) {
654+
public void editEntryAndFocusField(BibEntry entry, Field field) {
654655
showAndEdit(entry);
655656
Platform.runLater(() -> {
656657
// Focus field and entry in main table (async to give entry editor time to load)
657-
entryEditor.setFocusToField(fieldName);
658+
entryEditor.setFocusToField(field);
658659
clearAndSelect(entry);
659660
});
660661
}
@@ -808,7 +809,7 @@ public void updateSearchManager() {
808809
}
809810

810811
private void instantiateSearchAutoCompleter() {
811-
searchAutoCompleter = new PersonNameSuggestionProvider(InternalBibtexFields.getPersonNameFields());
812+
searchAutoCompleter = new PersonNameSuggestionProvider(FieldFactory.getPersonNameFields());
812813
for (BibEntry entry : bibDatabaseContext.getDatabase().getEntries()) {
813814
searchAutoCompleter.indexEntry(entry);
814815
}
@@ -1300,11 +1301,11 @@ private class OpenURLAction implements BaseAction {
13001301
public void action() {
13011302
final List<BibEntry> bes = mainTable.getSelectedEntries();
13021303
if (bes.size() == 1) {
1303-
String field = FieldName.DOI;
1304-
Optional<String> link = bes.get(0).getField(FieldName.DOI);
1305-
if (bes.get(0).hasField(FieldName.URL)) {
1306-
link = bes.get(0).getField(FieldName.URL);
1307-
field = FieldName.URL;
1304+
Field field = StandardField.DOI;
1305+
Optional<String> link = bes.get(0).getField(StandardField.DOI);
1306+
if (bes.get(0).hasField(StandardField.URL)) {
1307+
link = bes.get(0).getField(StandardField.URL);
1308+
field = StandardField.URL;
13081309
}
13091310
if (link.isPresent()) {
13101311
try {
@@ -1320,9 +1321,9 @@ public void action() {
13201321
List<LinkedFile> files = bes.get(0).getFiles();
13211322

13221323
Optional<LinkedFile> linkedFile = files.stream()
1323-
.filter(file -> (FieldName.URL.equalsIgnoreCase(file.getFileType())
1324-
|| FieldName.PS.equalsIgnoreCase(file.getFileType())
1325-
|| FieldName.PDF.equalsIgnoreCase(file.getFileType())))
1324+
.filter(file -> (StandardField.URL.getName().equalsIgnoreCase(file.getFileType())
1325+
|| StandardField.PS.getName().equalsIgnoreCase(file.getFileType())
1326+
|| StandardField.PDF.getName().equalsIgnoreCase(file.getFileType())))
13261327
.findFirst();
13271328

13281329
if (linkedFile.isPresent()) {

src/main/java/org/jabref/gui/ClipBoardManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void setContent(String string) {
8181

8282
public void setContent(List<BibEntry> entries) throws IOException {
8383
final ClipboardContent content = new ClipboardContent();
84-
BibEntryWriter writer = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs.getLatexFieldFormatterPreferences()), false);
84+
BibEntryWriter writer = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs.getLatexFieldFormatterPreferences()), Globals.entryTypesManager);
8585
String serializedEntries = writer.serializeAll(entries, BibDatabaseMode.BIBTEX);
8686
content.put(DragAndDropDataFormats.ENTRIES, serializedEntries);
8787
content.putString(serializedEntries);

src/main/java/org/jabref/gui/EntryTypeView.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
import javafx.scene.control.TitledPane;
1414
import javafx.scene.layout.FlowPane;
1515

16+
import org.jabref.Globals;
1617
import org.jabref.gui.util.BaseDialog;
1718
import org.jabref.gui.util.ControlHelper;
1819
import org.jabref.gui.util.ViewModelListCellFactory;
1920
import org.jabref.logic.importer.IdBasedFetcher;
2021
import org.jabref.logic.l10n.Localization;
21-
import org.jabref.model.EntryTypes;
2222
import org.jabref.model.database.BibDatabaseMode;
23+
import org.jabref.model.entry.BibEntryType;
2324
import org.jabref.model.entry.BiblatexEntryTypes;
2425
import org.jabref.model.entry.BibtexEntryTypes;
2526
import org.jabref.model.entry.EntryType;
@@ -84,10 +85,9 @@ public EntryTypeView(BasePanel basePanel, DialogService dialogService, JabRefPre
8485

8586
}
8687

87-
private void addEntriesToPane(FlowPane pane, Collection<? extends EntryType> entries) {
88-
89-
for (EntryType entryType : entries) {
90-
Button entryButton = new Button(entryType.getName());
88+
private void addEntriesToPane(FlowPane pane, Collection<? extends BibEntryType> entries) {
89+
for (BibEntryType entryType : entries) {
90+
Button entryButton = new Button(entryType.getType().getDisplayName());
9191
entryButton.setUserData(entryType);
9292
entryButton.setOnAction(event -> setEntryTypeForReturnAndClose(entryType));
9393
pane.getChildren().add(entryButton);
@@ -124,7 +124,7 @@ public void initialize() {
124124
bibTexTitlePane.setVisible(false);
125125
ieeeTranTitlePane.setVisible(false);
126126

127-
List<EntryType> customTypes = EntryTypes.getAllCustomTypes(BibDatabaseMode.BIBLATEX);
127+
List<BibEntryType> customTypes = Globals.entryTypesManager.getAllCustomTypes(BibDatabaseMode.BIBLATEX);
128128
if (customTypes.isEmpty()) {
129129
customTitlePane.setVisible(false);
130130
} else {
@@ -136,7 +136,7 @@ public void initialize() {
136136
addEntriesToPane(bibTexPane, BibtexEntryTypes.ALL);
137137
addEntriesToPane(ieeetranPane, IEEETranEntryTypes.ALL);
138138

139-
List<EntryType> customTypes = EntryTypes.getAllCustomTypes(BibDatabaseMode.BIBTEX);
139+
List<BibEntryType> customTypes = Globals.entryTypesManager.getAllCustomTypes(BibDatabaseMode.BIBTEX);
140140
if (customTypes.isEmpty()) {
141141
customTitlePane.setVisible(false);
142142
} else {
@@ -162,8 +162,8 @@ private void focusTextField(Event event) {
162162
idTextField.selectAll();
163163
}
164164

165-
private void setEntryTypeForReturnAndClose(EntryType entryType) {
166-
type = entryType;
165+
private void setEntryTypeForReturnAndClose(BibEntryType entryType) {
166+
type = entryType.getType();
167167
viewModel.stopFetching();
168168
this.close();
169169
}

src/main/java/org/jabref/gui/EntryTypeViewModel.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import javafx.concurrent.Task;
1515
import javafx.concurrent.Worker;
1616

17+
import org.jabref.Globals;
1718
import org.jabref.gui.duplicationFinder.DuplicateResolverDialog;
1819
import org.jabref.logic.bibtex.DuplicateCheck;
1920
import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator;
@@ -138,7 +139,7 @@ public void runFetcherWorker() {
138139
Optional<BibEntry> result = fetcherWorker.getValue();
139140
if (result.isPresent()) {
140141
final BibEntry entry = result.get();
141-
Optional<BibEntry> duplicate = DuplicateCheck.containsDuplicate(basePanel.getDatabase(), entry, basePanel.getBibDatabaseContext().getMode());
142+
Optional<BibEntry> duplicate = new DuplicateCheck(Globals.entryTypesManager).containsDuplicate(basePanel.getDatabase(), entry, basePanel.getBibDatabaseContext().getMode());
142143
if ((duplicate.isPresent())) {
143144
DuplicateResolverDialog dialog = new DuplicateResolverDialog(entry, duplicate.get(), DuplicateResolverDialog.DuplicateResolverType.IMPORT_CHECK, basePanel.getBibDatabaseContext());
144145
switch (dialog.showAndWait().orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK)) {

0 commit comments

Comments
 (0)