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

make file path relative when creatig entry from pdf #11409

Closed
wants to merge 6 commits into from

Conversation

Arshadpd
Copy link

Closes #11173

Mandatory checks

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

@Siedlerchr
Copy link
Member

You can just push your changes, the PR will be updated automatically. No need to open close

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.

Code changes are strange. Many lines removed. No proper spacing between fields and class.

File was attached before. Why an additional setting of the file field?

@Arshadpd
Copy link
Author

Thanks for the review @koppor ,

  1. The spacing was actually reduced in efforts to remove the Checkstyle issues. It is rectified now.

  2. I am trying to understand the comment on the "File" field, but if the concern is about the object " this.filePreferences = preferences.getFilePreferences(); want", I just wanted to let you know that I got the object name updated in one of the other commits to Jabref main branch, when I was syncing my fork. I also had to change my code to adapt the new object name for "FilePreferences".

@Siedlerchr Siedlerchr changed the title Fix for issue 11173 make file path relative Jun 22, 2024
@Siedlerchr Siedlerchr changed the title make file path relative make file path relative when creatig entry from pdf Jun 22, 2024
if (!pdfEntriesInFile.isEmpty()) {
for (BibEntry entry : pdfEntriesInFile) {
Copy link
Member

Choose a reason for hiding this comment

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

That's stupid. We have a method which takes of all of those things. Try to understand the code first before doing any changes
see addResultToList and it takes a Path as argument.
You basically just have to call FileUtil.relative before adding it tot he list

Copy link
Author

Choose a reason for hiding this comment

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

Hi @Siedlerchr ,

Thanks for your review. Please help me to clear my doubts
as per my understanding,

  1. The addResultToList() methiod is just used for logging purpose, as we add the result of the operations and just use it to log at the end of the operation.

  2. As per your suggestion, I am already using the FileUtil.relativize() method, this call is in the private relativize() method that has been added to the ImportHandler class. This code was approved by @koppor in the comment section of the issue, and we have created the pull request for the same.

If you suggest, instead of having a different private relativize() method in the class, directly implement it in the following way,

for (BibEntry entry : pdfEntriesInFile) {
entry.setField(StandardField.FILE, FileUtil.relativize(file));
}

I can implement it in this way as well. As of now we went ahead with the approach discussed and approved in the issue comments section. Please let us know your thoughts and feel free to correct me if my understanding is wrong.

Thanks,
Arshad

Copy link
Member

Choose a reason for hiding this comment

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

I tried to understand the code and the position seems to be OK.

The hard part is to deal with non-usual flows. Did you read in org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter#importDatabase(java.nio.file.Path)? There, an exceptional case for mulitple linked files is written down.

Do

  1. entry.getFiles()
  2. Iterate through the list and make relativize each path
  3. Call entry.setFiles(...)

In addition:

  1. Move String relPath = relativize(file); down to here. The variable is not used else
  2. Inline relativize here. It is a two line method. Thus, no need to create a new method.

Please note that at #11173 (comment) I had not the full content of your pull request and no IDE opened at my side. The updated comment results of an half an our investigation of JabRef's code.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe, the more non-hacky fix would be to have create a relative path in org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter#importDatabase(java.nio.file.Path) at the end at entry.addFile(new LinkedFile("", filePath, StandardFileType.PDF.getName()));

Maybe, the call can be like this:

var pdfImporterResult = contentImporter.importPDFContent(file, bibDatabaseContext, preferences.getFilePreferences());

But (much) more code changes will be needed, because importDatabase is @Override. Thus, the context and filePreferences need to be stored elsewhere etc.

Copy link
Member

Choose a reason for hiding this comment

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

@Arshadpd Any feedback on this?

Copy link
Member

Choose a reason for hiding this comment

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

Form my point of view the current implementaton is fine and we can leave the more complex one as a future task

Copy link
Member

Choose a reason for hiding this comment

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

The current implementation removes all links contained in the BibEntry objects contained. Thus, if more than one file link is contained, it is removed. I need to recheck, if this case really happens. Reading my comment from last week (#11409 (comment)), it might happen.

Moreover, I had code comments even if we agree that (potentially) destroying data is OK. These should be addressed in all cases. -- Maybe, it is OK to create a log output (warn) if file entries are overwritten.

We spend now at least one hour for reviewing and we should make use of the intellecutal propery we crafted there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When creating an entry based on a PDF, the file path should be relative
4 participants