-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix: Allow pasting PDF URLs into main table to create entries #12911
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
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.
Comments on first look
@@ -399,6 +402,16 @@ public List<BibEntry> handleStringData(String data) throws FetcherException { | |||
if ((data == null) || data.isEmpty()) { | |||
return Collections.emptyList(); | |||
} | |||
LOGGER.debug("Checking if URL is a PDF: {}", data); | |||
|
|||
if (org.jabref.logic.util.URLUtil.isURL(data) && data.toLowerCase().endsWith(".pdf")) { |
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.
Why use fully qualified package link instead of import?
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.
Thanks, I changed it.
Unhealthy reflex sometimes😅
@@ -399,6 +402,16 @@ public List<BibEntry> handleStringData(String data) throws FetcherException { | |||
if ((data == null) || data.isEmpty()) { | |||
return Collections.emptyList(); | |||
} | |||
LOGGER.debug("Checking if URL is a PDF: {}", data); |
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.
Remove
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.
For me it would be OK. Maybe with "trace" level?
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 agree with the comments. Trace level seems suitable since it provides low level detail. In hindsight, debug feels too noisy (especially given how often handleStringData gets called)
I changed it to trace level
urlDownload.toFile(targetFile); | ||
} catch (FetcherException fe) { | ||
LOGGER.error("Error downloading PDF from URL", fe); | ||
throw new IOException("Error downloading PDF", fe); |
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.
Why does this have to be wrapped into an 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.
Yeah it doesn't have to be–thanks for the catch! I changed it
entries.add(emptyEntry); | ||
} | ||
return entries; | ||
} catch (Exception ex) { |
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.
Do not catch generic exceptions.
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 changed it to IO Exception.
src/main/resources/csl-styles
Outdated
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.
Revert the submodule changes as per https://devdocs.jabref.org/code-howtos/faq.html#submodules
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 reverted them–thank you for the reminder!
6c9ee9f
to
ef322c6
Compare
Could someone please create an issue for this PR? The issue was listed in a non-public repo. Edit: Sorry for the force push (ran into some sync issues with my local setup after a rebase) |
No need for rebasing. We squash all commits after merging the PR |
} | ||
} | ||
|
||
private String deriveFileNameFromUrl(String url) { |
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.
Use FileUtil.getValidFileName
Please link the melting pot issue, even if it's not visible for everyone. In the changelog you can create an entry and reference the PR numner |
Unfortunately, I didn't receive a melting pot link for this issue. I just received a problem description and proceeded with solving it. Do you want me to share that "description" with you? |
If there is no issue, then it's fine. The description in the pull-request is good enough as is. |
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.
Works
} | ||
LOGGER.trace("Checking if URL is a PDF: {}", data); | ||
|
||
if (URLUtil.isURL(data) && data.toLowerCase().endsWith(".pdf")) { |
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 wonder, can you extract somehow last element of the URL, so that it resembles a path.
And then use method FileUtil#isPDFFile
(https://github.com/JabRef/jabref/blob/main/src/main/java/org/jabref/logic/util/io/FileUtil.java#L494)
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.
If extraction of last elements would take too much code -- then it's okay to leave as is
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 implemented your suggestions.
This way added a few more lines, but I prefer it that way: more maintainable and cleaner.
Your pull request needs to link an issue. To ease organizational workflows, please link this pull-request to the issue with syntax as described in https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue:
Examples
|
…#12911) * Improve handling of PDF file import behavior * Add support for handling PDF URLs when pasted * Revert submodule changes * Replace Collections.emptyList() with List.of() and improve exception handling * Change log level from debug to trace for PDF URL * Registered fix in changelog * Used getValidFileName for helper method deriveFileNameFromUrl * Refactor PDF URL detection using FileUtil.isPDFFile * Move getFileNameFromURL helper method to URLUtil class
…#12911) * Improve handling of PDF file import behavior * Add support for handling PDF URLs when pasted * Revert submodule changes * Replace Collections.emptyList() with List.of() and improve exception handling * Change log level from debug to trace for PDF URL * Registered fix in changelog * Used getValidFileName for helper method deriveFileNameFromUrl * Refactor PDF URL detection using FileUtil.isPDFFile * Move getFileNameFromURL helper method to URLUtil class
Previously, pasting a URL that ended in
.pdf
into the main table showed an error: “Could not find suitable import format.” This change improves usability by allowing users to paste PDF links directly (e.g. on Windows 10 via clicking into the main table and then pressingCTRL + V
), and automatically adds a corresponding BibEntry with metadata and file attachment.Closes https://github.com/JabRef/jabref-issue-melting-pot/issues/201
This change:
.pdf
URLs inImportHandler#handleStringData
PdfMergeMetadataImporter
Manual Testing
This feature was manually tested:
.pdf
URL into the main tableNo test case added because this feature relies on clipboard input and file download behavior, which are difficult to mock in unit tests.
Screenshots
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if change is visible to the user)