-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
Thank you for working on this.
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? |
I intend to include them as additional commits within this PR. |
Nice! 👍 |
Code hint: This is already implemented at org.jabref.cli.JournalListMvGenerator. One just needs to move that class to |
This could be easy.
|
…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
src/main/java/org/jabref/logic/journals/JournalAbbreviationPreferences.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/journals/JournalAbbreviationPreferences.java
Outdated
Show resolved
Hide resolved
@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. |
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. |
if (filePath.endsWith(".mv")) { | ||
openMvFile(path); | ||
} else { | ||
openFile(path); | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
if (name.endsWith(".mv")) { | ||
openMvFile(filePath); | ||
} else { // .csv file | ||
openFile(filePath); | ||
} |
There was a problem hiding this comment.
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.
@@ -58,13 +59,27 @@ public void readAbbreviations() throws IOException { | |||
} | |||
} | |||
|
|||
public void readAbbreviationsFromMv() throws IOException { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
if (journalsDir == null) { | ||
String defaultDir = Directories.getJournalAbbreviationsDirectory().toString(); | ||
setJournalAbbreviationDir(defaultDir); | ||
return defaultDir; | ||
} |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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.
@trag-bot didn't find any issues in the code! ✅✨ |
Closes #10557
UI changes:
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if change is visible to the user)