From efa5b1aa37f84be772888d23547cd69bcd946859 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 17 Apr 2020 16:36:21 +0200 Subject: [PATCH 01/10] Rework journal abbreviation caching --- build.gradle | 1 + src/main/java/module-info.java | 1 + .../JournalsSuggestionProvider.java | 8 +- .../journals/AbbreviationsFileViewModel.java | 4 +- .../ManageJournalAbbreviationsViewModel.java | 3 +- .../logic/journals/AbbreviationParser.java | 39 +++----- .../journals/JournalAbbreviationLoader.java | 92 ++++++++++++------- .../JournalAbbreviationRepository.java | 72 ++++++++++----- .../integrity/AbbreviationCheckerTest.java | 5 +- .../logic/integrity/IntegrityCheckTest.java | 9 +- .../JournalAbbreviationRepositoryTest.java | 72 +++++++-------- ...ippedJournalAbbreviationDuplicateTest.java | 4 +- 12 files changed, 171 insertions(+), 139 deletions(-) diff --git a/build.gradle b/build.gradle index bef63748c5d..3e84e7f87ed 100644 --- a/build.gradle +++ b/build.gradle @@ -116,6 +116,7 @@ dependencies { implementation 'org.apache.pdfbox:xmpbox:2.0.19' implementation group: 'org.apache.commons', name: 'commons-csv', version: '1.8' + implementation 'com.h2database:h2-mvstore:1.4.200' implementation group: 'org.apache.tika', name: 'tika-core', version: '1.24' diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 6bbf87db090..c494250e6f2 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -88,4 +88,5 @@ requires flexmark.ext.gfm.tasklist; requires flexmark.util.ast; requires flexmark.util.data; + requires com.h2database.mvstore; } diff --git a/src/main/java/org/jabref/gui/autocompleter/JournalsSuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/JournalsSuggestionProvider.java index 5e8b5c95f4d..11a81f4cb22 100644 --- a/src/main/java/org/jabref/gui/autocompleter/JournalsSuggestionProvider.java +++ b/src/main/java/org/jabref/gui/autocompleter/JournalsSuggestionProvider.java @@ -1,11 +1,6 @@ package org.jabref.gui.autocompleter; -import java.util.List; -import java.util.stream.Collectors; - -import org.jabref.logic.journals.Abbreviation; import org.jabref.logic.journals.JournalAbbreviationLoader; -import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.model.entry.field.Field; public class JournalsSuggestionProvider extends FieldValueSuggestionProvider { @@ -14,11 +9,14 @@ public class JournalsSuggestionProvider extends FieldValueSuggestionProvider { JournalAbbreviationLoader abbreviationLoader) { super(field); + // TODO: Reimplement + /* JournalAbbreviationPreferences journalAbbreviationPreferences = preferences.getJournalAbbreviationPreferences(); List journals = abbreviationLoader.getRepository(journalAbbreviationPreferences) .getAbbreviations().stream() .map(Abbreviation::getName) .collect(Collectors.toList()); addPossibleSuggestions(journals); + */ } } diff --git a/src/main/java/org/jabref/gui/journals/AbbreviationsFileViewModel.java b/src/main/java/org/jabref/gui/journals/AbbreviationsFileViewModel.java index efa0bde3a69..45f4afa35ee 100644 --- a/src/main/java/org/jabref/gui/journals/AbbreviationsFileViewModel.java +++ b/src/main/java/org/jabref/gui/journals/AbbreviationsFileViewModel.java @@ -50,9 +50,9 @@ public AbbreviationsFileViewModel(List abbreviations, Str this.isBuiltInList = new SimpleBooleanProperty(true); } - public void readAbbreviations() throws FileNotFoundException { + public void readAbbreviations() throws IOException { if (path.isPresent()) { - List abbreviationList = JournalAbbreviationLoader.readJournalListFromFile(path.get().toFile()); + List abbreviationList = JournalAbbreviationLoader.readJournalListFromFile(path.get()); abbreviationList.forEach(abbreviation -> abbreviations.addAll(new AbbreviationViewModel(abbreviation))); } else { throw new FileNotFoundException(); diff --git a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java index 2835d0eff5f..32ae4caebb9 100644 --- a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java +++ b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java @@ -1,6 +1,5 @@ package org.jabref.gui.journals; -import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; @@ -183,7 +182,7 @@ private void openFile(Path filePath) { if (abbreviationsFile.exists()) { try { abbreviationsFile.readAbbreviations(); - } catch (FileNotFoundException e) { + } catch (IOException e) { logger.debug(e.getLocalizedMessage()); } } diff --git a/src/main/java/org/jabref/logic/journals/AbbreviationParser.java b/src/main/java/org/jabref/logic/journals/AbbreviationParser.java index 44d8d2e32ec..8251bc550b5 100644 --- a/src/main/java/org/jabref/logic/journals/AbbreviationParser.java +++ b/src/main/java/org/jabref/logic/journals/AbbreviationParser.java @@ -1,18 +1,17 @@ package org.jabref.logic.journals; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; -import java.net.URL; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.HashSet; import java.util.LinkedList; import java.util.List; -import java.util.Objects; import java.util.Set; import org.jabref.model.strings.StringUtil; @@ -33,32 +32,20 @@ public class AbbreviationParser { public void readJournalListFromResource(String resourceFileName) { try { - URL url = Objects.requireNonNull(JournalAbbreviationRepository.class.getResource(Objects.requireNonNull(resourceFileName))); - readJournalList(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8)); + InputStream stream = JournalAbbreviationRepository.class.getResourceAsStream(resourceFileName); + readJournalList(new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))); } catch (IOException e) { - LOGGER.info(String.format("Could not read journal list from file %s", resourceFileName), e); + LOGGER.error(String.format("Could not read journal list from file %s", resourceFileName), e); } } - public void readJournalListFromFile(File file) throws FileNotFoundException { - try (FileInputStream stream = new FileInputStream(Objects.requireNonNull(file)); - InputStreamReader reader = new InputStreamReader(stream, Objects.requireNonNull(StandardCharsets.UTF_8))) { - readJournalList(reader); - } catch (FileNotFoundException e) { - throw e; - } catch (IOException e) { - LOGGER.warn(String.format("Could not read journal list from file %s", file.getAbsolutePath()), e); - } + public void readJournalListFromFile(Path file) throws IOException { + readJournalListFromFile(file, StandardCharsets.UTF_8); } - public void readJournalListFromFile(File file, Charset encoding) throws FileNotFoundException { - try (FileInputStream stream = new FileInputStream(Objects.requireNonNull(file)); - InputStreamReader reader = new InputStreamReader(stream, Objects.requireNonNull(encoding))) { + public void readJournalListFromFile(Path file, Charset encoding) throws IOException { + try (BufferedReader reader = Files.newBufferedReader(file, encoding)) { readJournalList(reader); - } catch (FileNotFoundException e) { - throw e; - } catch (IOException e) { - LOGGER.warn(String.format("Could not read journal list from file %s", file.getAbsolutePath()), e); } } @@ -68,7 +55,7 @@ public void readJournalListFromFile(File file, Charset encoding) throws FileNotF * * @param reader a given file into a Reader object */ - private void readJournalList(Reader reader) { + private void readJournalList(Reader reader) throws IOException { try (CSVParser csvParser = new CSVParser(reader, AbbreviationFormat.getCSVFormat())) { for (CSVRecord csvRecord : csvParser) { String name = csvRecord.size() > 0 ? csvRecord.get(0) : StringUtil.EMPTY; @@ -82,8 +69,6 @@ private void readJournalList(Reader reader) { abbreviations.add(new Abbreviation(name, abbreviation, shortestUniqueAbbreviation)); } - } catch (IOException ex) { - LOGGER.info("Could not read journal list from file ", ex); } } diff --git a/src/main/java/org/jabref/logic/journals/JournalAbbreviationLoader.java b/src/main/java/org/jabref/logic/journals/JournalAbbreviationLoader.java index 64ea5871ea9..1cf1049bfcc 100644 --- a/src/main/java/org/jabref/logic/journals/JournalAbbreviationLoader.java +++ b/src/main/java/org/jabref/logic/journals/JournalAbbreviationLoader.java @@ -1,12 +1,15 @@ package org.jabref.logic.journals; -import java.io.File; -import java.io.FileNotFoundException; +import java.io.IOException; import java.nio.charset.Charset; +import java.nio.file.Path; import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; +import org.h2.mvstore.MVMap; +import org.h2.mvstore.MVStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,11 +17,11 @@ public class JournalAbbreviationLoader { private static final Logger LOGGER = LoggerFactory.getLogger(JournalAbbreviationLoader.class); - // Journal initialization private static final String JOURNALS_FILE_BUILTIN = "/journals/journalList.csv"; private static final String JOURNALS_IEEE_ABBREVIATION_LIST_WITH_CODE = "/journals/IEEEJournalListCode.csv"; private static final String JOURNALS_IEEE_ABBREVIATION_LIST_WITH_TEXT = "/journals/IEEEJournalListText.csv"; - private JournalAbbreviationRepository journalAbbrev; + + private JournalAbbreviationRepository repository = new JournalAbbreviationRepository(); public static List getOfficialIEEEAbbreviations() { return readJournalListFromResource(JOURNALS_IEEE_ABBREVIATION_LIST_WITH_CODE); @@ -32,41 +35,65 @@ public static List getBuiltInAbbreviations() { return readJournalListFromResource(JOURNALS_FILE_BUILTIN); } - public static List readJournalListFromResource(String resource) { + private static List readJournalListFromResource(String resource) { AbbreviationParser parser = new AbbreviationParser(); parser.readJournalListFromResource(Objects.requireNonNull(resource)); return parser.getAbbreviations(); } - public static List readJournalListFromFile(File file) throws FileNotFoundException { + public static List readJournalListFromFile(Path file) throws IOException { LOGGER.debug(String.format("Reading journal list from file %s", file)); AbbreviationParser parser = new AbbreviationParser(); - parser.readJournalListFromFile(Objects.requireNonNull(file)); + parser.readJournalListFromFile(file); return parser.getAbbreviations(); } - public static List readJournalListFromFile(File file, Charset encoding) throws FileNotFoundException { + private static List readJournalListFromFile(Path file, Charset encoding) throws IOException { LOGGER.debug(String.format("Reading journal list from file %s", file)); AbbreviationParser parser = new AbbreviationParser(); - parser.readJournalListFromFile(Objects.requireNonNull(file), Objects.requireNonNull(encoding)); + parser.readJournalListFromFile(file, Objects.requireNonNull(encoding)); return parser.getAbbreviations(); } - public void update(JournalAbbreviationPreferences journalAbbreviationPreferences) { - journalAbbrev = new JournalAbbreviationRepository(); - - // The order of reading the journal lists is important: last added abbreviation wins - // For instance, in the personal list one can overwrite abbreviations in the built in list - - // Read builtin list - journalAbbrev.addEntries(readJournalListFromResource(JOURNALS_FILE_BUILTIN)); - - // Read IEEE list - if (journalAbbreviationPreferences.useIEEEAbbreviations()) { - journalAbbrev.addEntries(getOfficialIEEEAbbreviations()); - } else { - journalAbbrev.addEntries(getStandardIEEEAbbreviations()); + public static void writeDefaultDatabase(Path targetDirectory) { + try (MVStore store = MVStore.open(targetDirectory.resolve("journalList.mv").getParent().toString())) { + MVMap fullToAbbreviation = store.openMap("FullToAbbreviation"); + + // Add all standard abbreviations + fullToAbbreviation.putAll( + getBuiltInAbbreviations() + .stream() + .collect(Collectors.toMap(Abbreviation::getName, Abbreviation::getAbbreviation)) + ); + + // Add all IEEE abbreviations + fullToAbbreviation.putAll( + getStandardIEEEAbbreviations() + .stream() + .collect(Collectors.toMap(Abbreviation::getName, Abbreviation::getAbbreviation)) + ); + + MVMap abbreviationToFull = store.openMap("AbbreviationToFull"); + + // Add all standard abbreviations + abbreviationToFull.putAll( + getBuiltInAbbreviations() + .stream() + .collect(Collectors.toMap(Abbreviation::getAbbreviation, Abbreviation::getName)) + ); + + // Add all IEEE abbreviations + abbreviationToFull.putAll( + getStandardIEEEAbbreviations() + .stream() + .collect(Collectors.toMap(Abbreviation::getAbbreviation, Abbreviation::getName)) + ); + //store.commit(); } + } + + public void update(JournalAbbreviationPreferences journalAbbreviationPreferences) { + repository = new JournalAbbreviationRepository(); // Read external lists List lists = journalAbbreviationPreferences.getExternalJournalLists(); @@ -74,10 +101,9 @@ public void update(JournalAbbreviationPreferences journalAbbreviationPreferences Collections.reverse(lists); for (String filename : lists) { try { - journalAbbrev.addEntries(readJournalListFromFile(new File(filename))); - } catch (FileNotFoundException e) { - // The file couldn't be found... should we tell anyone? - LOGGER.info(String.format("Cannot find external journal list file %s", filename), e); + repository.addCustomAbbreviations(readJournalListFromFile(Path.of(filename))); + } catch (IOException e) { + LOGGER.error(String.format("Cannot read external journal list file %s", filename), e); } } } @@ -86,19 +112,19 @@ public void update(JournalAbbreviationPreferences journalAbbreviationPreferences String personalJournalList = journalAbbreviationPreferences.getPersonalJournalLists(); if ((personalJournalList != null) && !personalJournalList.trim().isEmpty()) { try { - journalAbbrev.addEntries( - readJournalListFromFile(new File(personalJournalList), + repository.addCustomAbbreviations( + readJournalListFromFile(Path.of(personalJournalList), journalAbbreviationPreferences.getDefaultEncoding())); - } catch (FileNotFoundException e) { - LOGGER.info(String.format("Personal journal list file '%s' not found.", personalJournalList), e); + } catch (IOException e) { + LOGGER.error(String.format("Personal journal list file '%s' could not be read.", personalJournalList), e); } } } public JournalAbbreviationRepository getRepository(JournalAbbreviationPreferences journalAbbreviationPreferences) { - if (journalAbbrev == null) { + if (repository == null) { update(journalAbbreviationPreferences); } - return journalAbbrev; + return repository; } } diff --git a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java index bb4a07481e3..c2baa839372 100644 --- a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java +++ b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java @@ -1,24 +1,28 @@ package org.jabref.logic.journals; +import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; +import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.Set; + +import org.h2.mvstore.MVMap; +import org.h2.mvstore.MVStore; /** * A repository for all journal abbreviations, including add and find methods. */ public class JournalAbbreviationRepository { - // We have over 15.000 abbreviations in the built-in lists - private final Set abbreviations = new HashSet<>(16000); + private final MVMap fullToAbbreviation; + private final MVMap abbreviationToFull; + private final List customAbbreviations; - public JournalAbbreviationRepository(Abbreviation... abbreviations) { - for (Abbreviation abbreviation : abbreviations) { - addEntry(abbreviation); - } + public JournalAbbreviationRepository() { + MVStore store = new MVStore.Builder().readOnly().fileName("journalList.mv").open(); + this.fullToAbbreviation = store.openMap("FullToAbbreviation"); + this.abbreviationToFull = store.openMap("AbbreviationToFull"); + this.customAbbreviations = new ArrayList<>(); } private static boolean isMatched(String name, Abbreviation abbreviation) { @@ -36,16 +40,19 @@ private static boolean isMatchedAbbreviated(String name, Abbreviation abbreviati return isAbbreviated && !isExpanded; } - public int size() { - return abbreviations.size(); - } - /** * Returns true if the given journal name is contained in the list either in its full form (e.g Physical Review * Letters) or its abbreviated form (e.g. Phys. Rev. Lett.). */ public boolean isKnownName(String journalName) { - return abbreviations.stream().anyMatch(abbreviation -> isMatched(journalName.trim(), abbreviation)); + String journal = journalName.trim(); + + boolean isKnown = customAbbreviations.stream().anyMatch(abbreviation -> isMatched(journal, abbreviation)); + if (isKnown) { + return true; + } + + return fullToAbbreviation.containsKey(journal) || abbreviationToFull.containsKey(journal); } /** @@ -53,7 +60,14 @@ public boolean isKnownName(String journalName) { * i.e. journals whose abbreviation is the same as the full name are not considered */ public boolean isAbbreviatedName(String journalName) { - return abbreviations.stream().anyMatch(abbreviation -> isMatchedAbbreviated(journalName.trim(), abbreviation)); + String journal = journalName.trim(); + + boolean isAbbreviated = customAbbreviations.stream().anyMatch(abbreviation -> isMatchedAbbreviated(journal, abbreviation)); + if (isAbbreviated) { + return true; + } + + return abbreviationToFull.containsKey(journal); } /** @@ -63,23 +77,33 @@ public boolean isAbbreviatedName(String journalName) { * @return The abbreviated name */ public Optional getAbbreviation(String journalName) { - return abbreviations.stream().filter(abbreviation -> isMatched(journalName.trim(), abbreviation)).findFirst(); + String journal = journalName.trim(); + + Optional customAbbreviation = customAbbreviations.stream() + .filter(abbreviation -> isMatched(journal, abbreviation)) + .findAny(); + if (customAbbreviation.isPresent()) { + return customAbbreviation; + } + + return Optional.ofNullable(fullToAbbreviation.get(journal)) + .map(abbreviation -> new Abbreviation(journal, abbreviation)); } - public void addEntry(Abbreviation abbreviation) { + public void addCustomAbbreviation(Abbreviation abbreviation) { Objects.requireNonNull(abbreviation); - // Abbreviation equality is tested on name only, so we might have to remove an old abbreviation - abbreviations.remove(abbreviation); - abbreviations.add(abbreviation); + // We do not want to keep duplicates, thus remove the old abbreviation + customAbbreviations.remove(abbreviation); + customAbbreviations.add(abbreviation); } - public void addEntries(Collection abbreviationsToAdd) { - abbreviationsToAdd.forEach(this::addEntry); + public List getCustomAbbreviations() { + return customAbbreviations; } - public Set getAbbreviations() { - return Collections.unmodifiableSet(abbreviations); + public void addCustomAbbreviations(Collection abbreviationsToAdd) { + abbreviationsToAdd.forEach(this::addCustomAbbreviation); } public Optional getNextAbbreviation(String text) { diff --git a/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java b/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java index 033bdbe98d1..3dd354c0009 100644 --- a/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java @@ -18,7 +18,8 @@ class AbbreviationCheckerTest { @BeforeEach void setUp() { - abbreviationRepository = new JournalAbbreviationRepository(new Abbreviation("Test Journal", "T. J.")); + abbreviationRepository = new JournalAbbreviationRepository(); + abbreviationRepository.addCustomAbbreviation(new Abbreviation("Test Journal", "T. J.")); checker = new AbbreviationChecker(abbreviationRepository); } @@ -29,7 +30,7 @@ void checkValueComplainsAboutAbbreviatedJournalName() { @Test void checkValueDoesNotComplainAboutJournalNameThatHasSameAbbreviation() { - abbreviationRepository.addEntry(new Abbreviation("Journal", "Journal")); + abbreviationRepository.addCustomAbbreviation(new Abbreviation("Journal", "Journal")); assertEquals(Optional.empty(), checker.checkValue("Journal")); } } diff --git a/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java index 6f2a4a62009..a5725f7882a 100644 --- a/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java +++ b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java @@ -10,7 +10,6 @@ import java.util.UUID; import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; -import org.jabref.logic.journals.Abbreviation; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern; import org.jabref.model.database.BibDatabase; @@ -368,7 +367,7 @@ void testEntryIsUnchangedAfterChecks() { new IntegrityCheck(context, mock(FilePreferences.class), createBibtexKeyPatternPreferences(), - new JournalAbbreviationRepository(new Abbreviation("IEEE Software", "IEEE SW")), true, false) + new JournalAbbreviationRepository(), true, false) .checkDatabase(); assertEquals(clonedEntry, entry); @@ -408,7 +407,7 @@ private void assertWrong(BibDatabaseContext context) { List messages = new IntegrityCheck(context, mock(FilePreferences.class), createBibtexKeyPatternPreferences(), - new JournalAbbreviationRepository(new Abbreviation("IEEE Software", "IEEE SW")), true, false) + new JournalAbbreviationRepository(), true, false) .checkDatabase(); assertNotEquals(Collections.emptyList(), messages); } @@ -417,7 +416,7 @@ private void assertCorrect(BibDatabaseContext context) { List messages = new IntegrityCheck(context, mock(FilePreferences.class), createBibtexKeyPatternPreferences(), - new JournalAbbreviationRepository(new Abbreviation("IEEE Software", "IEEE SW")), true, false + new JournalAbbreviationRepository(), true, false ).checkDatabase(); assertEquals(Collections.emptyList(), messages); } @@ -426,7 +425,7 @@ private void assertCorrect(BibDatabaseContext context, boolean allowIntegerEditi List messages = new IntegrityCheck(context, mock(FilePreferences.class), createBibtexKeyPatternPreferences(), - new JournalAbbreviationRepository(new Abbreviation("IEEE Software", "IEEE SW")), true, + new JournalAbbreviationRepository(), true, allowIntegerEdition ).checkDatabase(); assertEquals(Collections.emptyList(), messages); diff --git a/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java b/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java index aae00e61ce0..2655408d544 100644 --- a/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java +++ b/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java @@ -6,20 +6,19 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -public class JournalAbbreviationRepositoryTest { +class JournalAbbreviationRepositoryTest { @Test - public void empty() { + void empty() { JournalAbbreviationRepository repository = new JournalAbbreviationRepository(); - assertTrue(repository.getAbbreviations().isEmpty()); + assertTrue(repository.getCustomAbbreviations().isEmpty()); } @Test - public void oneElement() { + void oneElement() { JournalAbbreviationRepository repository = new JournalAbbreviationRepository(); - repository.addEntry(new Abbreviation("Long Name", "L. N.")); - assertEquals(1, repository.size()); - assertFalse(repository.getAbbreviations().isEmpty()); + repository.addCustomAbbreviation(new Abbreviation("Long Name", "L. N.")); + assertEquals(1, repository.getCustomAbbreviations().size()); assertEquals("L. N.", repository.getDefaultAbbreviation("Long Name").orElse("WRONG")); assertEquals("UNKNOWN", repository.getDefaultAbbreviation("?").orElse("UNKNOWN")); @@ -42,11 +41,10 @@ public void oneElement() { } @Test - public void oneElementWithShortestUniqueAbbreviation() { + void oneElementWithShortestUniqueAbbreviation() { JournalAbbreviationRepository repository = new JournalAbbreviationRepository(); - repository.addEntry(new Abbreviation("Long Name", "L. N.", "LN")); - assertEquals(1, repository.size()); - assertFalse(repository.getAbbreviations().isEmpty()); + repository.addCustomAbbreviation(new Abbreviation("Long Name", "L. N.", "LN")); + assertEquals(1, repository.getCustomAbbreviations().size()); assertEquals("L. N.", repository.getDefaultAbbreviation("Long Name").orElse("WRONG")); assertEquals("UNKNOWN", repository.getDefaultAbbreviation("?").orElse("UNKNOWN")); @@ -71,59 +69,59 @@ public void oneElementWithShortestUniqueAbbreviation() { } @Test - public void testDuplicates() { + void testDuplicates() { JournalAbbreviationRepository repository = new JournalAbbreviationRepository(); - repository.addEntry(new Abbreviation("Long Name", "L. N.")); - repository.addEntry(new Abbreviation("Long Name", "L. N.")); - assertEquals(1, repository.size()); + repository.addCustomAbbreviation(new Abbreviation("Long Name", "L. N.")); + repository.addCustomAbbreviation(new Abbreviation("Long Name", "L. N.")); + assertEquals(1, repository.getCustomAbbreviations().size()); } @Test - public void testDuplicatesWithShortestUniqueAbbreviation() { + void testDuplicatesWithShortestUniqueAbbreviation() { JournalAbbreviationRepository repository = new JournalAbbreviationRepository(); - repository.addEntry(new Abbreviation("Long Name", "L. N.", "LN")); - repository.addEntry(new Abbreviation("Long Name", "L. N.", "LN")); - assertEquals(1, repository.size()); + repository.addCustomAbbreviation(new Abbreviation("Long Name", "L. N.", "LN")); + repository.addCustomAbbreviation(new Abbreviation("Long Name", "L. N.", "LN")); + assertEquals(1, repository.getCustomAbbreviations().size()); } @Test - public void testDuplicatesIsoOnly() { + void testDuplicatesIsoOnly() { JournalAbbreviationRepository repository = new JournalAbbreviationRepository(); - repository.addEntry(new Abbreviation("Old Long Name", "L. N.")); - repository.addEntry(new Abbreviation("New Long Name", "L. N.")); - assertEquals(2, repository.size()); + repository.addCustomAbbreviation(new Abbreviation("Old Long Name", "L. N.")); + repository.addCustomAbbreviation(new Abbreviation("New Long Name", "L. N.")); + assertEquals(2, repository.getCustomAbbreviations().size()); } @Test - public void testDuplicatesIsoOnlyWithShortestUniqueAbbreviation() { + void testDuplicatesIsoOnlyWithShortestUniqueAbbreviation() { JournalAbbreviationRepository repository = new JournalAbbreviationRepository(); - repository.addEntry(new Abbreviation("Old Long Name", "L. N.", "LN")); - repository.addEntry(new Abbreviation("New Long Name", "L. N.", "LN")); - assertEquals(2, repository.size()); + repository.addCustomAbbreviation(new Abbreviation("Old Long Name", "L. N.", "LN")); + repository.addCustomAbbreviation(new Abbreviation("New Long Name", "L. N.", "LN")); + assertEquals(2, repository.getCustomAbbreviations().size()); } @Test - public void testDuplicateKeys() { + void testDuplicateKeys() { JournalAbbreviationRepository repository = new JournalAbbreviationRepository(); - repository.addEntry(new Abbreviation("Long Name", "L. N.")); - assertEquals(1, repository.size()); + repository.addCustomAbbreviation(new Abbreviation("Long Name", "L. N.")); + assertEquals(1, repository.getCustomAbbreviations().size()); assertEquals("L. N.", repository.getDefaultAbbreviation("Long Name").orElse("WRONG")); - repository.addEntry(new Abbreviation("Long Name", "LA. N.")); - assertEquals(1, repository.size()); + repository.addCustomAbbreviation(new Abbreviation("Long Name", "LA. N.")); + assertEquals(1, repository.getCustomAbbreviations().size()); assertEquals("LA. N.", repository.getDefaultAbbreviation("Long Name").orElse("WRONG")); } @Test - public void testDuplicateKeysWithShortestUniqueAbbreviation() { + void testDuplicateKeysWithShortestUniqueAbbreviation() { JournalAbbreviationRepository repository = new JournalAbbreviationRepository(); - repository.addEntry(new Abbreviation("Long Name", "L. N.", "LN")); - assertEquals(1, repository.size()); + repository.addCustomAbbreviation(new Abbreviation("Long Name", "L. N.", "LN")); + assertEquals(1, repository.getCustomAbbreviations().size()); assertEquals("L. N.", repository.getDefaultAbbreviation("Long Name").orElse("WRONG")); assertEquals("LN", repository.getShortestUniqueAbbreviation("Long Name").orElse("WRONG")); - repository.addEntry(new Abbreviation("Long Name", "LA. N.", "LAN")); - assertEquals(1, repository.size()); + repository.addCustomAbbreviation(new Abbreviation("Long Name", "LA. N.", "LAN")); + assertEquals(1, repository.getCustomAbbreviations().size()); assertEquals("LA. N.", repository.getDefaultAbbreviation("Long Name").orElse("WRONG")); assertEquals("LAN", repository.getShortestUniqueAbbreviation("Long Name").orElse("WRONG")); } diff --git a/src/test/java/org/jabref/logic/journals/ShippedJournalAbbreviationDuplicateTest.java b/src/test/java/org/jabref/logic/journals/ShippedJournalAbbreviationDuplicateTest.java index 3de917ca259..5c39474cc52 100644 --- a/src/test/java/org/jabref/logic/journals/ShippedJournalAbbreviationDuplicateTest.java +++ b/src/test/java/org/jabref/logic/journals/ShippedJournalAbbreviationDuplicateTest.java @@ -9,7 +9,7 @@ public class ShippedJournalAbbreviationDuplicateTest { @Test public void noDuplicatesInShippedIEEEOfficialJournalAbbreviations() { JournalAbbreviationRepository repoBuiltIn = new JournalAbbreviationRepository(); - repoBuiltIn.addEntries(JournalAbbreviationLoader.getBuiltInAbbreviations()); + repoBuiltIn.addCustomAbbreviations(JournalAbbreviationLoader.getBuiltInAbbreviations()); JournalAbbreviationLoader.getOfficialIEEEAbbreviations().parallelStream().forEach(abbreviation -> { assertFalse(repoBuiltIn.getAbbreviation(abbreviation.getName()).isPresent()); @@ -21,7 +21,7 @@ public void noDuplicatesInShippedIEEEOfficialJournalAbbreviations() { @Test public void noDuplicatesInShippedIEEEStandardJournalAbbreviations() { JournalAbbreviationRepository repoBuiltIn = new JournalAbbreviationRepository(); - repoBuiltIn.addEntries(JournalAbbreviationLoader.getBuiltInAbbreviations()); + repoBuiltIn.addCustomAbbreviations(JournalAbbreviationLoader.getBuiltInAbbreviations()); JournalAbbreviationLoader.getStandardIEEEAbbreviations().parallelStream().forEach(abbreviation -> { assertFalse(repoBuiltIn.getAbbreviation(abbreviation.getName()).isPresent(), "duplicate name " + abbreviation.toString()); From 7fc293f9179a90a5d7edd04d898df5d421af53d5 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Thu, 23 Apr 2020 22:17:21 +0200 Subject: [PATCH 02/10] Add ADR-0010 --- docs/adr/0010-use-h2-as-internal-database.md | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 docs/adr/0010-use-h2-as-internal-database.md diff --git a/docs/adr/0010-use-h2-as-internal-database.md b/docs/adr/0010-use-h2-as-internal-database.md new file mode 100644 index 00000000000..471bcf21332 --- /dev/null +++ b/docs/adr/0010-use-h2-as-internal-database.md @@ -0,0 +1,24 @@ +# Use H2 as Internal SQL Database + +## Context and Problem Statement + +We need to store data internally in a structured way to gain performance. + +## Decision Drivers + +* Easy to integrate +* Easy to use +* Common technology + +## Considered Options + +* [H2 Database Engine](http://www.h2database.com/html/main.html) +* [SQLite](https://www.sqlite.org/index.html) + +## Decision Outcome + +Chosen option: "H2 Database Engine", because it was straight-forward to use. + +## Links + +* [Comparison at SQL Workbench](https://www.sql-workbench.eu/dbms_comparison.html) From 384747ecdc1e5fa869a69ed5a9646b9e1d203ced Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 24 Apr 2020 14:14:50 +0200 Subject: [PATCH 03/10] Remove IEEE abbreviations --- CHANGELOG.md | 1 + .../ManageJournalAbbreviationsViewModel.java | 26 +- .../jabref/gui/preferences/AdvancedTab.fxml | 3 - .../gui/preferences/AdvancedTabView.java | 4 - .../gui/preferences/AdvancedTabViewModel.java | 27 +- .../journals/JournalAbbreviationLoader.java | 42 +-- .../JournalAbbreviationPreferences.java | 19 +- .../jabref/preferences/JabRefPreferences.java | 8 +- .../journals/IEEEJournalListCode.csv | 263 ------------------ .../journals/IEEEJournalListText.csv | 263 ------------------ ...ationsViewModelMixedAbbreviationsTest.java | 18 +- ...odelNoShortestUniqueAbbreviationsTest.java | 18 +- ...elWithShortestUniqueAbbreviationsTest.java | 18 +- .../logic/journals/AbbreviationsTest.java | 45 +-- ...ippedJournalAbbreviationDuplicateTest.java | 32 --- 15 files changed, 28 insertions(+), 759 deletions(-) delete mode 100644 src/main/resources/journals/IEEEJournalListCode.csv delete mode 100644 src/main/resources/journals/IEEEJournalListText.csv delete mode 100644 src/test/java/org/jabref/logic/journals/ShippedJournalAbbreviationDuplicateTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d363c184f3..9890a4aa992 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We removed the obsolete `External programs / Open PDF` section in the preferences, as the default application to open PDFs is now set in the `Manage external file types` dialog. [#6130](https://github.com/JabRef/jabref/pull/6130) - We removed the option to configure whether a `.bib.bak` file should be generated upon save. It is now always enabled. Documentation at . [#6092](https://github.com/JabRef/jabref/issues/6092) +- We removed the built-in list of IEEE journal abbreviations using BibTeX strings. If you still want to use them, you have to download them separately from . ## [5.0] – 2020-03-06 diff --git a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java index 32ae4caebb9..5fdb140b68c 100644 --- a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java +++ b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java @@ -45,8 +45,6 @@ public class ManageJournalAbbreviationsViewModel extends AbstractViewModel { private final SimpleObjectProperty currentAbbreviation = new SimpleObjectProperty<>(); private final SimpleBooleanProperty isFileRemovable = new SimpleBooleanProperty(); private final SimpleBooleanProperty isLoading = new SimpleBooleanProperty(false); - private final SimpleBooleanProperty isLoadingBuiltIn = new SimpleBooleanProperty(false); - private final SimpleBooleanProperty isLoadingIeee = new SimpleBooleanProperty(false); private final SimpleBooleanProperty isEditableAndRemovable = new SimpleBooleanProperty(false); private final SimpleBooleanProperty isAbbreviationEditableAndRemovable = new SimpleBooleanProperty(false); private final PreferencesService preferences; @@ -101,7 +99,6 @@ public ManageJournalAbbreviationsViewModel(PreferencesService preferences, Dialo } } }); - isLoading.bind(isLoadingBuiltIn.or(isLoadingIeee)); } public SimpleBooleanProperty isLoadingProperty() { @@ -109,32 +106,19 @@ public SimpleBooleanProperty isLoadingProperty() { } /** - * This will wrap the built in and ieee abbreviations in pseudo abbreviation files and add them to the list of - * journal abbreviation files. + * This will load the built in abbreviation files and add it to the list of journal abbreviation files. */ - void addBuiltInLists() { + void addBuiltInList() { BackgroundTask .wrap(JournalAbbreviationLoader::getBuiltInAbbreviations) - .onRunning(() -> isLoadingBuiltIn.setValue(true)) + .onRunning(() -> isLoading.setValue(true)) .onSuccess(result -> { - isLoadingBuiltIn.setValue(false); + isLoading.setValue(false); addList(Localization.lang("JabRef built in list"), result); selectLastJournalFile(); }) .onFailure(dialogService::showErrorDialogAndWait) .executeWith(taskExecutor); - - BackgroundTask - .wrap(() -> abbreviationsPreferences.useIEEEAbbreviations() - ? JournalAbbreviationLoader.getOfficialIEEEAbbreviations() - : JournalAbbreviationLoader.getStandardIEEEAbbreviations()) - .onRunning(() -> isLoadingIeee.setValue(true)) - .onSuccess(result -> { - isLoadingIeee.setValue(false); - addList(Localization.lang("IEEE built in list"), result); - }) - .onFailure(dialogService::showErrorDialogAndWait) - .executeWith(taskExecutor); } private void addList(String name, List abbreviations) { @@ -411,6 +395,6 @@ public void addAbbreviation() { public void init() { createFileObjects(); selectLastJournalFile(); - addBuiltInLists(); + addBuiltInList(); } } diff --git a/src/main/java/org/jabref/gui/preferences/AdvancedTab.fxml b/src/main/java/org/jabref/gui/preferences/AdvancedTab.fxml index a98ac76d508..57bf6241d0c 100644 --- a/src/main/java/org/jabref/gui/preferences/AdvancedTab.fxml +++ b/src/main/java/org/jabref/gui/preferences/AdvancedTab.fxml @@ -24,9 +24,6 @@