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

Conversation

Menoa11
Copy link

@Menoa11 Menoa11 commented Mar 25, 2025

Closes #12549

This PR enhances the Merge Entries Dialog by improving the automatic selection of bibliographic fields when merging entries from a DOI with manual entries. Previously, the dialog always prioritized data from the mannual entry, even when the mannual entry contained clearly incorrect information. Now, when merging from a DOI, the system automatically selects the more reliable fields for:

Year: If the local year is out of a reasonable range (e.g., before 1800 or after 2100) or differs from the DOI year by more than 10 years it will choose the more recent year out of the two.

Entry Type: If the local entry type is "misc," it defaults to the type provided by the DOI.

Code Changes:

  • FetchAndMergeEntry.java: Calls autoSelectBetterFields() when merging from a DOI.
  • MergeEntriesDialog.java: Introduces autoSelectBetterFields() method.
  • ThreeWayMergeView.java: Iterates through all fields and invokes autoSelectBetterValue().
  • FieldRowView.java: Implements autoSelectBetterValue() to apply selection rules for "year" and "entry type."

How It Works:

  • If merging from a DOI, the dialog automatically evaluates the "year" and "entry type" fields.
  • If the local year is out of a reasonable range or differs by more than 10 years, the DOI-provided year is selected.
  • If the local entry type is "misc," the DOI-provided type is selected.

Testing:

  • Manually tested with multiple entries containing incorrect years and entry types. Verified that other fields remain unchanged unless manually adjusted.
  • Tests have also now been added to src/test/java/org/jabref/gui/mergeentries/FieldRowViewModelTest.java to verify the changes that were made.

Visuals of change effects:

Before change:
image

After change:
image

After change:
image

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (if change is visible to the user)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

@Menoa11
Copy link
Author

Menoa11 commented Mar 26, 2025

@ThiloteE please let us know if the changes are good.

@Menoa11
Copy link
Author

Menoa11 commented Mar 27, 2025

@koppor Please let us know what you think.

@koppor koppor added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Mar 27, 2025
@koppor koppor removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Mar 28, 2025
@koppor
Copy link
Member

koppor commented Mar 28, 2025

Move logic to org.jabref.gui.mergeentries.newmergedialog.FieldRowViewModel and add tests to org.jabref.gui.mergeentries.FieldRowViewModelTest

@koppor koppor marked this pull request as draft March 28, 2025 07:04
@xts2002
Copy link

xts2002 commented Mar 30, 2025

@koppor Hi I have implemented the changes you requested, please let us know if you need any more changes.

@Menoa11
Copy link
Author

Menoa11 commented Mar 31, 2025

Thank you for all the feedback! I just want to mention that we have a deadline to merge the PR which is April 4, @koppor @ThiloteE so we would really appreciate an approval before then.

* 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

Comment on lines 298 to 301
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.


// 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

@koppor
Copy link
Member

koppor commented Mar 31, 2025

@koppor Hi I have implemented the changes you requested, please let us know if you need any more changes.

No, you did not. I am pretty sure, I told you to use JabRefs fields instead of strings

@koppor
Copy link
Member

koppor commented Mar 31, 2025

Thank you for all the feedback! I just want to mention that we have a deadline to merge the PR which is April 4, @koppor @ThiloteE so we would really appreciate an approval before then.

This informaion is new to us. You needed 20 days to come up with a pull request.

You did address my previous review comments properly.

The good thing is that you reacted fast on my review replies.

Maybe, we can manage that your PR will be ready to be merged. Currently, I think, it will need two more rounds.

Copy link

trag-bot bot commented Apr 2, 2025

@trag-bot didn't find any issues in the code! ✅✨

@xts2002
Copy link

xts2002 commented Apr 2, 2025

@koppor Sorry about that. Now the method autoSelectBetterValue uses Field to check the type of the entry. Are there any more places that should be changed?

@jabref-machine
Copy link
Collaborator

You committed your code on the main brach of your fork. This is a bad practice. The right way is to branch out from main, work on your patch/feature in that new branch, and then get that branch merged via the pull request (see GitHub flow).
For this pull request, this is OK. For subsequent pull requests, please start with a different branch with a proper branch name. See CONTRIBUTING.md for more details.

@koppor
Copy link
Member

koppor commented Apr 2, 2025

@koppor Sorry about that. Now the method autoSelectBetterValue uses Field to check the type of the entry. Are there any more places that should be changed?

Yes.

Please take this as excersie to level-up your tooling and coding skills. To get better than competitors.

Please scroll through your diff https://github.com/JabRef/jabref/pull/12826/files

grafik


I think, you did not understand what I meant to use Field instead of String.

--

For the purpose of getting the task done, this is solved. But I cannot merge since it does not meet our expectations of code quality. -- It is even hard for AI to work with non-good code, thus we try to have good code.

I think, nearly all of your lines have to be changed.

@koppor
Copy link
Member

koppor commented Apr 2, 2025

@koppor Sorry about that. Now the method autoSelectBetterValue uses Field to check the type of the entry. Are there any more places that should be changed?

@xts2002 Please read my 5 day old comment: #12826 (comment). The logic is not yet moved to there. Now you use Strings. If the logic is there, you can use higher-level data structures.

@koppor
Copy link
Member

koppor commented Apr 2, 2025

More information on MVVM can be found at https://github.com/JabRef/jabref/wiki/Code---JavaFX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When fetching from DOI: Dialog should select field data based on validity
6 participants