Skip to content

Add quality checker for journal abbrevs #13190

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

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
49b85b1
Create JournalAbbreviationValidator & check for wrong escape characters
aaspst May 9, 2025
a133c31
Check for non-UTF8 characters
aaspst May 9, 2025
ec293db
Add check for same letter starting
aaspst May 20, 2025
1f00b0f
Check if abbreviation is same as full text
aaspst May 20, 2025
3304609
Add Manag. validation check
aaspst May 27, 2025
8472ef9
Add check for duplicate full names with different abbrev
aaspst May 27, 2025
4a67907
Add check for duplicate abbreviations with different full names
aaspst May 27, 2025
f8e7550
Implement journal entry validation logic
aaspst May 28, 2025
2b8c6b2
Add issue retrieval method
aaspst May 28, 2025
366e776
Initialize JournalAbbreviationValidatorTest class
aaspst May 28, 2025
664d96e
Add escape test cases
aaspst May 28, 2025
a45c1a6
Add UTF-8 test cases
aaspst May 28, 2025
0458158
Add starting letters test cases
aaspst May 28, 2025
67c8a7a
Add AbbreviationEqualsFullText test cases
aaspst May 28, 2025
2d5e36b
Add outdated manag. test cases
aaspst May 28, 2025
6eac2af
Add duplicate test cases
aaspst May 28, 2025
6c71f5d
Add more escape test cases
aaspst May 28, 2025
5846c14
Add non UTF-8 test cases
aaspst May 28, 2025
a67e487
Add starting letters test cases
aaspst May 30, 2025
be0e86a
Add empty inputs & whitespaces only test cases
aaspst May 30, 2025
22e6eac
Add more duplicate check test cases
aaspst May 30, 2025
ec45ee8
Add AbbreviationEqualsFullTextWithSpecialCharacters test case
aaspst May 30, 2025
089b804
Add outdated variations test cases
aaspst May 30, 2025
36691c5
Add long input test case
aaspst May 30, 2025
a2cf0c0
Add all checks validation test case
aaspst May 30, 2025
163cef4
Modify validation methods to return Optional<ValidationResult> instea…
aaspst Jun 2, 2025
3718776
Update test cases to handle the Optional<ValidationResult> returns
aaspst Jun 2, 2025
488ac8c
Add getissues() and Optional.empty() to validation methods
aaspst Jun 2, 2025
76392ec
Add runtime validation and connect validator with JabKit
aaspst Jun 3, 2025
0bda42e
Add real time validation in GUI
aaspst Jun 3, 2025
b5b20a2
Localize message using Localization.lang
aaspst Jun 3, 2025
8f1f017
Modify getValidateJournals to use java.util.Optional
aaspst Jun 3, 2025
3c285e7
Resolve Checkstyle errors
aaspst Jun 4, 2025
e33db01
Move validator back to original location
aaspst Jun 4, 2025
9ddd8c4
Change assertFalse and assertTrue to assertEquals
aaspst Jun 5, 2025
d17edd3
Merge branch 'JabRef:main' into fix-for-issue-149
aaspst Jun 6, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
import jakarta.inject.Inject;
import org.controlsfx.control.textfield.CustomTextField;

import java.util.List;
import java.util.stream.Collectors;

/**
* This class controls the user interface of the journal abbreviations dialog. The UI elements and their layout are
* defined in the FXML file.
Expand All @@ -59,6 +62,7 @@ public class JournalAbbreviationsTab extends AbstractPreferenceTabView<JournalAb

@FXML private CustomTextField searchBox;
@FXML private CheckBox useFJournal;
@FXML private CheckBox validateAbbreviations;

@Inject private TaskExecutor taskExecutor;
@Inject private JournalAbbreviationRepository abbreviationRepository;
Expand Down Expand Up @@ -87,17 +91,61 @@ private void initialize() {

searchBox.setPromptText(Localization.lang("Search..."));
searchBox.setLeft(IconTheme.JabRefIcons.SEARCH.getGraphicNode());

validateAbbreviations.selectedProperty().bindBidirectional(viewModel.validateAbbreviationsProperty());
}

private void setUpTable() {
journalTableNameColumn.setCellValueFactory(cellData -> cellData.getValue().nameProperty());
journalTableNameColumn.setCellFactory(TextFieldTableCell.forTableColumn());
journalTableNameColumn.setOnEditCommit(event -> {
if (viewModel.validateAbbreviationsProperty().get()) {
AbbreviationViewModel item = event.getRowValue();
String newValue = event.getNewValue();
List<ValidationResult> results = viewModel.validateAbbreviation(item.getName(), newValue, item.getAbbreviation());
if (!results.isEmpty()) {
event.consume();
dialogService.showErrorDialogAndWait(Localization.lang("Validation Error"),
results.stream()
.map(ValidationResult::getMessage)
.collect(Collectors.joining("\n")));
}
}
});

journalTableAbbreviationColumn.setCellValueFactory(cellData -> cellData.getValue().abbreviationProperty());
journalTableAbbreviationColumn.setCellFactory(TextFieldTableCell.forTableColumn());
journalTableAbbreviationColumn.setOnEditCommit(event -> {
if (viewModel.validateAbbreviationsProperty().get()) {
AbbreviationViewModel item = event.getRowValue();
String newValue = event.getNewValue();
List<ValidationResult> results = viewModel.validateAbbreviation(item.getName(), item.getAbbreviation(), newValue);
if (!results.isEmpty()) {
event.consume();
dialogService.showErrorDialogAndWait(Localization.lang("Validation Error"),
results.stream()
.map(ValidationResult::getMessage)
.collect(Collectors.joining("\n")));
}
}
});

journalTableShortestUniqueAbbreviationColumn.setCellValueFactory(cellData -> cellData.getValue().shortestUniqueAbbreviationProperty());
journalTableShortestUniqueAbbreviationColumn.setCellFactory(TextFieldTableCell.forTableColumn());
journalTableShortestUniqueAbbreviationColumn.setOnEditCommit(event -> {
if (viewModel.validateAbbreviationsProperty().get()) {
AbbreviationViewModel item = event.getRowValue();
String newValue = event.getNewValue();
List<ValidationResult> results = viewModel.validateAbbreviation(item.getName(), item.getAbbreviation(), newValue);
if (!results.isEmpty()) {
event.consume();
dialogService.showErrorDialogAndWait(Localization.lang("Validation Error"),
results.stream()
.map(ValidationResult::getMessage)
.collect(Collectors.joining("\n")));
}
}
});

actionsColumn.setCellValueFactory(cellData -> cellData.getValue().nameProperty());
new ValueTableCellFactory<AbbreviationViewModel, String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class JournalAbbreviationsTabViewModel implements PreferenceTabViewModel
private final SimpleBooleanProperty isEditableAndRemovable = new SimpleBooleanProperty(false);
private final SimpleBooleanProperty isAbbreviationEditableAndRemovable = new SimpleBooleanProperty(false);
private final SimpleBooleanProperty useFJournal = new SimpleBooleanProperty(true);
private final SimpleBooleanProperty validateAbbreviations = new SimpleBooleanProperty(true);

private final DialogService dialogService;
private final TaskExecutor taskExecutor;
Expand All @@ -66,6 +67,9 @@ public JournalAbbreviationsTabViewModel(JournalAbbreviationPreferences abbreviat
this.journalAbbreviationRepository = Objects.requireNonNull(journalAbbreviationRepository);
this.abbreviationsPreferences = abbreviationsPreferences;

useFJournal.setValue(abbreviationsPreferences.shouldUseFJournalField());
validateAbbreviations.setValue(abbreviationsPreferences.shouldValidateAbbreviations());

abbreviationsCount.bind(abbreviations.sizeProperty());
currentAbbreviation.addListener((observable, oldValue, newValue) -> {
boolean isAbbreviation = (newValue != null) && !newValue.isPseudoAbbreviation();
Expand Down Expand Up @@ -103,6 +107,10 @@ public JournalAbbreviationsTabViewModel(JournalAbbreviationPreferences abbreviat
}
}
});

// Bind preferences
useFJournal.addListener((obs, oldValue, newValue) -> abbreviationsPreferences.setUseFJournalField(newValue));
validateAbbreviations.addListener((obs, oldValue, newValue) -> abbreviationsPreferences.setValidateAbbreviations(newValue));
}

@Override
Expand Down Expand Up @@ -387,4 +395,17 @@ public SimpleBooleanProperty isFileRemovableProperty() {
public SimpleBooleanProperty useFJournalProperty() {
return useFJournal;
}

public BooleanProperty validateAbbreviationsProperty() {
return validateAbbreviations;
}

public void setValidateAbbreviations(boolean validateAbbreviations) {
this.validateAbbreviations.set(validateAbbreviations);
}

public List<ValidationResult> validateAbbreviation(String name, String abbreviation, String shortestUniqueAbbreviation) {
Abbreviation abbreviationObject = new Abbreviation(name, abbreviation, shortestUniqueAbbreviation);
return journalAbbreviationRepository.getValidationIssues();
}
}
Loading
Loading