Skip to content

Commit 6342c8f

Browse files
committed
Merge remote-tracking branch 'upstream/master' into convertSearchWorker
* upstream/master: Fix Some Codacy Code Convention Issues (#4904) Bump ridl from 6.2.2 to 6.2.3 (#4903) Bump juh from 6.2.2 to 6.2.3 (#4902) Bump jurt from 6.2.2 to 6.2.3 (#4901) Bump unoil from 6.2.2 to 6.2.3 (#4900) Bump richtextfx from 0.9.3 to 0.10.0 (#4899) Store column widths as integer (#4896) Improve full text search for several files (#4855)
2 parents b2971ed + 1c11575 commit 6342c8f

File tree

8 files changed

+101
-76
lines changed

8 files changed

+101
-76
lines changed

build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ dependencies {
101101

102102
compile 'commons-cli:commons-cli:1.4'
103103

104-
compile "org.libreoffice:juh:6.2.2"
105-
compile "org.libreoffice:jurt:6.2.2"
106-
compile "org.libreoffice:ridl:6.2.2"
107-
compile "org.libreoffice:unoil:6.2.2"
104+
compile "org.libreoffice:juh:6.2.3"
105+
compile "org.libreoffice:jurt:6.2.3"
106+
compile "org.libreoffice:ridl:6.2.3"
107+
compile "org.libreoffice:unoil:6.2.3"
108108

109109
compile 'io.github.java-diff-utils:java-diff-utils:4.0'
110110
compile 'info.debatty:java-string-similarity:1.2.1'
@@ -130,7 +130,7 @@ dependencies {
130130
compile 'de.saxsys:mvvmfx:1.8.0'
131131
compile 'org.fxmisc.easybind:easybind:1.0.3'
132132
compile 'org.fxmisc.flowless:flowless:0.6.1'
133-
compile 'org.fxmisc.richtext:richtextfx:0.9.3'
133+
compile 'org.fxmisc.richtext:richtextfx:0.10.0'
134134
compile 'com.sibvisions.external.jvxfx:dndtabpane:0.1'
135135
compile 'javax.inject:javax.inject:1'
136136
compile 'com.jfoenix:jfoenix:8.0.8'

src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package org.jabref.gui.externalfiles;
22

3+
import java.net.MalformedURLException;
34
import java.net.URL;
45
import java.nio.file.Path;
56
import java.util.Map;
67
import java.util.Optional;
78
import java.util.concurrent.ConcurrentHashMap;
89

10+
import javafx.concurrent.Task;
11+
912
import org.jabref.Globals;
1013
import org.jabref.gui.BasePanel;
1114
import org.jabref.gui.DialogService;
1215
import org.jabref.gui.actions.SimpleCommand;
1316
import org.jabref.gui.fieldeditors.LinkedFileViewModel;
17+
import org.jabref.gui.fieldeditors.LinkedFilesEditorViewModel;
1418
import org.jabref.gui.util.BackgroundTask;
1519
import org.jabref.logic.importer.FulltextFetchers;
1620
import org.jabref.logic.l10n.Localization;
21+
import org.jabref.logic.net.URLDownload;
1722
import org.jabref.model.entry.BibEntry;
1823
import org.jabref.model.entry.LinkedFile;
1924
import org.jabref.preferences.JabRefPreferences;
@@ -63,18 +68,29 @@ public void execute() {
6368
return;
6469
}
6570
}
66-
BackgroundTask.wrap(this::findFullTexts)
67-
.onSuccess(this::downloadFullTexts)
68-
.executeWith(Globals.TASK_EXECUTOR);
69-
}
7071

71-
private Map<Optional<URL>, BibEntry> findFullTexts() {
72-
Map<Optional<URL>, BibEntry> downloads = new ConcurrentHashMap<>();
73-
for (BibEntry entry : basePanel.getSelectedEntries()) {
74-
FulltextFetchers fetchers = new FulltextFetchers(Globals.prefs.getImportFormatPreferences());
75-
downloads.put(fetchers.findFullTextPDF(entry), entry);
76-
}
77-
return downloads;
72+
Task<Map<Optional<URL>, BibEntry>> findFullTextsTask = new Task<Map<Optional<URL>, BibEntry>>() {
73+
@Override
74+
protected Map<Optional<URL>, BibEntry> call() {
75+
Map<Optional<URL>, BibEntry> downloads = new ConcurrentHashMap<>();
76+
int count = 0;
77+
for (BibEntry entry : basePanel.getSelectedEntries()) {
78+
FulltextFetchers fetchers = new FulltextFetchers(Globals.prefs.getImportFormatPreferences());
79+
downloads.put(fetchers.findFullTextPDF(entry), entry);
80+
updateProgress(++count, basePanel.getSelectedEntries().size());
81+
}
82+
return downloads;
83+
}
84+
};
85+
86+
findFullTextsTask.setOnSucceeded(value -> downloadFullTexts(findFullTextsTask.getValue()));
87+
88+
dialogService.showProgressDialogAndWait(
89+
Localization.lang("Look up full text documents"),
90+
Localization.lang("Looking for full text document..."),
91+
findFullTextsTask);
92+
93+
Globals.TASK_EXECUTOR.execute(findFullTextsTask);
7894
}
7995

8096
private void downloadFullTexts(Map<Optional<URL>, BibEntry> downloads) {
@@ -92,7 +108,7 @@ private void downloadFullTexts(Map<Optional<URL>, BibEntry> downloads) {
92108
return;
93109
}
94110
//Download and link full text
95-
addLinkedFileFromURL(result.get(), entry);
111+
addLinkedFileFromURL(result.get(), entry, dir.get());
96112

97113
} else {
98114
dialogService.notify(Localization.lang("No full text document found for entry %0.",
@@ -103,12 +119,13 @@ private void downloadFullTexts(Map<Optional<URL>, BibEntry> downloads) {
103119

104120
/**
105121
* This method attaches a linked file from a URL (if not already linked) to an entry using the key and value pair
106-
* from the findFullTexts map
122+
* from the findFullTexts map and then downloads the file into the given targetDirectory
107123
*
108124
* @param url the url "key"
109125
* @param entry the entry "value"
126+
* @param targetDirectory the target directory for the downloaded file
110127
*/
111-
private void addLinkedFileFromURL(URL url, BibEntry entry) {
128+
private void addLinkedFileFromURL(URL url, BibEntry entry, Path targetDirectory) {
112129
LinkedFile newLinkedFile = new LinkedFile(url, "");
113130

114131
if (!entry.getFiles().contains(newLinkedFile)) {
@@ -121,12 +138,21 @@ private void addLinkedFileFromURL(URL url, BibEntry entry) {
121138
dialogService,
122139
JabRefPreferences.getInstance());
123140

124-
onlineFile.download();
125-
126-
entry.addFile(onlineFile.getFile());
127-
128-
dialogService.notify(Localization.lang("Finished downloading full text document for entry %0.",
129-
entry.getCiteKeyOptional().orElse(Localization.lang("undefined"))));
141+
try {
142+
URLDownload urlDownload = new URLDownload(newLinkedFile.getLink());
143+
BackgroundTask<Path> downloadTask = onlineFile.prepareDownloadTask(targetDirectory, urlDownload);
144+
downloadTask.onSuccess(destination -> {
145+
LinkedFile downloadedFile = LinkedFilesEditorViewModel.fromFile(
146+
destination,
147+
basePanel.getBibDatabaseContext().getFileDirectoriesAsPaths(JabRefPreferences.getInstance().getFilePreferences()));
148+
entry.addFile(downloadedFile);
149+
dialogService.notify(Localization.lang("Finished downloading full text document for entry %0.",
150+
entry.getCiteKeyOptional().orElse(Localization.lang("undefined"))));
151+
});
152+
Globals.TASK_EXECUTOR.execute(downloadTask);
153+
} catch (MalformedURLException exception) {
154+
dialogService.showErrorDialogAndWait(Localization.lang("Invalid URL"), exception);
155+
}
130156
} else {
131157
dialogService.notify(Localization.lang("Full text document for entry %0 already linked.",
132158
entry.getCiteKeyOptional().orElse(Localization.lang("undefined"))));

src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ public void download() {
394394
if (!linkedFile.isOnlineLink()) {
395395
throw new UnsupportedOperationException("In order to download the file it has to be an online link");
396396
}
397-
398397
try {
399398
Optional<Path> targetDirectory = databaseContext.getFirstExistingFileDir(filePreferences);
400399
if (!targetDirectory.isPresent()) {
@@ -403,30 +402,34 @@ public void download() {
403402
}
404403

405404
URLDownload urlDownload = new URLDownload(linkedFile.getLink());
406-
BackgroundTask<Path> downloadTask = BackgroundTask
407-
.wrap(() -> {
408-
Optional<ExternalFileType> suggestedType = inferFileType(urlDownload);
409-
String suggestedTypeName = suggestedType.map(ExternalFileType::getName).orElse("");
410-
linkedFile.setFileType(suggestedTypeName);
411-
412-
String suggestedName = linkedFileHandler.getSuggestedFileName();
413-
return targetDirectory.get().resolve(suggestedName);
414-
})
415-
.then(destination -> new FileDownloadTask(urlDownload.getSource(), destination))
416-
.onSuccess(destination -> {
417-
LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectoriesAsPaths(filePreferences));
418-
linkedFile.setLink(newLinkedFile.getLink());
419-
linkedFile.setFileType(newLinkedFile.getFileType());
420-
})
421-
.onFailure(exception -> dialogService.showErrorDialogAndWait("Download failed", exception));
422-
405+
BackgroundTask<Path> downloadTask = prepareDownloadTask(targetDirectory.get(), urlDownload);
406+
downloadTask.onSuccess(destination -> {
407+
LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectoriesAsPaths(filePreferences));
408+
linkedFile.setLink(newLinkedFile.getLink());
409+
linkedFile.setFileType(newLinkedFile.getFileType());
410+
});
423411
downloadProgress.bind(downloadTask.workDonePercentageProperty());
424412
taskExecutor.execute(downloadTask);
425413
} catch (MalformedURLException exception) {
426414
dialogService.showErrorDialogAndWait(Localization.lang("Invalid URL"), exception);
427415
}
428416
}
429417

418+
public BackgroundTask<Path> prepareDownloadTask(Path targetDirectory, URLDownload urlDownload) {
419+
BackgroundTask<Path> downloadTask = BackgroundTask
420+
.wrap(() -> {
421+
Optional<ExternalFileType> suggestedType = inferFileType(urlDownload);
422+
String suggestedTypeName = suggestedType.map(ExternalFileType::getName).orElse("");
423+
linkedFile.setFileType(suggestedTypeName);
424+
425+
String suggestedName = linkedFileHandler.getSuggestedFileName();
426+
return targetDirectory.resolve(suggestedName);
427+
})
428+
.then(destination -> new FileDownloadTask(urlDownload.getSource(), destination))
429+
.onFailure(exception -> dialogService.showErrorDialogAndWait("Download failed", exception));
430+
return downloadTask;
431+
}
432+
430433
private Optional<ExternalFileType> inferFileType(URLDownload urlDownload) {
431434
Optional<ExternalFileType> suggestedType = inferFileTypeFromMimeType(urlDownload);
432435

src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private void initialize() {
7272

7373
generalFileDirectory.textProperty().bindBidirectional(viewModel.generalFileDirectoryPropertyProperty());
7474
userSpecificFileDirectory.textProperty().bindBidirectional(viewModel.userSpecificFileDirectoryProperty());
75-
laTexFileDirectory.textProperty().bindBidirectional(viewModel.LaTexFileDirectoryProperty());
75+
laTexFileDirectory.textProperty().bindBidirectional(viewModel.laTexFileDirectoryProperty());
7676

7777
encoding.itemsProperty().bind(viewModel.encodingsProperty());
7878
encoding.valueProperty().bindBidirectional(viewModel.selectedEncodingProperty());
@@ -142,7 +142,7 @@ private void storeSettings() {
142142
metaData.setUserFileDirectory(preferencesService.getUser(), text);
143143
}
144144

145-
text = viewModel.LaTexFileDirectoryProperty().getValue();
145+
text = viewModel.laTexFileDirectoryProperty().getValue();
146146
if (text.isEmpty()) {
147147
metaData.clearLaTexFileDirectory(preferencesService.getUser());
148148
} else {
@@ -180,7 +180,7 @@ private void storeSettings() {
180180

181181
boolean changed = saveOrderConfigChanged || encodingChanged
182182
|| viewModel.generalFileDirChanged() || viewModel.userFileDirChanged()
183-
|| viewModel.protectedValueChanged() || saveActionsChanged || viewModel.LaTexFileDirChanged();
183+
|| viewModel.protectedValueChanged() || saveActionsChanged || viewModel.laTexFileDirChanged();
184184
// ... if so, mark base changed. Prevent the Undo button from removing
185185
// change marking:
186186
if (changed) {

src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public StringProperty userSpecificFileDirectoryProperty() {
8080
return this.userSpecificFileDirectoryProperty;
8181
}
8282

83-
public StringProperty LaTexFileDirectoryProperty() {
83+
public StringProperty laTexFileDirectoryProperty() {
8484
return this.laTexFileDirectoryProperty;
8585
}
8686

@@ -116,7 +116,7 @@ public boolean userFileDirChanged() {
116116
return !oldUserSpecificFileDir.equals(userSpecificFileDirectoryProperty.getValue());
117117
}
118118

119-
public boolean LaTexFileDirChanged() {
119+
public boolean laTexFileDirChanged() {
120120
return !oldLaTexFileDir.equals(laTexFileDirectoryProperty.getValue());
121121
}
122122

src/main/java/org/jabref/gui/maintable/PersistenceVisualStateTable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ private void updateColumnPreferences() {
6161
NormalTableColumn normalColumn = (NormalTableColumn) column;
6262

6363
columnNames.add(normalColumn.getColumnName());
64-
columnsWidths.add(String.valueOf(normalColumn.getWidth()));
64+
columnsWidths.add(String.valueOf(Double.valueOf(normalColumn.getWidth()).intValue()));
6565
}
6666
}
6767

68-
if (columnNames.size() == columnsWidths.size() &&
69-
columnNames.size() == preferences.getStringList(JabRefPreferences.COLUMN_NAMES).size()) {
68+
if ((columnNames.size() == columnsWidths.size()) &&
69+
(columnNames.size() == preferences.getStringList(JabRefPreferences.COLUMN_NAMES).size())) {
7070
preferences.putStringList(JabRefPreferences.COLUMN_NAMES, columnNames);
7171
preferences.putStringList(JabRefPreferences.COLUMN_WIDTHS, columnsWidths);
7272
}

src/main/java/org/jabref/gui/preferences/TableColumnsTab.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ public void storeSettings() {
502502

503503
for (TableRow tr : data) {
504504
names.add(tr.getName().toLowerCase(Locale.ROOT));
505-
widths.add(String.valueOf(tr.getLength()));
505+
widths.add(String.valueOf(Double.valueOf(tr.getLength()).intValue()));
506506
}
507507

508508
// Finally, we store the new preferences.
@@ -522,14 +522,14 @@ private void updateOrderAction() {
522522
final HashMap<String, Integer> map = new HashMap<>();
523523

524524
// first element (#) not inside data
525-
/*
526-
for (TableColumn<BibEntry, ?> column : panel.getMainTable().getColumns()) {
527-
String name = column.getText();
528-
if ((name != null) && !name.isEmpty()) {
529-
map.put(name.toLowerCase(Locale.ROOT), i);
530-
}
525+
/*
526+
for (TableColumn<BibEntry, ?> column : panel.getMainTable().getColumns()) {
527+
String name = column.getText();
528+
if ((name != null) && !name.isEmpty()) {
529+
map.put(name.toLowerCase(Locale.ROOT), i);
531530
}
532-
*/
531+
}
532+
*/
533533
data.sort((o1, o2) -> {
534534
Integer n1 = map.get(o1.getName());
535535
Integer n2 = map.get(o2.getName());

src/main/java/org/jabref/logic/auxparser/DefaultAuxParser.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,13 @@
2424
/**
2525
* LaTeX Aux to BibTeX Parser
2626
* <p>
27-
* Extracts a subset of BibTeX entries from a BibDatabase that are included in an AUX file.
28-
* Also supports nested AUX files (latex \\include).
27+
* Extracts a subset of BibTeX entries from a BibDatabase that are included in an AUX file. Also supports nested AUX
28+
* files (latex \\include).
2929
*
30-
* There exists no specification of the AUX file.
31-
* Every package, class or document can write to the AUX file.
32-
* The AUX file consists of LaTeX macros and is read at the \begin{document} and again at the \end{document}.
30+
* There exists no specification of the AUX file. Every package, class or document can write to the AUX file. The AUX
31+
* file consists of LaTeX macros and is read at the \begin{document} and again at the \end{document}.
3332
*
34-
* BibTeX citation: \citation{x,y,z}
35-
* Biblatex citation: \abx@aux@cite{x,y,z}
36-
* Nested AUX files: \@input{x}
33+
* BibTeX citation: \citation{x,y,z} Biblatex citation: \abx@aux@cite{x,y,z} Nested AUX files: \@input{x}
3734
*/
3835
public class DefaultAuxParser implements AuxParser {
3936
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultAuxParser.class);
@@ -128,15 +125,14 @@ private void matchCitation(AuxParserResult result, String line) {
128125
*/
129126
private void resolveTags(AuxParserResult result) {
130127
for (String key : result.getUniqueKeys()) {
131-
Optional<BibEntry> entry = masterDatabase.getEntryByKey(key);
132-
133-
if (result.getGeneratedBibDatabase().getEntryByKey(key).isPresent()) {
134-
// do nothing, key has already been processed
135-
} else if (entry.isPresent()) {
136-
insertEntry(entry.get(), result);
137-
resolveCrossReferences(entry.get(), result);
138-
} else {
139-
result.getUnresolvedKeys().add(key);
128+
if (!result.getGeneratedBibDatabase().getEntryByKey(key).isPresent()) {
129+
Optional<BibEntry> entry = masterDatabase.getEntryByKey(key);
130+
if (entry.isPresent()) {
131+
insertEntry(entry.get(), result);
132+
resolveCrossReferences(entry.get(), result);
133+
} else {
134+
result.getUnresolvedKeys().add(key);
135+
}
140136
}
141137
}
142138

0 commit comments

Comments
 (0)