@@ -56,48 +56,51 @@ public void execute() {
56
56
57
57
if (basePanel .getSelectedEntries ().size () >= WARNING_LIMIT ) {
58
58
boolean confirmDownload = dialogService .showConfirmationDialogAndWait (
59
- Localization .lang ("Look up full text documents" ),
60
- Localization .lang (
61
- "You are about to look up full text documents for %0 entries." ,
62
- String .valueOf (basePanel .getSelectedEntries ().size ())) + "\n "
63
- + Localization .lang ("JabRef will send at least one request per entry to a publisher." )
64
- + "\n "
65
- + Localization .lang ("Do you still want to continue?" ),
66
- Localization .lang ("Look up full text documents" ),
67
- Localization .lang ("Cancel" ));
59
+ Localization .lang ("Look up full text documents" ),
60
+ Localization .lang (
61
+ "You are about to look up full text documents for %0 entries." ,
62
+ String .valueOf (basePanel .getSelectedEntries ().size ())) + "\n "
63
+ + Localization .lang ("JabRef will send at least one request per entry to a publisher." )
64
+ + "\n "
65
+ + Localization .lang ("Do you still want to continue?" ),
66
+ Localization .lang ("Look up full text documents" ),
67
+ Localization .lang ("Cancel" ));
68
68
69
69
if (!confirmDownload ) {
70
70
basePanel .output (Localization .lang ("Operation canceled." ));
71
71
return ;
72
72
}
73
73
}
74
74
75
- Task <Map <BibEntry , Optional <URL >>> findFullTextsTask = new Task <Map <BibEntry , Optional <URL >>>() {
75
+ Task <Map <BibEntry , Optional <URL >>> findFullTextsTask = new Task <Map <BibEntry , Optional <URL >>>() {
76
+
76
77
@ Override
77
78
protected Map <BibEntry , Optional <URL >> call () {
78
79
Map <BibEntry , Optional <URL >> downloads = new ConcurrentHashMap <>();
79
80
int count = 0 ;
80
81
AutoSetFileLinksUtil util = new AutoSetFileLinksUtil (basePanel .getBibDatabaseContext (), Globals .prefs .getFilePreferences (), Globals .prefs .getAutoLinkPreferences (), ExternalFileTypes .getInstance ());
81
- util .linkAssociatedFiles (basePanel .getSelectedEntries (), new NamedCompound ("" ));
82
+ List < BibEntry > changed = util .linkAssociatedFiles (basePanel .getSelectedEntries (), new NamedCompound ("" ));
82
83
83
- for (BibEntry entry : basePanel .getSelectedEntries ()) {
84
- List <LinkedFile > fileList = entry .getFiles ();
85
- if (fileList .isEmpty ()) {
84
+ for (BibEntry entry : changed ) {
85
+ if (entry .getFiles ().isEmpty ()) {
86
86
FulltextFetchers fetchers = new FulltextFetchers (Globals .prefs .getImportFormatPreferences ());
87
87
downloads .put (entry , fetchers .findFullTextPDF (entry ));
88
+ } else {
89
+ downloads .put (entry , Optional .empty ());
88
90
}
89
91
updateProgress (++count , basePanel .getSelectedEntries ().size ());
90
92
}
93
+
91
94
return downloads ;
92
95
}
93
96
};
94
97
95
98
findFullTextsTask .setOnSucceeded (value -> downloadFullTexts (findFullTextsTask .getValue ()));
96
99
97
100
dialogService .showProgressDialogAndWait (
98
- Localization .lang ("Look up full text documents" ),
99
- Localization .lang ("Looking for full text document..." ),
100
- findFullTextsTask );
101
+ Localization .lang ("Look up full text documents" ),
102
+ Localization .lang ("Looking for full text document..." ),
103
+ findFullTextsTask );
101
104
102
105
Globals .TASK_EXECUTOR .execute (findFullTextsTask );
103
106
}
@@ -112,16 +115,19 @@ private void downloadFullTexts(Map<BibEntry, Optional<URL>> downloads) {
112
115
if (!dir .isPresent ()) {
113
116
114
117
dialogService .showErrorDialogAndWait (Localization .lang ("Directory not found" ),
115
- Localization .lang ("Main file directory not set!" ) + " " + Localization .lang ("Preferences" )
116
- + " -> " + Localization .lang ("File" ));
118
+ Localization .lang ("Main file directory not set!" ) + " " + Localization .lang ("Preferences" )
119
+ + " -> " + Localization .lang ("File" ));
117
120
return ;
118
121
}
119
122
//Download and link full text
120
123
addLinkedFileFromURL (result .get (), entry , dir .get ());
121
124
125
+ } else if (!result .isPresent () && !entry .getFiles ().isEmpty ()) {
126
+ dialogService .notify (Localization .lang ("Full text document found already on disk for entry %0" , entry .getCiteKeyOptional ().orElse (Localization .lang ("undefined" ))));
127
+
122
128
} else {
123
129
dialogService .notify (Localization .lang ("No full text document found for entry %0." ,
124
- entry .getCiteKeyOptional ().orElse (Localization .lang ("undefined" ))));
130
+ entry .getCiteKeyOptional ().orElse (Localization .lang ("undefined" ))));
125
131
}
126
132
}
127
133
}
@@ -140,33 +146,33 @@ private void addLinkedFileFromURL(URL url, BibEntry entry, Path targetDirectory)
140
146
if (!entry .getFiles ().contains (newLinkedFile )) {
141
147
142
148
LinkedFileViewModel onlineFile = new LinkedFileViewModel (
143
- newLinkedFile ,
144
- entry ,
145
- basePanel .getBibDatabaseContext (),
146
- Globals .TASK_EXECUTOR ,
147
- dialogService ,
148
- JabRefPreferences .getInstance ().getXMPPreferences (),
149
- JabRefPreferences .getInstance ().getFilePreferences (),
150
- ExternalFileTypes .getInstance ());
149
+ newLinkedFile ,
150
+ entry ,
151
+ basePanel .getBibDatabaseContext (),
152
+ Globals .TASK_EXECUTOR ,
153
+ dialogService ,
154
+ JabRefPreferences .getInstance ().getXMPPreferences (),
155
+ JabRefPreferences .getInstance ().getFilePreferences (),
156
+ ExternalFileTypes .getInstance ());
151
157
152
158
try {
153
159
URLDownload urlDownload = new URLDownload (newLinkedFile .getLink ());
154
160
BackgroundTask <Path > downloadTask = onlineFile .prepareDownloadTask (targetDirectory , urlDownload );
155
161
downloadTask .onSuccess (destination -> {
156
162
LinkedFile downloadedFile = LinkedFilesEditorViewModel .fromFile (
157
- destination ,
158
- basePanel .getBibDatabaseContext ().getFileDirectoriesAsPaths (JabRefPreferences .getInstance ().getFilePreferences ()), ExternalFileTypes .getInstance ());
163
+ destination ,
164
+ basePanel .getBibDatabaseContext ().getFileDirectoriesAsPaths (JabRefPreferences .getInstance ().getFilePreferences ()), ExternalFileTypes .getInstance ());
159
165
entry .addFile (downloadedFile );
160
166
dialogService .notify (Localization .lang ("Finished downloading full text document for entry %0." ,
161
- entry .getCiteKeyOptional ().orElse (Localization .lang ("undefined" ))));
167
+ entry .getCiteKeyOptional ().orElse (Localization .lang ("undefined" ))));
162
168
});
163
169
Globals .TASK_EXECUTOR .execute (downloadTask );
164
170
} catch (MalformedURLException exception ) {
165
171
dialogService .showErrorDialogAndWait (Localization .lang ("Invalid URL" ), exception );
166
172
}
167
173
} else {
168
174
dialogService .notify (Localization .lang ("Full text document for entry %0 already linked." ,
169
- entry .getCiteKeyOptional ().orElse (Localization .lang ("undefined" ))));
175
+ entry .getCiteKeyOptional ().orElse (Localization .lang ("undefined" ))));
170
176
}
171
177
}
172
178
}
0 commit comments