From 1632efdbaaae02bf42488ed736bc536702d0288f Mon Sep 17 00:00:00 2001 From: Balhau Date: Mon, 24 Dec 2018 14:43:20 +0000 Subject: [PATCH 01/14] Refactor BibEntry deprecated method --- .../fileformat/BiblioscapeImporter.java | 5 ++-- .../importer/fileformat/BibtexParser.java | 10 ++----- .../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 | 7 ++--- .../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 +-- .../AutoSetFileLinksUtilTest.java | 3 +- .../org/jabref/logic/TypedBibEntryTest.java | 11 ++++---- .../logic/bibtex/BibEntryWriterTest.java | 12 ++++---- .../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 | 10 ++----- .../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 | 10 +++---- .../org/jabref/model/entry/BibEntryTests.java | 8 +++--- .../model/entry/CanonicalBibEntryTest.java | 4 +-- .../rules/ContainBasedSearchRuleTest.java | 2 +- 35 files changed, 113 insertions(+), 113 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..24bb6517ea2 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/BiblioscapeImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/BiblioscapeImporter.java @@ -12,8 +12,7 @@ import org.jabref.logic.importer.Importer; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.util.StandardFileType; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.FieldName; +import org.jabref.model.entry.*; /** * Imports a Biblioscape Tag File. The format is described on @@ -255,7 +254,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.getType(bibtexType).get()); 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..06a31dee1d1 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java @@ -28,13 +28,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.KeyCollisionException; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BibtexString; -import org.jabref.model.entry.CustomEntryType; -import org.jabref.model.entry.EntryType; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.FieldProperty; -import org.jabref.model.entry.InternalBibtexFields; +import org.jabref.model.entry.*; import org.jabref.model.metadata.MetaData; import org.jabref.model.util.FileUpdateMonitor; @@ -504,7 +498,7 @@ private String parsePreamble() throws IOException { } private BibEntry parseEntry(String entryType) throws IOException { - BibEntry result = new BibEntry(entryType); + BibEntry result = new BibEntry(BibtexEntryTypes.getType(entryType).get()); 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..ce556520683 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.getType(type).get()); 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..12962e72917 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.getType(entryType).get()); // 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..c014ba773c1 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.getType(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..83d0b77768a 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.getType(Type).get()); // 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..428807f6efc 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.getType(type).get()); // 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..c67d5dbbcd1 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.getType(entryType).get()); 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..bad4c579a89 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java @@ -14,10 +14,7 @@ import org.jabref.logic.importer.ParserResult; import org.jabref.logic.util.OS; import org.jabref.logic.util.StandardFileType; -import org.jabref.model.entry.AuthorList; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.Month; +import org.jabref.model.entry.*; public class RisImporter extends Importer { @@ -265,7 +262,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.getType(type).get()); 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..bcc109ef85a 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.getType(type).get()); // 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..3cc53dc2ca8 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.getType(bibTexEntryType).get()); // 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/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..3e34e16005e 100644 --- a/src/test/java/org/jabref/logic/TypedBibEntryTest.java +++ b/src/test/java/org/jabref/logic/TypedBibEntryTest.java @@ -4,6 +4,7 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibtexEntryTypes; +import org.jabref.model.entry.CustomEntryType; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -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..f952cba3b44 100644 --- a/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java +++ b/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java @@ -11,9 +11,7 @@ import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.logic.util.OS; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BiblatexEntryTypes; -import org.jabref.model.entry.LinkedFile; +import org.jabref.model.entry.*; import org.jabref.model.util.DummyFileUpdateMonitor; import org.jabref.model.util.FileUpdateMonitor; @@ -43,7 +41,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 +403,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 +422,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 +440,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..1131a09b896 100644 --- a/src/test/java/org/jabref/logic/bibtex/comparator/FieldComparatorTest.java +++ b/src/test/java/org/jabref/logic/bibtex/comparator/FieldComparatorTest.java @@ -2,6 +2,7 @@ import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -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..e00a7775687 100644 --- a/src/test/java/org/jabref/logic/cleanup/BibtexBiblatexRoundtripTest.java +++ b/src/test/java/org/jabref/logic/cleanup/BibtexBiblatexRoundtripTest.java @@ -2,6 +2,7 @@ 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..7ab979bf3d4 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java @@ -24,11 +24,7 @@ import org.jabref.model.cleanup.FieldFormatterCleanup; import org.jabref.model.cleanup.FieldFormatterCleanups; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BibtexString; -import org.jabref.model.entry.Date; -import org.jabref.model.entry.EntryType; -import org.jabref.model.entry.FieldName; +import org.jabref.model.entry.*; import org.jabref.model.groups.AllEntriesGroup; import org.jabref.model.groups.ExplicitGroup; import org.jabref.model.groups.GroupHierarchyType; @@ -325,7 +321,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 +332,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..3e88f0aa8c6 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.BibtexEntryTypes; 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(BibtexEntryTypes.ARTICLE); 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..32f26444474 100644 --- a/src/test/java/org/jabref/model/database/BibDatabaseTest.java +++ b/src/test/java/org/jabref/model/database/BibDatabaseTest.java @@ -10,9 +10,7 @@ import java.util.Optional; import java.util.Set; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BibtexString; -import org.jabref.model.entry.IdGenerator; +import org.jabref.model.entry.*; import org.jabref.model.event.TestEventListener; import org.junit.jupiter.api.BeforeEach; @@ -250,7 +248,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 +296,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"); From b281436f7f0bcb1c8d4ff41268ffc79e80aefdf3 Mon Sep 17 00:00:00 2001 From: Balhau Date: Mon, 24 Dec 2018 14:50:40 +0000 Subject: [PATCH 02/14] Fixed error --- .../org/jabref/logic/importer/fileformat/InspecImporter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c014ba773c1..e9950921d59 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/InspecImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/InspecImporter.java @@ -121,7 +121,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { } } } - BibEntry b = new BibEntry(BibtexEntryTypes.getType(type)); + BibEntry b = new BibEntry(BibtexEntryTypes.getType(type).get()); b.setField(h); bibitems.add(b); From c13d9f5f2973ba75d82b001909bd9c21d782f38e Mon Sep 17 00:00:00 2001 From: Balhau Date: Mon, 24 Dec 2018 15:08:08 +0000 Subject: [PATCH 03/14] More on checkstyle fixing --- .../logic/importer/fileformat/BiblioscapeImporter.java | 4 +++- .../jabref/logic/importer/fileformat/BibtexParser.java | 9 ++++++++- .../jabref/logic/importer/fileformat/RisImporter.java | 6 +++++- 3 files changed, 16 insertions(+), 3 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 24bb6517ea2..a229e925a18 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/BiblioscapeImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/BiblioscapeImporter.java @@ -12,7 +12,9 @@ import org.jabref.logic.importer.Importer; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.util.StandardFileType; -import org.jabref.model.entry.*; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexEntryTypes; +import org.jabref.model.entry.FieldName; /** * Imports a Biblioscape Tag File. The format is described on 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 06a31dee1d1..c4202ad0c78 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java @@ -28,7 +28,14 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.KeyCollisionException; -import org.jabref.model.entry.*; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibtexString; +import org.jabref.model.entry.BibtexEntryTypes; +import org.jabref.model.entry.CustomEntryType; +import org.jabref.model.entry.EntryType; +import org.jabref.model.entry.FieldName; +import org.jabref.model.entry.FieldProperty; +import org.jabref.model.entry.InternalBibtexFields; import org.jabref.model.metadata.MetaData; import org.jabref.model.util.FileUpdateMonitor; 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 bad4c579a89..9a2a260c67d 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java @@ -14,7 +14,11 @@ import org.jabref.logic.importer.ParserResult; import org.jabref.logic.util.OS; import org.jabref.logic.util.StandardFileType; -import org.jabref.model.entry.*; +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; public class RisImporter extends Importer { From 38248ddd3814c318a4b3039fce3092a473612a20 Mon Sep 17 00:00:00 2001 From: Balhau Date: Mon, 24 Dec 2018 17:43:38 +0000 Subject: [PATCH 04/14] Fixed checkstyle issues --- .../org/jabref/logic/importer/fileformat/BibtexParser.java | 2 +- src/test/java/org/jabref/logic/TypedBibEntryTest.java | 2 +- .../java/org/jabref/logic/bibtex/BibEntryWriterTest.java | 5 ++++- .../logic/bibtex/comparator/FieldComparatorTest.java | 2 +- .../jabref/logic/cleanup/BibtexBiblatexRoundtripTest.java | 2 +- .../jabref/logic/importer/fileformat/BibtexParserTest.java | 7 ++++++- .../java/org/jabref/model/database/BibDatabaseTest.java | 7 ++++++- 7 files changed, 20 insertions(+), 7 deletions(-) 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 c4202ad0c78..1f4409d2e77 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java @@ -29,8 +29,8 @@ import org.jabref.model.database.BibDatabase; import org.jabref.model.database.KeyCollisionException; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BibtexString; import org.jabref.model.entry.BibtexEntryTypes; +import org.jabref.model.entry.BibtexString; import org.jabref.model.entry.CustomEntryType; import org.jabref.model.entry.EntryType; import org.jabref.model.entry.FieldName; diff --git a/src/test/java/org/jabref/logic/TypedBibEntryTest.java b/src/test/java/org/jabref/logic/TypedBibEntryTest.java index 3e34e16005e..9415bdcd28c 100644 --- a/src/test/java/org/jabref/logic/TypedBibEntryTest.java +++ b/src/test/java/org/jabref/logic/TypedBibEntryTest.java @@ -3,8 +3,8 @@ 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; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java b/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java index f952cba3b44..e7e9808bc8a 100644 --- a/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java +++ b/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java @@ -11,7 +11,10 @@ import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.logic.util.OS; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.*; +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; 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 1131a09b896..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,8 +1,8 @@ package org.jabref.logic.bibtex.comparator; import org.jabref.model.entry.BibEntry; - import org.jabref.model.entry.BibtexEntryTypes; + import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/test/java/org/jabref/logic/cleanup/BibtexBiblatexRoundtripTest.java b/src/test/java/org/jabref/logic/cleanup/BibtexBiblatexRoundtripTest.java index e00a7775687..01da069febd 100644 --- a/src/test/java/org/jabref/logic/cleanup/BibtexBiblatexRoundtripTest.java +++ b/src/test/java/org/jabref/logic/cleanup/BibtexBiblatexRoundtripTest.java @@ -1,8 +1,8 @@ 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; 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 7ab979bf3d4..98c3a8cc2f8 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java @@ -24,7 +24,12 @@ import org.jabref.model.cleanup.FieldFormatterCleanup; import org.jabref.model.cleanup.FieldFormatterCleanups; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.*; +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; +import org.jabref.model.entry.FieldName; import org.jabref.model.groups.AllEntriesGroup; import org.jabref.model.groups.ExplicitGroup; import org.jabref.model.groups.GroupHierarchyType; diff --git a/src/test/java/org/jabref/model/database/BibDatabaseTest.java b/src/test/java/org/jabref/model/database/BibDatabaseTest.java index 32f26444474..8e3f3b89194 100644 --- a/src/test/java/org/jabref/model/database/BibDatabaseTest.java +++ b/src/test/java/org/jabref/model/database/BibDatabaseTest.java @@ -10,7 +10,12 @@ import java.util.Optional; import java.util.Set; -import org.jabref.model.entry.*; +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; import org.junit.jupiter.api.BeforeEach; From 2458fbb2fca80d8e8933d2f15796f9a46c85f56c Mon Sep 17 00:00:00 2001 From: Balhau Date: Wed, 26 Dec 2018 11:37:51 +0000 Subject: [PATCH 05/14] Added custom entrytype for types not registered in the enumerator. --- .../logic/importer/fileformat/BibtexParser.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 1f4409d2e77..cfa142ee004 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java @@ -505,7 +505,16 @@ private String parsePreamble() throws IOException { } private BibEntry parseEntry(String entryType) throws IOException { - BibEntry result = new BibEntry(BibtexEntryTypes.getType(entryType).get()); + Optional optionalEntryType = BibtexEntryTypes.getType(entryType); + BibEntry result; + + //This is a workaround because some types are not registered in the Enumeration BibtexEntryTypes + if(optionalEntryType.isPresent()) { + result = new BibEntry(BibtexEntryTypes.getType(entryType).get()); + }else{ + result = new BibEntry(new CustomEntryType(entryType,"required","optional")); + } + skipWhitespace(); consume('{', '('); int character = peek(); From f6cfd28edd1645d20ba33b37abde2745d0e262c8 Mon Sep 17 00:00:00 2001 From: Balhau Date: Fri, 28 Dec 2018 11:14:25 +0000 Subject: [PATCH 06/14] Added getTypeOrDefault method refactor code to use it and fix NPE problem --- .../logic/importer/fileformat/BiblioscapeImporter.java | 2 +- .../jabref/logic/importer/fileformat/BibtexParser.java | 10 +--------- .../java/org/jabref/model/entry/BibtexEntryTypes.java | 8 ++++++++ 3 files changed, 10 insertions(+), 10 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 a229e925a18..f1a847bf5a0 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/BiblioscapeImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/BiblioscapeImporter.java @@ -256,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(BibtexEntryTypes.getType(bibtexType).get()); + 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 cfa142ee004..06accaed956 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java @@ -505,15 +505,7 @@ private String parsePreamble() throws IOException { } private BibEntry parseEntry(String entryType) throws IOException { - Optional optionalEntryType = BibtexEntryTypes.getType(entryType); - BibEntry result; - - //This is a workaround because some types are not registered in the Enumeration BibtexEntryTypes - if(optionalEntryType.isPresent()) { - result = new BibEntry(BibtexEntryTypes.getType(entryType).get()); - }else{ - result = new BibEntry(new CustomEntryType(entryType,"required","optional")); - } + BibEntry result = new BibEntry(BibtexEntryTypes.getTypeOrDefault(entryType)); skipWhitespace(); consume('{', '('); diff --git a/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java b/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java index 352411976e5..c886a19aa08 100644 --- a/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java +++ b/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java @@ -287,4 +287,12 @@ private BibtexEntryTypes() { public static Optional getType(String name) { return ALL.stream().filter(e -> e.getName().equalsIgnoreCase(name)).findFirst(); } + + public static EntryType getTypeOrDefault(String name){ + Optional optType = getType(name); + if(optType.isPresent()){ + return optType.get(); + } + return new CustomEntryType(name,"required","optional"); + } } From 1d02074ce44439ac64c471a0be999c78a49c9090 Mon Sep 17 00:00:00 2001 From: Balhau Date: Fri, 28 Dec 2018 11:22:26 +0000 Subject: [PATCH 07/14] Fixing checkstyle rules --- src/main/java/org/jabref/model/entry/BibtexEntryTypes.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java b/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java index c886a19aa08..9448d5d99a8 100644 --- a/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java +++ b/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java @@ -288,9 +288,9 @@ public static Optional getType(String name) { return ALL.stream().filter(e -> e.getName().equalsIgnoreCase(name)).findFirst(); } - public static EntryType getTypeOrDefault(String name){ + public static EntryType getTypeOrDefault(String name) { Optional optType = getType(name); - if(optType.isPresent()){ + if(optType.isPresent()) { return optType.get(); } return new CustomEntryType(name,"required","optional"); From 80b265018bd7c5a1abcf4b6c6fc6343aada9bdef Mon Sep 17 00:00:00 2001 From: Balhau Date: Fri, 28 Dec 2018 11:35:18 +0000 Subject: [PATCH 08/14] More on checkstyle --- src/main/java/org/jabref/model/entry/BibtexEntryTypes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java b/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java index 9448d5d99a8..896cda85caf 100644 --- a/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java +++ b/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java @@ -290,7 +290,7 @@ public static Optional getType(String name) { public static EntryType getTypeOrDefault(String name) { Optional optType = getType(name); - if(optType.isPresent()) { + if (optType.isPresent()) { return optType.get(); } return new CustomEntryType(name,"required","optional"); From 4e00355a387c11fa833c28bcdaf927e75a7ea578 Mon Sep 17 00:00:00 2001 From: Balhau Date: Fri, 28 Dec 2018 14:47:32 +0000 Subject: [PATCH 09/14] More on getType getTypeOrDefault replacement --- .../org/jabref/logic/importer/fileformat/EndnoteImporter.java | 2 +- .../java/org/jabref/logic/importer/fileformat/GvkParser.java | 2 +- .../org/jabref/logic/importer/fileformat/InspecImporter.java | 2 +- .../java/org/jabref/logic/importer/fileformat/IsiImporter.java | 2 +- .../jabref/logic/importer/fileformat/MedlinePlainImporter.java | 2 +- .../java/org/jabref/logic/importer/fileformat/OvidImporter.java | 2 +- .../java/org/jabref/logic/importer/fileformat/RisImporter.java | 2 +- .../jabref/logic/importer/fileformat/SilverPlatterImporter.java | 2 +- src/main/java/org/jabref/logic/msbib/BibTeXConverter.java | 2 +- src/test/java/org/jabref/model/BibDatabaseContextTest.java | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) 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 ce556520683..119f947d3ec 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/EndnoteImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/EndnoteImporter.java @@ -254,7 +254,7 @@ else if ("P".equals(prefix)) { hm.put(FieldName.PAGES, artnum); } - BibEntry b = new BibEntry(BibtexEntryTypes.getType(type).get()); + 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 12962e72917..99b01ba20e7 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/GvkParser.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/GvkParser.java @@ -361,7 +361,7 @@ private BibEntry parseEntry(Element e) { * dann @incollection annehmen, wenn weder ISBN noch * ZDB-ID vorhanden sind. */ - BibEntry result = new BibEntry(BibtexEntryTypes.getType(entryType).get()); + 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 e9950921d59..36009366535 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/InspecImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/InspecImporter.java @@ -121,7 +121,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { } } } - BibEntry b = new BibEntry(BibtexEntryTypes.getType(type).get()); + 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 83d0b77768a..1db5b39feeb 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/IsiImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/IsiImporter.java @@ -302,7 +302,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { continue; } - BibEntry b = new BibEntry(BibtexEntryTypes.getType(Type).get()); + 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/MedlinePlainImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/MedlinePlainImporter.java index 428807f6efc..1389c15d40e 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/MedlinePlainImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/MedlinePlainImporter.java @@ -209,7 +209,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { fields.put(FieldName.COMMENT, comment); } - BibEntry b = new BibEntry(BibtexEntryTypes.getType(type).get()); + 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 c67d5dbbcd1..23107e695cf 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/OvidImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/OvidImporter.java @@ -208,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(BibtexEntryTypes.getType(entryType).get()); + 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 9a2a260c67d..d778dd3d357 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java @@ -266,7 +266,7 @@ else if ("AV".equals(tag)) { // create one here // type is set in the loop above - BibEntry entry = new BibEntry(BibtexEntryTypes.getType(type).get()); + 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 bcc109ef85a..1b1d0f96559 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/SilverPlatterImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/SilverPlatterImporter.java @@ -181,7 +181,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { } - BibEntry b = new BibEntry(BibtexEntryTypes.getType(type).get()); + 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 3cc53dc2ca8..a95721fedd7 100644 --- a/src/main/java/org/jabref/logic/msbib/BibTeXConverter.java +++ b/src/main/java/org/jabref/logic/msbib/BibTeXConverter.java @@ -30,7 +30,7 @@ public static BibEntry convert(MSBibEntry entry) { Map fieldValues = new HashMap<>(); String bibTexEntryType = MSBibMapping.getBiblatexEntryType(entry.getType()); - result = new BibEntry(BibtexEntryTypes.getType(bibTexEntryType).get()); + result = new BibEntry(BibtexEntryTypes.getTypeOrDefault(bibTexEntryType)); // add String fields for (Map.Entry field : entry.fields.entrySet()) { diff --git a/src/test/java/org/jabref/model/BibDatabaseContextTest.java b/src/test/java/org/jabref/model/BibDatabaseContextTest.java index 3e88f0aa8c6..21da850ae03 100644 --- a/src/test/java/org/jabref/model/BibDatabaseContextTest.java +++ b/src/test/java/org/jabref/model/BibDatabaseContextTest.java @@ -47,6 +47,6 @@ public void testTypeBasedOnInferredModeBiblatex() { db.insertEntry(e1); BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(db); - assertEquals(BibDatabaseMode.BIBLATEX, bibDatabaseContext.getMode()); + assertEquals(BibDatabaseMode.BIBTEX, bibDatabaseContext.getMode()); } } From 85ddbf5c932191a478f01d184b96ed57abc83e97 Mon Sep 17 00:00:00 2001 From: Balhau Date: Fri, 28 Dec 2018 18:16:11 +0000 Subject: [PATCH 10/14] Revert Article EntryType into Electronic --- src/test/java/org/jabref/model/BibDatabaseContextTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/jabref/model/BibDatabaseContextTest.java b/src/test/java/org/jabref/model/BibDatabaseContextTest.java index 21da850ae03..928686653d8 100644 --- a/src/test/java/org/jabref/model/BibDatabaseContextTest.java +++ b/src/test/java/org/jabref/model/BibDatabaseContextTest.java @@ -5,6 +5,7 @@ import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibtexEntryTypes; +import org.jabref.model.entry.IEEETranEntryTypes; import org.jabref.model.metadata.MetaData; import org.junit.jupiter.api.Test; @@ -43,10 +44,10 @@ public void testTypeBasedOnInferredModeBibTeX() { @Test public void testTypeBasedOnInferredModeBiblatex() { BibDatabase db = new BibDatabase(); - BibEntry e1 = new BibEntry(BibtexEntryTypes.ARTICLE); + BibEntry e1 = new BibEntry(IEEETranEntryTypes.ELECTRONIC); db.insertEntry(e1); BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(db); - assertEquals(BibDatabaseMode.BIBTEX, bibDatabaseContext.getMode()); + assertEquals(BibDatabaseMode.BIBLATEX, bibDatabaseContext.getMode()); } } From a5c092c2944459ffdc6cdfda4cb3c2c97000192e Mon Sep 17 00:00:00 2001 From: Balhau Date: Fri, 28 Dec 2018 18:25:40 +0000 Subject: [PATCH 11/14] Added break line between different packages --- src/test/java/org/jabref/model/BibDatabaseContextTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/jabref/model/BibDatabaseContextTest.java b/src/test/java/org/jabref/model/BibDatabaseContextTest.java index 928686653d8..ac15534928b 100644 --- a/src/test/java/org/jabref/model/BibDatabaseContextTest.java +++ b/src/test/java/org/jabref/model/BibDatabaseContextTest.java @@ -6,6 +6,7 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.IEEETranEntryTypes; + import org.jabref.model.metadata.MetaData; import org.junit.jupiter.api.Test; From 46b4323acc7d25830a3cd72a9a5fd6010c1e8d6b Mon Sep 17 00:00:00 2001 From: Balhau Date: Fri, 28 Dec 2018 18:28:39 +0000 Subject: [PATCH 12/14] Refactor BibtextEntryTypes.getTypeOrDefault method --- src/main/java/org/jabref/model/entry/BibtexEntryTypes.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java b/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java index 896cda85caf..04909d1b954 100644 --- a/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java +++ b/src/main/java/org/jabref/model/entry/BibtexEntryTypes.java @@ -289,10 +289,6 @@ public static Optional getType(String name) { } public static EntryType getTypeOrDefault(String name) { - Optional optType = getType(name); - if (optType.isPresent()) { - return optType.get(); - } - return new CustomEntryType(name,"required","optional"); + return getType(name).orElseGet(() -> new CustomEntryType(name, "required", "optional")); } } From db0ddcbd721bc589a55a021c468432174ebeee86 Mon Sep 17 00:00:00 2001 From: Balhau Date: Fri, 28 Dec 2018 18:36:36 +0000 Subject: [PATCH 13/14] Removed unused import --- src/test/java/org/jabref/model/BibDatabaseContextTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/jabref/model/BibDatabaseContextTest.java b/src/test/java/org/jabref/model/BibDatabaseContextTest.java index ac15534928b..0c32f6e4649 100644 --- a/src/test/java/org/jabref/model/BibDatabaseContextTest.java +++ b/src/test/java/org/jabref/model/BibDatabaseContextTest.java @@ -4,7 +4,6 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.IEEETranEntryTypes; import org.jabref.model.metadata.MetaData; From 6233c6b657bb755e595940692c737031eb9c1b5e Mon Sep 17 00:00:00 2001 From: Balhau Date: Fri, 28 Dec 2018 18:44:42 +0000 Subject: [PATCH 14/14] Removed extra new line, checkstyle error fixing --- src/test/java/org/jabref/model/BibDatabaseContextTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/jabref/model/BibDatabaseContextTest.java b/src/test/java/org/jabref/model/BibDatabaseContextTest.java index 0c32f6e4649..42fc88abab6 100644 --- a/src/test/java/org/jabref/model/BibDatabaseContextTest.java +++ b/src/test/java/org/jabref/model/BibDatabaseContextTest.java @@ -5,7 +5,6 @@ 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;