Skip to content

Fix PDF relativization test#12621

Closed
InAnYan wants to merge 9 commits into
JabRef:mainfrom
InAnYan:fix/relativization
Closed

Fix PDF relativization test#12621
InAnYan wants to merge 9 commits into
JabRef:mainfrom
InAnYan:fix/relativization

Conversation

@InAnYan

@InAnYan InAnYan commented Mar 4, 2025

Copy link
Copy Markdown
Member

Fixes failing test: PdfMergeMetadataImporterTest#importRelativizesFilePath.

Fixes #12620

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 (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.

@koppor

koppor commented Mar 4, 2025

Copy link
Copy Markdown
Member

Blocked by #12619

@koppor koppor requested a review from Copilot March 4, 2025 13:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PR Overview

This PR fixes a failing test for PDF metadata file path relativization. The changes include:

  • Modifying the test to use a manually instantiated FilePreferences rather than a mocked one.
  • Adding an overloaded importDatabase method in PdfMergeMetadataImporter that relativizes the file path.
  • Introducing a corresponding overloaded importDatabase method in PdfImporter to support the new file path handling.

Reviewed Changes

File Description
src/test/java/org/jabref/logic/importer/fileformat/pdf/PdfMergeMetadataImporterTest.java Updates test to use manual file preferences instantiation for correct working directory setup
src/main/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporter.java Introduces a new method that relativizes the file path before database import
src/main/java/org/jabref/logic/importer/fileformat/pdf/PdfImporter.java Adds an overloaded method accepting FilePreferences to resolve the file path correctly

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

}
}

public ParserResult importDatabase(Path filePath, FilePreferences filePreferences) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure why this is necessary. Shouldn't the caller take care about the absolute path? - Since this method is a) a duplicate of public ParserResult importDatabase(Path filePath) and b) used only once, I propose to move Path readPath = filePreferences.getWorkingDirectory().resolve(filePath); to the caller.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes... the problem is:

XmpUtilReader can't read relativized path. This was the reason why I (mistakenly) removed relativization.

So in this method I leave relativized path in BibEntry, but when I'm reading I use the full path.

Yeah, something's wrong here

@koppor koppor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, let's go this through. Better than nothing. :)

I have a small suggestion, which would make the logic more clear.

Maybe, also the JavaDoc should be copied into PdfImporter.

Comment on lines +201 to +203
List<Path> directories = context.getFileDirectories(filePreferences);

filePath = FileUtil.relativize(filePath, directories);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be moved down to ´importDatabase`, then I understand it more...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It is in importDatabase?

@InAnYan InAnYan marked this pull request as draft March 17, 2025 20:18
@InAnYan

InAnYan commented Mar 17, 2025

Copy link
Copy Markdown
Member Author

I should think about it more

@koppor

koppor commented Mar 17, 2025

Copy link
Copy Markdown
Member

I should think about it more

The quick fix is OK for now, isn't it?

Comment thread src/main/java/org/jabref/logic/importer/fileformat/pdf/PdfImporter.java Outdated
@InAnYan InAnYan marked this pull request as ready for review March 20, 2025 09:49
} catch (IOException e) {
return ParserResult.fromError(e);
}
return new PdfMergeMetadataImporter(importFormatPreferences).importDatabase(file, context, filePreferences);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The try-catch block removal shifts exception handling responsibility to the caller without documenting this change in method signature. Method should declare throws IOException.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

IntelliJ said that it is not thrown at all


public List<BibEntry> importDatabase(Path filePath, PDDocument document) throws IOException, ParseException {
return grobidService.processPDF(filePath, importFormatPreferences);
public List<BibEntry> importDatabase(Path fullPath, PDDocument document) throws IOException, ParseException {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The method accepts PDDocument parameter but doesn't use it in the implementation, violating the Single Responsibility Principle by having unused parameters.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, it just uses grobid.

Is there any way to mark this argument as explicitly unused?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why can't it be removed - I don't see any @Override annotation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh! It should be overriden

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Then you can add JavaDoc and use @param and then say that it is ignored ^^

@github-actions

Copy link
Copy Markdown
Contributor

If you made changes that are visible to the user, please add a brief description along with the issue number to the CHANGELOG.md file. More details can be found in our Developer Documentation about the changelog.


public List<BibEntry> importDatabase(Path filePath, PDDocument document) throws IOException {
return new XmpUtilReader().readXmp(filePath, xmpPreferences);
public List<BibEntry> importDatabase(Path fullPath, PDDocument document) throws IOException {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Method accepts PDDocument parameter but doesn't use it in the implementation, violating Single Responsibility Principle by having unused parameters.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, this is expected.

Is there any way to mark this argument as explicitly unused?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in #12833

@koppor koppor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will be fixed by #12833

That uses org.jabref.logic.cleanup.RelativePathsCleanup#RelativePathsCleanup

@koppor koppor mentioned this pull request Mar 27, 2025
4 tasks
@koppor koppor deleted the fix/relativization branch April 1, 2025 01:47
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.

Fix PdfMergeMetadataImporterTest

4 participants