Skip to content

Fix when fetching from DOI: Dialog selects field data based on validity #12826

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

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
36a2e42
ella's fix - see end of change implementation doc
ellapalter Mar 24, 2025
b2018c5
added logic for if years differ by more than 10
ellapalter Mar 25, 2025
cdb51a8
Made consistency changes before PR
Mar 25, 2025
c37c4f9
Added update to the changelog.md file under the fixed category
Mar 25, 2025
9342eb8
Fixed all the gradle checkstyle problems
Mar 25, 2025
75e28e7
Changed leftYear comparison from '>2100' to +100 years from current y…
Mar 26, 2025
b22e1f9
Corrected Style
Mar 26, 2025
96e4d1e
Corrected Style
Mar 26, 2025
7bb2e3f
Added JavaDoc documentation for two methods
Mar 26, 2025
56ab176
Changed magic numbers and String to constants
Mar 26, 2025
fa3dfd8
Changed magic numbers and String to constants
Mar 26, 2025
a0f7e9f
Changed magic numbers and String to constants
Mar 26, 2025
ba16c49
Style correction
Mar 26, 2025
4aadea9
Update src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java
xts2002 Mar 29, 2025
52cf5cb
Moved Logic from FieldRowView.java to FieldRowViewModel.java
Mar 30, 2025
4b515fb
Merge branch 'main' into Tim_test
xts2002 Mar 30, 2025
c1b48bc
Merge pull request #1 from Menoa11/Tim_test
xts2002 Mar 30, 2025
27741ad
Checkstyle change
Mar 30, 2025
957ba76
Checkstyle change
Mar 30, 2025
1be86a0
OpenRewrite Change
Mar 30, 2025
16ab73f
Added Tests in FieldRowViewModelTest.java
Mar 30, 2025
0a9991c
Added Tests in FieldRowViewModelTest.java
Mar 30, 2025
0b67633
CheckStyle Change
Mar 30, 2025
2c9238c
Method autoSelectBetterValue now use ```Field``` to check whether the…
Apr 2, 2025
65e4d0e
OpenRewrite Run
Apr 2, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Fixed

- We fixed an issue where when fetching from DOI, dialog selects field data based on validity. [#12549](https://github.com/JabRef/jabref/issues/12549)
- We fixed an issue where the F4 shortcut key did not work without opening the right-click context menu. [#6101](https://github.com/JabRef/jabref/pull/6101)
- We fixed an issue where the file renaming dialog was not resizable and its size was too small for long file names. [#12518](https://github.com/JabRef/jabref/pull/12518)
- We fixed an issue where the name of the untitled database was shown as a blank space in the right-click context menu's "Copy to" option. [#12459](https://github.com/JabRef/jabref/pull/12459)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jabref.logic.importer.ImportCleanup;
import org.jabref.logic.importer.WebFetcher;
import org.jabref.logic.importer.WebFetchers;
import org.jabref.logic.importer.fetcher.DoiFetcher;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.BackgroundTask;
import org.jabref.logic.util.TaskExecutor;
Expand Down Expand Up @@ -110,6 +111,9 @@ private void showMergeDialog(BibEntry originalEntry, BibEntry fetchedEntry, WebF
dialog.setTitle(Localization.lang("Merge entry with %0 information", fetcher.getName()));
dialog.setLeftHeaderText(Localization.lang("Original entry"));
dialog.setRightHeaderText(Localization.lang("Entry from %0", fetcher.getName()));
if (fetcher instanceof DoiFetcher) {
dialog.autoSelectBetterFields();
}
Optional<BibEntry> mergedEntry = dialogService.showCustomDialogAndWait(dialog).map(EntriesMergeResult::mergedEntry);

if (mergedEntry.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ public void setRightHeaderText(String rightHeaderText) {
public void configureDiff(ShowDiffConfig diffConfig) {
threeWayMergeView.showDiff(diffConfig);
}

public void autoSelectBetterFields() {
threeWayMergeView.autoSelectBetterFields();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
*/
public class FieldRowView {
private static final Logger LOGGER = LoggerFactory.getLogger(FieldRowView.class);
private static final int YEAR_LOWER = 1800;
private static final int YEAR_DIF = 10;
private static final int YEAR_UPPER_DIF = 100;
private static final String MISC = "misc";

protected final FieldRowViewModel viewModel;

Expand Down Expand Up @@ -212,4 +216,8 @@ public boolean hasEqualLeftAndRightValues() {
public String toString() {
return "FieldRowView [shouldShowDiffs=" + shouldShowDiffs.get() + ", fieldNameCell=" + fieldNameCell + ", leftValueCell=" + leftValueCell + ", rightValueCell=" + rightValueCell + ", mergedValueCell=" + mergedValueCell + "]";
}

public void autoSelectBetterValue_1() {
viewModel.autoSelectBetterValue();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.gui.mergeentries.newmergedialog;

import java.time.Year;

import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;
Expand Down Expand Up @@ -37,6 +39,10 @@ public enum Selection {
NONE
}

private static final int YEAR_LOWER = 1800;
private static final int YEAR_DIF = 10;
private static final int YEAR_UPPER_DIF = 100;
private static final String MISC = "misc";
private final Logger LOGGER = LoggerFactory.getLogger(FieldRowViewModel.class);
private final BooleanProperty isFieldsMerged = new SimpleBooleanProperty(Boolean.FALSE);

Expand Down Expand Up @@ -282,4 +288,49 @@ public void redo() throws CannotRedoException {
setRightFieldValue(mergedFields);
}
}

/**
* Method for selecting the 'Better' year value.
* If the local year is out of a reasonable range (e.g., before 1800 or 100 years after current year as determined by the System Clock) or differs from the DOI year by more than 10 years, it will choose the more recent year out of the two.
*/
public void autoSelectBetterValue() {
String field_1 = getField().getDisplayName();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad variable name - please be consistent with others

if (field_1 == null) {
return;
}
field_1 = field_1.trim().toLowerCase();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this? When can dispalyname be null? Why toLowerCase? - we also have .getName - not sure what this code aims vor.


String leftVal = getLeftFieldValue();
String rightVal = getRightFieldValue();
if (leftVal == null || rightVal == null) {
return;
}
leftVal = leftVal.trim();
rightVal = rightVal.trim();

// Logic for auto selection based on field name
// Default is right value
if ("year".equals(field_1)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use standard fiels - as I dold you in the last review

try {
int leftYear = Integer.parseInt(leftVal);
int rightYear = Integer.parseInt(rightVal);
if (leftYear < YEAR_LOWER || leftYear > (Year.now().getValue() + YEAR_UPPER_DIF)) {
selectRightValue(); // Select right value if left year is out of range, note that work created before Year 1800 will still be correctly processed
} else if (Math.abs(leftYear - rightYear) > YEAR_DIF) {
// Select value based on a difference condition
if (leftYear > rightYear) {
selectLeftValue();
} else {
selectRightValue();
}
}
} catch (NumberFormatException e) {
selectRightValue();
}
} else if ("type".equals(field_1)) {
if (MISC.equalsIgnoreCase(leftVal)) {
selectRightValue(); // Select right value if left value is "misc"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,14 @@ public BibEntry getRightEntry() {
public void saveConfiguration() {
toolbar.saveToolbarConfiguration();
}

/**
* Directs to the method autoSelectBetterValue() in FieldRowViewModel.java
* Select 'Better' values for each field row in the Entry
*/
public void autoSelectBetterFields() {
for (FieldRowView row : fieldRows) {
row.autoSelectBetterValue_1();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ void hasEqualLeftAndRightValuesShouldReturnTrueIfKeywordsAreEqual() {
void selectLeftValueShouldBeCorrect() {
var monthFieldViewModel = createViewModelForField(StandardField.MONTH);
monthFieldViewModel.selectLeftValue();

assertEquals(FieldRowViewModel.Selection.LEFT, monthFieldViewModel.getSelection());
assertEquals(Optional.of(""), Optional.ofNullable(monthFieldViewModel.getMergedFieldValue()));

Expand Down