-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Fix file not linked after DL from fulltext fetcher #7162
Conversation
Remove redundant code
} catch (MalformedURLException exception) { | ||
dialogService.showErrorDialogAndWait(Localization.lang("Invalid URL"), exception); | ||
} | ||
onlineFile.download(); |
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 think with this change, downloading a pdf doesn't show any progress any more since the onlineFile
is not added to the entry until the download succeeds.
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.
Not exactly sure, at this point we add the online fie link and then call the download method which also shows the progress
jabref/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java
Lines 415 to 454 in c8f7be8
public void download() { | |
if (!linkedFile.isOnlineLink()) { | |
throw new UnsupportedOperationException("In order to download the file it has to be an online link"); | |
} | |
try { | |
Optional<Path> targetDirectory = databaseContext.getFirstExistingFileDir(filePreferences); | |
if (targetDirectory.isEmpty()) { | |
dialogService.showErrorDialogAndWait(Localization.lang("Download file"), Localization.lang("File directory is not set or does not exist!")); | |
return; | |
} | |
URLDownload urlDownload = new URLDownload(linkedFile.getLink()); | |
BackgroundTask<Path> downloadTask = prepareDownloadTask(targetDirectory.get(), urlDownload); | |
downloadTask.onSuccess(destination -> { | |
LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectories(filePreferences), externalFileTypes); | |
List<LinkedFile> linkedFiles = entry.getFiles(); | |
int oldFileIndex = -1; | |
int i = 0; | |
while (i < linkedFiles.size() && oldFileIndex == -1) { | |
LinkedFile file = linkedFiles.get(i); | |
// The file type changes as part of download process (see prepareDownloadTask), thus we only compare by link | |
if (file.getLink().equalsIgnoreCase(linkedFile.getLink())) { | |
oldFileIndex = i; | |
} | |
i++; | |
} | |
if (oldFileIndex == -1) { | |
linkedFiles.add(0, newLinkedFile); | |
} else { | |
linkedFiles.set(oldFileIndex, newLinkedFile); | |
} | |
entry.setFiles(linkedFiles); | |
}); | |
downloadProgress.bind(downloadTask.workDonePercentageProperty()); | |
downloadTask.titleProperty().set(Localization.lang("Downloading")); | |
downloadTask.messageProperty().set( | |
Localization.lang("Fulltext for") + ": " + entry.getCitationKey().orElse(Localization.lang("New entry"))); | |
downloadTask.showToUser(true); | |
taskExecutor.execute(downloadTask); |
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.
Is this the first time I really like deleted code? 😇
Okay, but this progress dialog is really ugly, especially compared to the nice experience you get after "download from a given url" (where you have to paste the url manually). |
I didn't change anything at the progress dialog...That is coming from the previous step, where the fulltext fetcher searches |
Remove redundant code
While debugging for #7152 I found that the file is downloaded, but not linked to the library afterwards.
Fortunately I could just replace it with the specific download method already defined.