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

Auto relativize PDF file paths when selecting "Search for unlinked local files" #12088

Merged
merged 13 commits into from
Oct 27, 2024

Conversation

u7676493
Copy link
Contributor

@u7676493 u7676493 commented Oct 26, 2024

Fixes koppor#549

It updates the functionality of the "Search for unlinked local files" import option - it now automatically relativizes the file paths for PDF files.

List of changes

  • Modified ImportHandler to use different arguments for importPDFContent(), accounting for the changes made to ExternalFilesContentImporter
    ImportHandler starts the execution of the logic of importing a PDF file.
  • Modified ExternalFilesContentImporter to include imports for BibDatabaseContext and FilePreferences classes as well as different arguments for importPDFContent() and importDatabase(), both related to the changes made to PdfMergeMetadataImporter
  • Modified PdfMergeMetadataImporter to add an alternate importDatabase() function with different arguments, using the BibDatabaseContext.getFileDirectories(FilePreferences) function to get all file directories and relativize the file path using the FileUtil.relativize(Path, List<Path>) function, before passing it into the default override of the importDatabase(Path) function from the Importer class.
    PdfMergeMetadataImporter handles all of the actual logic relating to importing a PDF file.
    The new importDatabase() function has three arguments: (Path file, BibDatabaseContext context, FilePreferences preferences)
  • Added a WIP test in PdfMergeMetadataImporter

Please provide me with any feedback you can! I haven't included any changes in documentation yet because this is still a WIP.

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 applicable)
  • 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.

@@ -118,7 +118,7 @@ public List<ImportFilesResultItemViewModel> call() {

try {
if (FileUtil.isPDFFile(file)) {
var pdfImporterResult = contentImporter.importPDFContent(file);
var pdfImporterResult = contentImporter.importPDFContent(file, bibDatabaseContext, filePreferences);
Copy link
Member

Choose a reason for hiding this comment

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

Can you change this to the strict returned type here?

Comment on lines 146 to 147
* @param context Everything related to the BIB file
* @param preferences Preferences for linked files
Copy link
Member

@subhramit subhramit Oct 26, 2024

Choose a reason for hiding this comment

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

146 - To be more precise, context is the metadata for the library. However, it's a common JabRef parameter, so can remove it.
147 - Can remove as well, as the type of the parameter makes the description redundant.

Comment on lines 101 to 105
// Set up results
List<BibEntry> result = importer.importDatabase(file, database, preferences).getDatabase().getEntries();

// Set up expected value
BibEntry expected = new BibEntry(StandardEntryType.InProceedings)
Copy link
Member

@subhramit subhramit Oct 26, 2024

Choose a reason for hiding this comment

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

Remove these two comments (redundant).

@u7676493
Copy link
Contributor Author

I have just added a commit that follows up on all of the requested changes so far.

@koppor koppor marked this pull request as ready for review October 26, 2024 23:19
Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

Tried it out. Works.

Small naming comment - otherwise code looks good. No need for additional tests. - Code is pretty similar with #10582 - which we also reviewed back then. - The PR was abandoned, thank you for porting it to the most recent version of JabRef.

Please add CHANGELOG.md entry and then it should be good to go!

@@ -17,9 +19,9 @@ public ExternalFilesContentImporter(ImportFormatPreferences importFormatPreferen
this.importFormatPreferences = importFormatPreferences;
}

public ParserResult importPDFContent(Path file) {
public ParserResult importPDFContent(Path file, BibDatabaseContext context, FilePreferences preferences) {
Copy link
Member

Choose a reason for hiding this comment

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

Name the preferences variable filePreferences - also in the method importDatabase

@u7676493 u7676493 changed the title [WIP] Auto relativize PDF file paths when selecting "Find Unlinked Files" Auto relativize PDF file paths when selecting "Find Unlinked Files" Oct 26, 2024
@u7676493 u7676493 changed the title Auto relativize PDF file paths when selecting "Find Unlinked Files" Auto relativize PDF file paths when selecting "Search for unlinked local files" Oct 26, 2024
koppor
koppor previously approved these changes Oct 26, 2024
@koppor koppor enabled auto-merge October 26, 2024 23:46
auto-merge was automatically disabled October 27, 2024 05:18

Head branch was pushed to by a user without write access

@koppor
Copy link
Member

koppor commented Oct 27, 2024

@u7676493 I already added it to the merge queue. You updated. Do you want to do any more changes?

List<Path> directories = context.getFileDirectories(filePreferences);

if (!directories.isEmpty()) {
filePath = FileUtil.relativize(filePath, directories);
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't that method also have a check for emptyness? Then, this call can be moved out of the if and the jf be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have just added a commit that does that

Removed unnecessary if statement
subhramit
subhramit previously approved these changes Oct 27, 2024
Copy link
Member

@subhramit subhramit left a comment

Choose a reason for hiding this comment

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

Looks good. Adding back to merge queue.

@subhramit subhramit added this pull request to the merge queue Oct 27, 2024
Merged via the queue into JabRef:main with commit b9f3951 Oct 27, 2024
23 checks passed
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.

Path should be relative after import at "Find Unlinked Files"
3 participants