Skip to content

Commit

Permalink
Remove empty customization warning (#5525)
Browse files Browse the repository at this point in the history
Remove empty customization warning
  • Loading branch information
koppor authored Oct 27, 2019
2 parents 9d8cac4 + 30c5000 commit f14b12b
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 43 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where it was no longer possible to connect to LibreOffice. [#5261](https://github.com/JabRef/jabref/issues/5261)
- The "All entries group" is no longer shown when no library is open.
- We fixed an exception which occurred when closing JabRef. [#5348](https://github.com/JabRef/jabref/issues/5348)
- We fixed an issue where JabRef reports incorrectly about customized entry types. [#5332](https://github.com/JabRef/jabref/issues/5332)
- We fixed a few problems that prevented JabFox to communicate with JabRef. [#4737](https://github.com/JabRef/jabref/issues/4737) [#4303](https://github.com/JabRef/jabref/issues/4303)
- We fixed an error where the groups containing an entry loose their highlight color when scrolling. [#5022](https://github.com/JabRef/jabref/issues/5022)
- We fixed an error where scrollbars were not shown. [#5374](https://github.com/JabRef/jabref/issues/5374)
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ public void start(Stage mainStage) throws Exception {
Platform.exit();
}
}

@Override
public void stop() {
Globals.stopBackgroundTasks();
Globals.shutdownThreadPools();
}

/**
* Tests if we are running an acceptable Java and terminates JabRef when we are sure the version is not supported.
* This test uses the requirements for the Java version as specified in <code>gradle.build</code>. It is possible to
Expand Down Expand Up @@ -166,7 +166,7 @@ private static void applyPreferences(JabRefPreferences preferences) {
// Build list of Import and Export formats
Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(),
Globals.prefs.getXMPPreferences(), Globals.getFileUpdateMonitor());
Globals.entryTypesManager.addCustomizedEntryTypes(preferences.loadBibEntryTypes(BibDatabaseMode.BIBTEX),
Globals.entryTypesManager.addCustomOrModifiedTypes(preferences.loadBibEntryTypes(BibDatabaseMode.BIBTEX),
preferences.loadBibEntryTypes(BibDatabaseMode.BIBLATEX));
Globals.exportFactory = Globals.prefs.getExporterFactory(Globals.journalAbbreviationLoader);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ private void exportFile(List<ParserResult> loaded, String[] data) {
private void importPreferences() {
try {
Globals.prefs.importPreferences(cli.getPreferencesImport());
Globals.entryTypesManager.addCustomizedEntryTypes(Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBTEX),
Globals.entryTypesManager.addCustomOrModifiedTypes(Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBTEX),
Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBLATEX));
List<TemplateExporter> customExporters = Globals.prefs.getCustomExportFormats(Globals.journalAbbreviationLoader);
LayoutFormatterPreferences layoutPreferences = Globals.prefs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
xmlns="http://javafx.com/javafx/8.0.171"
fx:controller="org.jabref.gui.importer.ImportCustomEntryTypesDialog">
<content>
<VBox minHeight="-Infinity" prefHeight="113.0" prefWidth="571.0" spacing="1.0">
<VBox spacing="1.0">
<children>
<Label text="%Custom entry types found in file" />
<Label text="%Select all customized types to be stored in local preferences:" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public ImportCustomEntryTypesDialog(BibDatabaseMode mode, List<BibEntryType> cus
});

setTitle(Localization.lang("Custom entry types"));

}

@FXML
public void initialize() {
viewModel = new ImportCustomEntryTypesDialogViewModel(mode, customEntryTypes, preferencesService);

boxDifferentCustomization.visibleProperty().bind(Bindings.isNotEmpty(viewModel.differentCustomizations()));
boxDifferentCustomization.managedProperty().bind(Bindings.isNotEmpty(viewModel.differentCustomizations()));
unknownEntryTypesCheckList.setItems(viewModel.newTypes());
differentCustomizationCheckList.setItems(viewModel.differentCustomizations());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ImportCustomEntryTypesDialogViewModel(BibDatabaseMode mode, List<BibEntry

for (BibEntryType customType : entryTypes) {
Optional<BibEntryType> currentlyStoredType = Globals.entryTypesManager.enrich(customType.getType(), mode);
if (!currentlyStoredType.isPresent()) {
if (currentlyStoredType.isEmpty()) {
newTypes.add(customType);
} else {
if (!EntryTypeFactory.isEqualNameAndFieldBased(customType, currentlyStoredType.get())) {
Expand All @@ -47,11 +47,11 @@ public ObservableList<BibEntryType> differentCustomizations() {

public void importBibEntryTypes(List<BibEntryType> checkedUnknownEntryTypes, List<BibEntryType> checkedDifferentEntryTypes) {
if (!checkedUnknownEntryTypes.isEmpty()) {
checkedUnknownEntryTypes.forEach(type -> Globals.entryTypesManager.addCustomizedEntryType(type, mode));
checkedUnknownEntryTypes.forEach(type -> Globals.entryTypesManager.addCustomOrModifiedType(type, mode));
preferencesService.saveCustomEntryTypes();
}
if (!checkedDifferentEntryTypes.isEmpty()) {
checkedUnknownEntryTypes.forEach(type -> Globals.entryTypesManager.addCustomizedEntryType(type, mode));
checkedUnknownEntryTypes.forEach(type -> Globals.entryTypesManager.addCustomOrModifiedType(type, mode));
preferencesService.saveCustomEntryTypes();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ public void performAction(BasePanel panel, ParserResult parserResult) {

ImportCustomEntryTypesDialog importBibEntryTypesDialog = new ImportCustomEntryTypesDialog(mode, getListOfUnknownAndUnequalCustomizations(parserResult));
importBibEntryTypesDialog.showAndWait();

}

private List<BibEntryType> getListOfUnknownAndUnequalCustomizations(ParserResult parserResult) {
BibDatabaseMode mode = getBibDatabaseModeFromParserResult(parserResult);

return parserResult.getEntryTypes()
.stream()
.filter(type -> Globals.entryTypesManager.isCustomizedType(type, mode))
.filter(type -> Globals.entryTypesManager.isDifferentCustomOrModifiedType(type, mode))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void upgradeStoredBibEntryTypes(BibDatabaseMode defaultBibDatabaseMode) {
int number = 0;
Optional<BibEntryType> type;
while ((type = getBibEntryType(number)).isPresent()) {
Globals.entryTypesManager.addCustomizedEntryType(type.get(), defaultBibDatabaseMode);
Globals.entryTypesManager.addCustomOrModifiedType(type.get(), defaultBibDatabaseMode);
storedOldTypes.add(type.get());
number++;
}
Expand Down
48 changes: 30 additions & 18 deletions src/main/java/org/jabref/model/entry/BibEntryTypesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ public static String serialize(BibEntryType entryType) {
/**
* Returns true if the type is a custom type, or if it is a standard type which has customized fields
*/
public boolean isCustomizedType(BibEntryType type, BibDatabaseMode mode) {
return mode == BibDatabaseMode.BIBLATEX ? BIBLATEX.isCustomizedType(type) : BIBTEX.isCustomizedType(type);
public boolean isCustomOrModifiedType(BibEntryType type, BibDatabaseMode mode) {
return mode == BibDatabaseMode.BIBLATEX ? BIBLATEX.isCustomOrModifiedType(type) : BIBTEX.isCustomOrModifiedType(type);
}

/**
* Sets the given custom entry types for BibTeX and biblatex mode
*/
public void addCustomizedEntryTypes(List<BibEntryType> customBibtexEntryTypes, List<BibEntryType> customBiblatexEntryTypes) {
customBibtexEntryTypes.forEach(type -> addCustomizedEntryType(type, BibDatabaseMode.BIBTEX));
customBiblatexEntryTypes.forEach(type -> addCustomizedEntryType(type, BibDatabaseMode.BIBLATEX));
public void addCustomOrModifiedTypes(List<BibEntryType> customizedBibtexEntryTypes, List<BibEntryType> customizedBiblatexEntryTypes) {
customizedBibtexEntryTypes.forEach(type -> addCustomOrModifiedType(type, BibDatabaseMode.BIBTEX));
customizedBiblatexEntryTypes.forEach(type -> addCustomOrModifiedType(type, BibDatabaseMode.BIBLATEX));
}

/**
Expand All @@ -104,11 +104,11 @@ public List<BibEntryType> getAllCustomTypes(BibDatabaseMode mode) {
}
}

public void addCustomizedEntryType(BibEntryType entryType, BibDatabaseMode mode) {
public void addCustomOrModifiedType(BibEntryType entryType, BibDatabaseMode mode) {
if (BibDatabaseMode.BIBLATEX == mode) {
BIBLATEX.addCustomizedType(entryType);
BIBLATEX.addCustomOrModifiedType(entryType);
} else if (BibDatabaseMode.BIBTEX == mode) {
BIBTEX.addCustomizedType(entryType);
BIBTEX.addCustomOrModifiedType(entryType);
}
}

Expand All @@ -127,11 +127,22 @@ public Optional<BibEntryType> enrich(EntryType type, BibDatabaseMode mode) {
return mode == BibDatabaseMode.BIBLATEX ? BIBLATEX.enrich(type) : BIBTEX.enrich(type);
}

public boolean isDifferentCustomOrModifiedType(BibEntryType type, BibDatabaseMode mode) {
Optional<BibEntryType> currentlyStoredType = enrich(type.getType(), mode);
if (currentlyStoredType.isEmpty()) {
// new customization
return true;
} else {
// different customization
return !EntryTypeFactory.isEqualNameAndFieldBased(type, currentlyStoredType.get());
}
}

/**
* This class is used to specify entry types for either BIBTEX and BIBLATEX.
*/
static class InternalEntryTypes {
private final SortedSet<BibEntryType> customizedTypes = new TreeSet<>();
private final SortedSet<BibEntryType> customOrModifiedType = new TreeSet<>();
private final SortedSet<BibEntryType> standardTypes;

public InternalEntryTypes(List<BibEntryType> standardTypes) {
Expand All @@ -143,9 +154,9 @@ public InternalEntryTypes(List<BibEntryType> standardTypes) {
* or null if it does not exist.
*/
public Optional<BibEntryType> enrich(EntryType type) {
Optional<BibEntryType> enrichedType = customizedTypes.stream()
.filter(customizedType -> customizedType.getType().equals(type))
.findFirst();
Optional<BibEntryType> enrichedType = customOrModifiedType.stream()
.filter(customizedType -> customizedType.getType().equals(type))
.findFirst();
if (enrichedType.isPresent()) {
return enrichedType;
} else {
Expand All @@ -155,19 +166,20 @@ public Optional<BibEntryType> enrich(EntryType type) {
}
}

private void addCustomizedType(BibEntryType type) {
customizedTypes.remove(type);
customizedTypes.add(type);
private void addCustomOrModifiedType(BibEntryType type) {
customOrModifiedType.remove(type);
customOrModifiedType.add(type);
}

public SortedSet<BibEntryType> getAllTypes() {
SortedSet<BibEntryType> allTypes = new TreeSet<>(customizedTypes);
SortedSet<BibEntryType> allTypes = new TreeSet<>(customOrModifiedType);
allTypes.addAll(standardTypes);
return allTypes;
}

public boolean isCustomizedType(BibEntryType entryType) {
return customizedTypes.stream().anyMatch(customizedType -> customizedType.getType().equals(entryType.getType()));
public boolean isCustomOrModifiedType(BibEntryType entryType) {
return customOrModifiedType.stream()
.anyMatch(customizedType -> customizedType.getType().equals(entryType.getType()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void writeEntryWithCustomizedTypeAlsoWritesTypeDeclaration() throws Exception {
new OrFields(StandardField.TITLE),
new OrFields(StandardField.AUTHOR),
new OrFields(StandardField.DATE)));
entryTypesManager.addCustomizedEntryType(customizedBibType, BibDatabaseMode.BIBTEX);
entryTypesManager.addCustomOrModifiedType(customizedBibType, BibDatabaseMode.BIBTEX);
BibEntry entry = new BibEntry(customizedType);
database.insertEntry(entry);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.jabref.model;
package org.jabref.model.entry;

import java.util.Collections;
import java.util.Optional;
import java.util.TreeSet;
import java.util.stream.Stream;

import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.BibField;
import org.jabref.model.entry.field.FieldPriority;
import org.jabref.model.entry.field.StandardField;
Expand All @@ -25,8 +23,9 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class BibEntryTypeFactoryTest {
class BibEntryTypesManagerTest {

private static final EntryType UNKNOWN_TYPE = new UnknownEntryType("unknownType");
private static final EntryType CUSTOM_TYPE = new UnknownEntryType("customType");
Expand All @@ -51,6 +50,13 @@ void setUp() {
entryTypesManager = new BibEntryTypesManager();
}

@ParameterizedTest
@MethodSource("mode")
void isCustomOrModifiedTypeReturnsTrueForModifiedStandardEntryType(BibDatabaseMode mode) {
entryTypesManager.addCustomOrModifiedType(overwrittenStandardType, mode);
assertTrue(entryTypesManager.isCustomOrModifiedType(overwrittenStandardType, mode));
}

@Test
void allTypesBibtexAreCorrect() {
TreeSet<BibEntryType> defaultTypes = new TreeSet<>(BibtexEntryTypeDefinitions.ALL);
Expand All @@ -75,53 +81,53 @@ void unknownTypeIsNotFound(BibDatabaseMode mode) {
@ParameterizedTest
@MethodSource("mode")
void newCustomEntryTypeFound(BibDatabaseMode mode) {
entryTypesManager.addCustomizedEntryType(newCustomType, mode);
entryTypesManager.addCustomOrModifiedType(newCustomType, mode);
assertEquals(Optional.of(newCustomType), entryTypesManager.enrich(CUSTOM_TYPE, mode));
}

@ParameterizedTest
@MethodSource("mode")
void registeredBibEntryTypeIsContainedInListOfCustomizedEntryTypes(BibDatabaseMode mode) {
entryTypesManager.addCustomizedEntryType(newCustomType, mode);
entryTypesManager.addCustomOrModifiedType(newCustomType, mode);
assertEquals(Collections.singletonList(newCustomType), entryTypesManager.getAllCustomTypes(mode));
}

@Test
void registerBibEntryTypeDoesNotAffectOtherMode() {
entryTypesManager.addCustomizedEntryType(newCustomType, BibDatabaseMode.BIBTEX);
entryTypesManager.addCustomOrModifiedType(newCustomType, BibDatabaseMode.BIBTEX);
assertFalse(entryTypesManager.getAllTypes(BibDatabaseMode.BIBLATEX).contains(newCustomType));
}

@ParameterizedTest
@MethodSource("mode")
void overwriteBibEntryTypeFields(BibDatabaseMode mode) {
entryTypesManager.addCustomizedEntryType(newCustomType, mode);
entryTypesManager.addCustomOrModifiedType(newCustomType, mode);
BibEntryType newBibEntryTypeTitle = new BibEntryType(
CUSTOM_TYPE,
Collections.singleton(new BibField(StandardField.TITLE, FieldPriority.IMPORTANT)),
Collections.emptySet());
entryTypesManager.addCustomizedEntryType(newBibEntryTypeTitle, mode);
entryTypesManager.addCustomOrModifiedType(newBibEntryTypeTitle, mode);
assertEquals(Optional.of(newBibEntryTypeTitle), entryTypesManager.enrich(CUSTOM_TYPE, mode));
}

@ParameterizedTest
@MethodSource("mode")
void overwriteStandardTypeRequiredFields(BibDatabaseMode mode) {
entryTypesManager.addCustomizedEntryType(overwrittenStandardType, mode);
entryTypesManager.addCustomOrModifiedType(overwrittenStandardType, mode);
assertEquals(Optional.of(overwrittenStandardType), entryTypesManager.enrich(overwrittenStandardType.getType(), mode));
}

@ParameterizedTest
@MethodSource("mode")
void registeredCustomizedStandardEntryTypeIsNotContainedInListOfCustomEntryTypes(BibDatabaseMode mode) {
entryTypesManager.addCustomizedEntryType(overwrittenStandardType, mode);
entryTypesManager.addCustomOrModifiedType(overwrittenStandardType, mode);
assertEquals(Collections.emptyList(), entryTypesManager.getAllCustomTypes(mode));
}

@ParameterizedTest
@MethodSource("mode")
void standardTypeIsStillAccessibleIfOverwritten(BibDatabaseMode mode) {
entryTypesManager.addCustomizedEntryType(overwrittenStandardType, mode);
entryTypesManager.addCustomOrModifiedType(overwrittenStandardType, mode);
assertFalse(entryTypesManager.isCustomType(overwrittenStandardType.getType(), mode));
}
}

0 comments on commit f14b12b

Please sign in to comment.