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

Added default journal abbreviation setting #12105

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MattBryantt
Copy link

Changes Made

Added a UI option in the Web Search tab of preferences to allow journals to be automatically abbreviated when fetching from the web.

Screenshot 2024-10-27 at 16 28 33

org.jabref.logic.importer.ParserFetcher#doPostCleanup implements the newly added AbbreviateJournalCleanup task by default, which itself uses the UndoableAbbreviator. Overriding implementations of ParserFetcher#doPostCleanup were also changed to add the cleanup job.

Current Issues

The AbbreviateJournalCleanup uses a deprecated method JabRefGuiPreferences.getInstance() to obtain ImporterPreferences. However, this implementation was done to avoid changing the constructor arguments for each fetcher (e.g. CrossRef() → CrossRef(ImporterPreferences importerPreferences). One possible alternative is adding ImporterPreferences to ImportFormatPreferences, as this is already passed to many fetchers. However, this does not apply to all, and would seemingly require changes to a large amount of method signatures (i.e. functions that call fetchers, as in new CrossRef(). Suggestions for an improved implementation are welcome.

Changes will also likely need to merged with the refactoring of UndoableAbbreviator, outlined in #12101 and #11791.

Other Notes

Tests will need to be created upon implementation methods being approved.

Due to being a draft pull request, note that CHANGELOG.md and relevant documentation has not yet been modified. Will be completed upon approval.

Closes #11305

Mandatory checks

  • I own the copyright of the code submitted and I licence 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 (for UI changes)
  • 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.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

JUnit tests are failing. In the area "Some checks were not successful", locate "Tests / Unit tests (pull_request)" and click on "Details". This brings you to the test output.

You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide.

Comment on lines +49 to +50
if (entry.hasField(StandardField.JOURNALTITLE)) {
String oldJournalTitle = entry.getField(StandardField.JOURNALTITLE).orElse(null);
Copy link
Member

Choose a reason for hiding this comment

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

Try to use ...ifPresent(content -> {...}.

The .orElse(null) is a no-go. - Also just .get() directly after the hasField is an indication for

entry.getField(StandardField.JOURNALTITLE).ifPresent(content -> {
...
}

Copy link
Member

Choose a reason for hiding this comment

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

I think, you should use the latexFree variant (org.jabref.model.entry.BibEntry#getFieldLatexFree).

Store the two fields in a List and iterate through the list - to have no code duplilcation of the handling part.


UndoableAbbreviator undoableAbbreviator = new UndoableAbbreviator(repository, AbbreviationType.DEFAULT, false);

// Abbreviate journal and journaltitle fields
Copy link
Member

Choose a reason for hiding this comment

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

No need for that comment - the code saxs it.

public List<FieldChange> cleanup(BibEntry entry) {
List<FieldChange> changes = new ArrayList<>();

// Skip if preferences is disabled
Copy link
Member

Choose a reason for hiding this comment

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

Stands for itself. remove comemt.

// Skip if preferences is disabled
boolean shouldAutoAbbreviateJournals = JabRefGuiPreferences.getInstance().getImporterPreferences().shouldAutoAbbreviateJournals();
if (!shouldAutoAbbreviateJournals) {
return changes;
Copy link
Member

Choose a reason for hiding this comment

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

Return List.of() and initialize changes later.

Comment on lines +32 to +33
boolean shouldAutoAbbreviateJournals = JabRefGuiPreferences.getInstance().getImporterPreferences().shouldAutoAbbreviateJournals();
if (!shouldAutoAbbreviateJournals) {
Copy link
Member

Choose a reason for hiding this comment

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

Merge these two lines.

@koppor
Copy link
Member

koppor commented Oct 30, 2024

Tests will need to be created upon implementation methods being approved.

Please think about "test-driven development". If there are "only" implementation-style comments (as they currently are), the tests should not change. -- I know that test refactoring is hard on larger code changes; but at least you have test data available. This can be done regardless of the concrete implementation. Thus, always work on tests while implementing something.

@koppor koppor added the status: changes required Pull requests that are not yet complete label Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: changes required Pull requests that are not yet complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default journal abbreviation setting
2 participants