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

Store journal abbreviation lists in specified directory #12544

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

Conversation

adhamahmad
Copy link

@adhamahmad adhamahmad commented Feb 23, 2025

Closes #10557

UI changes:

image

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.

Your code currently does not meet JabRef's code guidelines. We use Checkstyle to identify issues. Please carefully follow the setup guide for the codestyle. Afterwards, please run checkstyle locally and fix the issues.
In case of issues with the import order, double check that you activated Auto Import. You can trigger fixing imports by pressing Ctrl+Alt+O to trigger Optimize Imports.

@adhamahmad adhamahmad marked this pull request as ready for review February 23, 2025 03:47
@adhamahmad adhamahmad marked this pull request as draft February 23, 2025 03:47
@ThiloteE ThiloteE changed the title Fix for issue 10557 Store journal abbreviation lists in specified directory Feb 24, 2025
@koppor
Copy link
Member

koppor commented Feb 26, 2025

Thank you for working on this.

TODO (Not implemented in this PR):

What does this mean?

Will there be follow-up PRs? Do you intent to work on this in the context of commits to this PR?

@adhamahmad
Copy link
Author

@koppor

I intend to include them as additional commits within this PR.

@koppor
Copy link
Member

koppor commented Feb 26, 2025

I intend to include them as additional commits within this PR.

Nice! 👍

@koppor
Copy link
Member

koppor commented Feb 27, 2025

* Implementation of .csv to .mv store conversion

Code hint: This is already implemented at org.jabref.cli.JournalListMvGenerator. One just needs to move that class to org.jabref.logic.journals and adapt it.

@koppor
Copy link
Member

koppor commented Feb 27, 2025

* Implement automatic detection of journal lists in the specified directory:

This could be easy.

  1. Have a HashMap (stored inMVStore) from filename to timestamp
  2. Files.walktree -> for each file: look up. if not found: import and put timestamp of file. If found: compare timestamp. If not equal: clear current hashmap for that. import and update time stamp

adhamahmad and others added 6 commits March 16, 2025 04:40
…version

- Automatically detect journal abbreviation lists in the specified directory
- Convert .csv files to .mv store format if the CSV timestamp is newer
- Maintain a HashMap in MVStore to track file timestamps and update accordingly
- Ensure JabRef always has a custom.csv available for user-defined abbreviations
- Improve journal abbreviation loading and preferences handling
@koppor
Copy link
Member

koppor commented Mar 16, 2025

@adhamahmad I think, the TODO list in the PR description should be updated if I read your last commit comment right?

@adhamahmad
Copy link
Author

@adhamahmad I think, the TODO list in the PR description should be updated if I read your last commit comment right?

You're right—the .csv to .mv conversion is now implemented. I updated the TODO list, the only missing part is the unit test.

@adhamahmad adhamahmad changed the title Store journal abbreviation lists in specified directory Closes #10557. Store journal abbreviation lists in specified directory Mar 17, 2025
@adhamahmad adhamahmad changed the title Closes #10557. Store journal abbreviation lists in specified directory Closes #10557 Store journal abbreviation lists in specified directory Mar 17, 2025
@adhamahmad adhamahmad changed the title Closes #10557 Store journal abbreviation lists in specified directory Store journal abbreviation lists in specified directory Mar 17, 2025
@koppor
Copy link
Member

koppor commented Mar 17, 2025

This PR might have conflicts with #12606 - They should be combined at some point.

Depening on which PR gets in first, the other one needs to be adapted.

Comment on lines 274 to 278
if (filePath.endsWith(".mv")) {
openMvFile(path);
} else {
openFile(path);
}
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, the logic is wrong.

Think of .mv as cache.

  • If .csv is older than .mv: Use .mv
  • Else: Create .mv from csv

Copy link
Author

@adhamahmad adhamahmad Mar 17, 2025

Choose a reason for hiding this comment

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

I reviewed the logic and found that the else branch (handling CSV files) is not needed.

By the time updateJournalFiles() is executed, the conversion process in JournalAbbreviationMvGenerator.convertAllCsvToMv() has already performed a timestamp check on all CSV files.

This ensures that any CSV file in the new directory has been converted to an MV file.

Comment on lines +133 to +137
if (name.endsWith(".mv")) {
openMvFile(filePath);
} else { // .csv file
openFile(filePath);
}
Copy link

Choose a reason for hiding this comment

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

Magic string ".mv" should be defined as a constant. String literals used for file extension checking should be extracted to named constants for better maintainability.

@adhamahmad adhamahmad requested a review from koppor March 17, 2025 20:54
@adhamahmad adhamahmad marked this pull request as ready for review March 17, 2025 20:55
@@ -58,13 +59,27 @@ public void readAbbreviations() throws IOException {
}
}

public void readAbbreviationsFromMv() throws IOException {
Copy link

Choose a reason for hiding this comment

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

Method lacks JavaDoc despite being a complex method that handles file loading and data transformation. The method's purpose and behavior should be documented.

fullToAbbreviation.putAll(abbreviationMap);
store.commit();
LOGGER.info("Saved MV file: {}", mvFile.getFileName());
} catch (IOException e) {
Copy link

Choose a reason for hiding this comment

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

The method declares throws IOException but also catches it internally, which creates confusion about exception handling responsibility. Should either handle or propagate.

Comment on lines +116 to +120
if (journalsDir == null) {
String defaultDir = Directories.getJournalAbbreviationsDirectory().toString();
setJournalAbbreviationDir(defaultDir);
return defaultDir;
}
Copy link

Choose a reason for hiding this comment

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

The code follows nested logic instead of failing fast. The condition should be inverted to return early, following the fail-fast principle.

JournalAbbreviationMvGenerator.convertCsvToMv(csvFile, mvFile);

// Verify the MV file is created
assertTrue(Files.exists(mvFile), "MV file should be created after conversion");
Copy link

Choose a reason for hiding this comment

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

Assertion message should be removed as the method name already conveys the expected behavior. The test method name clearly indicates what is being tested.

// Load abbreviations from the MV file
Collection<Abbreviation> abbreviations = JournalAbbreviationMvGenerator.loadAbbreviationsFromMv(mvFile);
// Expecting 2 abbreviations as in the CSV file
assertEquals(2, abbreviations.size(), "MV file should contain 2 abbreviations");
Copy link

Choose a reason for hiding this comment

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

Assertion message should be removed as the method name already conveys the expected behavior. The test method name clearly indicates what is being tested.

Copy link

trag-bot bot commented Mar 18, 2025

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

@koppor koppor marked this pull request as draft March 19, 2025 21:59
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.

Store journal lists in separate directory
2 participants