Download covers when preview panel is opened#15572
Conversation
* feat: add a test for requirement RE02 I also had to change the access modifier to `protected` for one download function. Additionally, I refactored the download method a bit, in order to mock at test it more easily. * fix: cleanup imports
Co-authored-by: Melker Trané <melkert@kth.se>
…gai (#62) Co-authored-by: Melker Trané <melkert@kth.se>
|
Your pull request conflicts with the target branch. Please merge with your code. For a step-by-step guide to resolve merge conflicts, see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line. |
Review Summary by QodoAutomatic book cover download with cooldown and failure tracking
WalkthroughsDescription• Automatically download book covers when preview panel opens • Implement 24-hour cooldown for failed cover download attempts • Create .not-available marker files for unavailable covers • Add comprehensive test suite for cover fetcher functionality Diagramflowchart LR
A["Preview Panel Opens"] -->|checks preference| B["Download Covers Enabled?"]
B -->|yes| C["BookCoverFetcher.downloadCoversForEntry"]
C -->|check existing image| D["Image Found?"]
D -->|yes| E["Use Existing Cover"]
D -->|no| F["Check .not-available File"]
F -->|exists & recent| G["Skip Download<br/>24h Cooldown Active"]
F -->|missing or old| H["Download Cover"]
H -->|success| I["Delete .not-available<br/>Refresh Preview"]
H -->|failure| J["Create/Update .not-available<br/>File with Timestamp"]
File Changes1. jabgui/src/main/java/org/jabref/gui/importer/BookCoverFetcher.java
|
Code Review by Qodo
1.
|
|
Setting this as ready for review in hopes that I get the help needed |
| void createNotAvailableFileAfterFailedDownload() throws Exception { | ||
| bookCoverFetcher.downloadCoversForEntry(badEntry); | ||
|
|
||
| assertTrue(Files.notExists(badCoverPath)); | ||
| assertTrue(Files.exists(badNotAvailablePath)); | ||
| } |
There was a problem hiding this comment.
2. Tests perform real http 📘 Rule violation ☼ Reliability
The newly added tests call downloadCoversForEntry(...), which performs real HTTP downloads (URLDownload), making tests slow and potentially flaky in CI/offline environments. Compliance requires tests to remain deterministic and fast unless clearly justified and controlled.
Agent Prompt
## Issue description
`BookCoverFetcherTest` triggers real HTTP requests via `BookCoverFetcher.downloadCoversForEntry(...)`, which can make CI runs flaky/slow and fail in restricted network environments.
## Issue Context
`BookCoverFetcher` uses `new URLDownload(url)` to fetch content over the network. Tests should avoid real network by injecting a downloader abstraction or by mocking/stubbing the network layer.
## Fix Focus Areas
- jabgui/src/test/java/org/jabref/gui/importer/BookCoverFetcherTest.java[76-81]
- jabgui/src/main/java/org/jabref/gui/importer/BookCoverFetcher.java[103-109]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
I don't have permisisons to push to your branch, can you please resolve the merge conflicts? |
|
Regarding your questions:
Yep, I think this would be a valid approach, but I would suggest you can do this in a follow-up. |
Related issues and pull requests
Closes #14848
Follow up to #15250
PR Description
This PR makes it so the book cover is automatically downloaded when the preview panel is opened. To make this possible,
BookCoverFetcherwas modified to create.not-availablefiles when it could not find a remote cover. Repeated attempts to download the cover should not be made if a previous attempt failed within 24 hours. A new test file,BookCoverFetcherTest.javawas created to test this functionality. Additionaly,PreviewViewerwas modified to download the book cover when opened and refresh when that is done.This PR also solves a bug where the fetcher downloads an empty image when no real cover is found, which displays as a white image in the preview panel.
HELP NEEDED
As per the request in #15250 I made the tests use real downloads. However, I can not simply use the FetcherTest annotation since the annotation is in jabref/jablib and BookCoverFetcherTest is in jabref/jabgui. I see two possible solutions:
Steps to test
Test download and refresh
Disable download book covers in preferences. Create a new entry with the ISBN filled in. Enable download book covers in preferences. Open the preview panel for the created entry. The book cover should download and refresh the panel content.
Test download cooldown
Go to the book covers directory and create the file
isbn-9780141036144.not-available. Make a new entry with ISBN 9780141036144. The book cover should not be downloaded (see logs). Change your time to be more than 24 hours in the future. Open the entry again. The book cover should now be downloaded and the panel refreshed. The.not-availablefile should be deleted.Screenshot
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)