Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to allow for integers in field "edition" when running database in bibtex mode #5104

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We moved the dropdown menu for selecting the push-application from the toolbar into the external application preferences. [#674](https://github.com/JabRef/jabref/issues/674)
- We removed the alphabetical ordering of the custom tabs and updated the error message when trying to create a general field with a name containing an illegal character. [#5019](https://github.com/JabRef/jabref/issues/5019)
- We added a context menu to the bib(la)tex-source-editor to copy'n'paste. [#5007](https://github.com/JabRef/jabref/pull/5007)
- We added a option to allow integer field in edition during check integrity even in Bibtex Mode. [#4680](https://github.com/JabRef/jabref/issues/4680)


### Fixed
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/gui/preferences/GeneralTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class GeneralTab extends Pane implements PrefsTab {
private final CheckBox useTimeStamp;
private final CheckBox updateTimeStamp;
private final CheckBox overwriteTimeStamp;
private final CheckBox allowEditionInteger;
private final TextField defOwnerField;
private final GridPane builder = new GridPane();

Expand Down Expand Up @@ -80,6 +81,7 @@ public GeneralTab(DialogService dialogService, JabRefPreferences prefs) {
inspectionWarnDupli = new CheckBox(Localization.lang("Warn about unresolved duplicates when closing inspection window"));
showAdvancedHints = new CheckBox(Localization.lang("Show advanced hints (i.e. helpful tooltips, suggestions and explanation)"));
shouldCollectTelemetry = new CheckBox(Localization.lang("Collect and share telemetry data to help improve JabRef."));
allowEditionInteger = new CheckBox(Localization.lang("Allow edition field Integer when in Bibtex mode"));
encodings = new ComboBox<>(FXCollections.observableArrayList(Encodings.ENCODINGS));

Label general = new Label(Localization.lang("General"));
Expand Down Expand Up @@ -139,6 +141,7 @@ public GeneralTab(DialogService dialogService, JabRefPreferences prefs) {
builder.add(biblioBox, 1, 29);

builder.add(showAdvancedHints,1,30);
builder.add(allowEditionInteger,1,31);
}

@Override
Expand Down Expand Up @@ -169,6 +172,7 @@ public void setValues() {
encodings.setValue(prefs.getDefaultEncoding());
languageSelection.setValue(prefs.getLanguage());
showAdvancedHints.setSelected(prefs.getBoolean(JabRefPreferences.SHOW_ADVANCED_HINTS));
allowEditionInteger.setSelected(prefs.getBoolean(JabRefPreferences.ALLOW_EDITION_INTEGER));
}

@Override
Expand All @@ -187,6 +191,7 @@ public void storeSettings() {
}
prefs.putBoolean(JabRefPreferences.MEMORY_STICK_MODE, memoryStick.isSelected());
prefs.putBoolean(JabRefPreferences.SHOW_ADVANCED_HINTS, showAdvancedHints.isSelected());
prefs.putBoolean(JabRefPreferences.ALLOW_EDITION_INTEGER, allowEditionInteger.isSelected());
prefs.putBoolean(JabRefPreferences.CONFIRM_DELETE, confirmDelete.isSelected());
prefs.putBoolean(JabRefPreferences.WARN_ABOUT_DUPLICATES_IN_INSPECTION, inspectionWarnDupli.isSelected());
String owner = defOwnerField.getText().trim();
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/org/jabref/logic/integrity/EditionChecker.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
package org.jabref.logic.integrity;

import org.apache.commons.lang3.StringUtils;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.strings.StringUtil;
import org.jabref.preferences.JabRefPreferences;

import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.regex.Pattern;

import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.strings.StringUtil;

public class EditionChecker implements ValueChecker {


private static final Predicate<String> FIRST_LETTER_CAPITALIZED = Pattern.compile("^[A-Z]").asPredicate();
private static final Predicate<String> ONLY_NUMERALS_OR_LITERALS = Pattern.compile("^([0-9]+|[^0-9].+)$")
.asPredicate();
private static final String FIRST_EDITION = "1";

private final BibDatabaseContext bibDatabaseContextEdition;

private final JabRefPreferences prefs = JabRefPreferences.getInstance();


public EditionChecker(BibDatabaseContext bibDatabaseContext) {
this.bibDatabaseContextEdition = Objects.requireNonNull(bibDatabaseContext);
Expand Down Expand Up @@ -49,8 +55,16 @@ public Optional<String> checkValue(String value) {
}

//BibTeX
if (!bibDatabaseContextEdition.isBiblatexMode() && !FIRST_LETTER_CAPITALIZED.test(value.trim())) {
return Optional.of(Localization.lang("should have the first letter capitalized"));
if (!bibDatabaseContextEdition.isBiblatexMode()) {
if(StringUtils.isNumeric(value.trim())){
if(!prefs.getBoolean(JabRefPreferences.ALLOW_EDITION_INTEGER)){
return Optional.of(Localization.lang("should be a String but received a Integer"));
}
}else{
if(!FIRST_LETTER_CAPITALIZED.test(value.trim())){
return Optional.of(Localization.lang("should have the first letter capitalized"));
}
}
}

return Optional.empty();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ public class JabRefPreferences implements PreferencesService {
public static final String WEB_SEARCH_VISIBLE = "webSearchVisible";
public static final String GROUP_SIDEPANE_VISIBLE = "groupSidepaneVisible";
public static final String ALLOW_FILE_AUTO_OPEN_BROWSE = "allowFileAutoOpenBrowse";
public static final String ALLOW_EDITION_INTEGER = "allowEditionInteger";
public static final String CUSTOM_TAB_NAME = "customTabName_";
public static final String CUSTOM_TAB_FIELDS = "customTabFields_";
public static final String USE_UNIT_FORMATTER_ON_SEARCH = "useUnitFormatterOnSearch";
Expand Down Expand Up @@ -704,6 +705,7 @@ private JabRefPreferences() {
defaults.put(EMAIL_SUBJECT, Localization.lang("References"));
defaults.put(OPEN_FOLDERS_OF_ATTACHED_FILES, Boolean.FALSE);
defaults.put(ALLOW_FILE_AUTO_OPEN_BROWSE, Boolean.TRUE);
defaults.put(ALLOW_EDITION_INTEGER, Boolean.FALSE);
defaults.put(WEB_SEARCH_VISIBLE, Boolean.TRUE);
defaults.put(GROUP_SIDEPANE_VISIBLE, Boolean.TRUE);
defaults.put(SELECTED_FETCHER_INDEX, 0);
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2093,3 +2093,6 @@ Import\ BibTeX=Import BibTeX
Import\ preferences\ from\ a\ file=Import preferences from a file
Matching=Matching
Same\ as\ --import,\ but\ will\ be\ imported\ to\ the\ opened\ tab=Same as --import, but will be imported to the opened tab

Allow\ edition\ field\ Integer\ when\ in\ Bibtex\ mode=Allow edition field Integer when in Bibtex mode
should\ be\ a\ String\ but\ received\ a\ Integer=should be a String but received a Integer
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jabref.model.entry.InternalBibtexFields;
import org.jabref.model.metadata.FilePreferences;
import org.jabref.model.metadata.MetaData;
import org.jabref.preferences.JabRefPreferences;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -33,6 +34,8 @@

class IntegrityCheckTest {

private final JabRefPreferences prefs = JabRefPreferences.getInstance();

@Test
void testEntryTypeChecks() {
assertCorrect(withMode(createContext("title", "sometitle", "article"), BibDatabaseMode.BIBTEX));
Expand Down Expand Up @@ -73,10 +76,14 @@ void testYearChecks() {

@Test
void testEditionChecks() {
Boolean defaultPref = prefs.getBoolean(prefs.ALLOW_EDITION_INTEGER);
assertCorrect(withMode(createContext("edition", "Second"), BibDatabaseMode.BIBTEX));
assertCorrect(withMode(createContext("edition", "Third"), BibDatabaseMode.BIBTEX));
assertWrong(withMode(createContext("edition", "second"), BibDatabaseMode.BIBTEX));
prefs.putBoolean(prefs.ALLOW_EDITION_INTEGER, false);
assertWrong(withMode(createContext("edition", "2"), BibDatabaseMode.BIBTEX));
prefs.putBoolean(prefs.ALLOW_EDITION_INTEGER, true);
assertCorrect(withMode(createContext("edition", "2"), BibDatabaseMode.BIBTEX));
assertWrong(withMode(createContext("edition", "2nd"), BibDatabaseMode.BIBTEX));
assertCorrect(withMode(createContext("edition", "2"), BibDatabaseMode.BIBLATEX));
assertCorrect(withMode(createContext("edition", "10"), BibDatabaseMode.BIBLATEX));
Expand All @@ -85,6 +92,7 @@ void testEditionChecks() {
assertCorrect(withMode(createContext("edition", "Edition 2000"), BibDatabaseMode.BIBLATEX));
assertWrong(withMode(createContext("edition", "2nd"), BibDatabaseMode.BIBLATEX));
assertWrong(createContext("edition", "1"));
prefs.putBoolean(prefs.ALLOW_EDITION_INTEGER, defaultPref);
}

@Test
Expand Down