Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into convertSearchWorker
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
Siedlerchr committed Apr 20, 2019
2 parents b2971ed + 1c11575 commit 6342c8f
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 76 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ dependencies {

compile 'commons-cli:commons-cli:1.4'

compile "org.libreoffice:juh:6.2.2"
compile "org.libreoffice:jurt:6.2.2"
compile "org.libreoffice:ridl:6.2.2"
compile "org.libreoffice:unoil:6.2.2"
compile "org.libreoffice:juh:6.2.3"
compile "org.libreoffice:jurt:6.2.3"
compile "org.libreoffice:ridl:6.2.3"
compile "org.libreoffice:unoil:6.2.3"

compile 'io.github.java-diff-utils:java-diff-utils:4.0'
compile 'info.debatty:java-string-similarity:1.2.1'
Expand All @@ -130,7 +130,7 @@ dependencies {
compile 'de.saxsys:mvvmfx:1.8.0'
compile 'org.fxmisc.easybind:easybind:1.0.3'
compile 'org.fxmisc.flowless:flowless:0.6.1'
compile 'org.fxmisc.richtext:richtextfx:0.9.3'
compile 'org.fxmisc.richtext:richtextfx:0.10.0'
compile 'com.sibvisions.external.jvxfx:dndtabpane:0.1'
compile 'javax.inject:javax.inject:1'
compile 'com.jfoenix:jfoenix:8.0.8'
Expand Down
66 changes: 46 additions & 20 deletions src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package org.jabref.gui.externalfiles;

import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

import javafx.concurrent.Task;

import org.jabref.Globals;
import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.fieldeditors.LinkedFileViewModel;
import org.jabref.gui.fieldeditors.LinkedFilesEditorViewModel;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.logic.importer.FulltextFetchers;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.net.URLDownload;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.LinkedFile;
import org.jabref.preferences.JabRefPreferences;
Expand Down Expand Up @@ -63,18 +68,29 @@ public void execute() {
return;
}
}
BackgroundTask.wrap(this::findFullTexts)
.onSuccess(this::downloadFullTexts)
.executeWith(Globals.TASK_EXECUTOR);
}

private Map<Optional<URL>, BibEntry> findFullTexts() {
Map<Optional<URL>, BibEntry> downloads = new ConcurrentHashMap<>();
for (BibEntry entry : basePanel.getSelectedEntries()) {
FulltextFetchers fetchers = new FulltextFetchers(Globals.prefs.getImportFormatPreferences());
downloads.put(fetchers.findFullTextPDF(entry), entry);
}
return downloads;
Task<Map<Optional<URL>, BibEntry>> findFullTextsTask = new Task<Map<Optional<URL>, BibEntry>>() {
@Override
protected Map<Optional<URL>, BibEntry> call() {
Map<Optional<URL>, BibEntry> downloads = new ConcurrentHashMap<>();
int count = 0;
for (BibEntry entry : basePanel.getSelectedEntries()) {
FulltextFetchers fetchers = new FulltextFetchers(Globals.prefs.getImportFormatPreferences());
downloads.put(fetchers.findFullTextPDF(entry), entry);
updateProgress(++count, basePanel.getSelectedEntries().size());
}
return downloads;
}
};

findFullTextsTask.setOnSucceeded(value -> downloadFullTexts(findFullTextsTask.getValue()));

dialogService.showProgressDialogAndWait(
Localization.lang("Look up full text documents"),
Localization.lang("Looking for full text document..."),
findFullTextsTask);

Globals.TASK_EXECUTOR.execute(findFullTextsTask);
}

private void downloadFullTexts(Map<Optional<URL>, BibEntry> downloads) {
Expand All @@ -92,7 +108,7 @@ private void downloadFullTexts(Map<Optional<URL>, BibEntry> downloads) {
return;
}
//Download and link full text
addLinkedFileFromURL(result.get(), entry);
addLinkedFileFromURL(result.get(), entry, dir.get());

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

/**
* This method attaches a linked file from a URL (if not already linked) to an entry using the key and value pair
* from the findFullTexts map
* from the findFullTexts map and then downloads the file into the given targetDirectory
*
* @param url the url "key"
* @param entry the entry "value"
* @param targetDirectory the target directory for the downloaded file
*/
private void addLinkedFileFromURL(URL url, BibEntry entry) {
private void addLinkedFileFromURL(URL url, BibEntry entry, Path targetDirectory) {
LinkedFile newLinkedFile = new LinkedFile(url, "");

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

onlineFile.download();

entry.addFile(onlineFile.getFile());

dialogService.notify(Localization.lang("Finished downloading full text document for entry %0.",
entry.getCiteKeyOptional().orElse(Localization.lang("undefined"))));
try {
URLDownload urlDownload = new URLDownload(newLinkedFile.getLink());
BackgroundTask<Path> downloadTask = onlineFile.prepareDownloadTask(targetDirectory, urlDownload);
downloadTask.onSuccess(destination -> {
LinkedFile downloadedFile = LinkedFilesEditorViewModel.fromFile(
destination,
basePanel.getBibDatabaseContext().getFileDirectoriesAsPaths(JabRefPreferences.getInstance().getFilePreferences()));
entry.addFile(downloadedFile);
dialogService.notify(Localization.lang("Finished downloading full text document for entry %0.",
entry.getCiteKeyOptional().orElse(Localization.lang("undefined"))));
});
Globals.TASK_EXECUTOR.execute(downloadTask);
} catch (MalformedURLException exception) {
dialogService.showErrorDialogAndWait(Localization.lang("Invalid URL"), exception);
}
} else {
dialogService.notify(Localization.lang("Full text document for entry %0 already linked.",
entry.getCiteKeyOptional().orElse(Localization.lang("undefined"))));
Expand Down
39 changes: 21 additions & 18 deletions src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ 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.isPresent()) {
Expand All @@ -403,30 +402,34 @@ public void download() {
}

URLDownload urlDownload = new URLDownload(linkedFile.getLink());
BackgroundTask<Path> downloadTask = BackgroundTask
.wrap(() -> {
Optional<ExternalFileType> suggestedType = inferFileType(urlDownload);
String suggestedTypeName = suggestedType.map(ExternalFileType::getName).orElse("");
linkedFile.setFileType(suggestedTypeName);

String suggestedName = linkedFileHandler.getSuggestedFileName();
return targetDirectory.get().resolve(suggestedName);
})
.then(destination -> new FileDownloadTask(urlDownload.getSource(), destination))
.onSuccess(destination -> {
LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectoriesAsPaths(filePreferences));
linkedFile.setLink(newLinkedFile.getLink());
linkedFile.setFileType(newLinkedFile.getFileType());
})
.onFailure(exception -> dialogService.showErrorDialogAndWait("Download failed", exception));

BackgroundTask<Path> downloadTask = prepareDownloadTask(targetDirectory.get(), urlDownload);
downloadTask.onSuccess(destination -> {
LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectoriesAsPaths(filePreferences));
linkedFile.setLink(newLinkedFile.getLink());
linkedFile.setFileType(newLinkedFile.getFileType());
});
downloadProgress.bind(downloadTask.workDonePercentageProperty());
taskExecutor.execute(downloadTask);
} catch (MalformedURLException exception) {
dialogService.showErrorDialogAndWait(Localization.lang("Invalid URL"), exception);
}
}

public BackgroundTask<Path> prepareDownloadTask(Path targetDirectory, URLDownload urlDownload) {
BackgroundTask<Path> downloadTask = BackgroundTask
.wrap(() -> {
Optional<ExternalFileType> suggestedType = inferFileType(urlDownload);
String suggestedTypeName = suggestedType.map(ExternalFileType::getName).orElse("");
linkedFile.setFileType(suggestedTypeName);

String suggestedName = linkedFileHandler.getSuggestedFileName();
return targetDirectory.resolve(suggestedName);
})
.then(destination -> new FileDownloadTask(urlDownload.getSource(), destination))
.onFailure(exception -> dialogService.showErrorDialogAndWait("Download failed", exception));
return downloadTask;
}

private Optional<ExternalFileType> inferFileType(URLDownload urlDownload) {
Optional<ExternalFileType> suggestedType = inferFileTypeFromMimeType(urlDownload);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void initialize() {

generalFileDirectory.textProperty().bindBidirectional(viewModel.generalFileDirectoryPropertyProperty());
userSpecificFileDirectory.textProperty().bindBidirectional(viewModel.userSpecificFileDirectoryProperty());
laTexFileDirectory.textProperty().bindBidirectional(viewModel.LaTexFileDirectoryProperty());
laTexFileDirectory.textProperty().bindBidirectional(viewModel.laTexFileDirectoryProperty());

encoding.itemsProperty().bind(viewModel.encodingsProperty());
encoding.valueProperty().bindBidirectional(viewModel.selectedEncodingProperty());
Expand Down Expand Up @@ -142,7 +142,7 @@ private void storeSettings() {
metaData.setUserFileDirectory(preferencesService.getUser(), text);
}

text = viewModel.LaTexFileDirectoryProperty().getValue();
text = viewModel.laTexFileDirectoryProperty().getValue();
if (text.isEmpty()) {
metaData.clearLaTexFileDirectory(preferencesService.getUser());
} else {
Expand Down Expand Up @@ -180,7 +180,7 @@ private void storeSettings() {

boolean changed = saveOrderConfigChanged || encodingChanged
|| viewModel.generalFileDirChanged() || viewModel.userFileDirChanged()
|| viewModel.protectedValueChanged() || saveActionsChanged || viewModel.LaTexFileDirChanged();
|| viewModel.protectedValueChanged() || saveActionsChanged || viewModel.laTexFileDirChanged();
// ... if so, mark base changed. Prevent the Undo button from removing
// change marking:
if (changed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public StringProperty userSpecificFileDirectoryProperty() {
return this.userSpecificFileDirectoryProperty;
}

public StringProperty LaTexFileDirectoryProperty() {
public StringProperty laTexFileDirectoryProperty() {
return this.laTexFileDirectoryProperty;
}

Expand Down Expand Up @@ -116,7 +116,7 @@ public boolean userFileDirChanged() {
return !oldUserSpecificFileDir.equals(userSpecificFileDirectoryProperty.getValue());
}

public boolean LaTexFileDirChanged() {
public boolean laTexFileDirChanged() {
return !oldLaTexFileDir.equals(laTexFileDirectoryProperty.getValue());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ private void updateColumnPreferences() {
NormalTableColumn normalColumn = (NormalTableColumn) column;

columnNames.add(normalColumn.getColumnName());
columnsWidths.add(String.valueOf(normalColumn.getWidth()));
columnsWidths.add(String.valueOf(Double.valueOf(normalColumn.getWidth()).intValue()));
}
}

if (columnNames.size() == columnsWidths.size() &&
columnNames.size() == preferences.getStringList(JabRefPreferences.COLUMN_NAMES).size()) {
if ((columnNames.size() == columnsWidths.size()) &&
(columnNames.size() == preferences.getStringList(JabRefPreferences.COLUMN_NAMES).size())) {
preferences.putStringList(JabRefPreferences.COLUMN_NAMES, columnNames);
preferences.putStringList(JabRefPreferences.COLUMN_WIDTHS, columnsWidths);
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/jabref/gui/preferences/TableColumnsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public void storeSettings() {

for (TableRow tr : data) {
names.add(tr.getName().toLowerCase(Locale.ROOT));
widths.add(String.valueOf(tr.getLength()));
widths.add(String.valueOf(Double.valueOf(tr.getLength()).intValue()));
}

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

// first element (#) not inside data
/*
for (TableColumn<BibEntry, ?> column : panel.getMainTable().getColumns()) {
String name = column.getText();
if ((name != null) && !name.isEmpty()) {
map.put(name.toLowerCase(Locale.ROOT), i);
}
/*
for (TableColumn<BibEntry, ?> column : panel.getMainTable().getColumns()) {
String name = column.getText();
if ((name != null) && !name.isEmpty()) {
map.put(name.toLowerCase(Locale.ROOT), i);
}
*/
}
*/
data.sort((o1, o2) -> {
Integer n1 = map.get(o1.getName());
Integer n2 = map.get(o2.getName());
Expand Down
30 changes: 13 additions & 17 deletions src/main/java/org/jabref/logic/auxparser/DefaultAuxParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@
/**
* LaTeX Aux to BibTeX Parser
* <p>
* Extracts a subset of BibTeX entries from a BibDatabase that are included in an AUX file.
* Also supports nested AUX files (latex \\include).
* Extracts a subset of BibTeX entries from a BibDatabase that are included in an AUX file. Also supports nested AUX
* files (latex \\include).
*
* There exists no specification of the AUX file.
* Every package, class or document can write to the AUX file.
* The AUX file consists of LaTeX macros and is read at the \begin{document} and again at the \end{document}.
* There exists no specification of the AUX file. Every package, class or document can write to the AUX file. The AUX
* file consists of LaTeX macros and is read at the \begin{document} and again at the \end{document}.
*
* BibTeX citation: \citation{x,y,z}
* Biblatex citation: \abx@aux@cite{x,y,z}
* Nested AUX files: \@input{x}
* BibTeX citation: \citation{x,y,z} Biblatex citation: \abx@aux@cite{x,y,z} Nested AUX files: \@input{x}
*/
public class DefaultAuxParser implements AuxParser {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultAuxParser.class);
Expand Down Expand Up @@ -128,15 +125,14 @@ private void matchCitation(AuxParserResult result, String line) {
*/
private void resolveTags(AuxParserResult result) {
for (String key : result.getUniqueKeys()) {
Optional<BibEntry> entry = masterDatabase.getEntryByKey(key);

if (result.getGeneratedBibDatabase().getEntryByKey(key).isPresent()) {
// do nothing, key has already been processed
} else if (entry.isPresent()) {
insertEntry(entry.get(), result);
resolveCrossReferences(entry.get(), result);
} else {
result.getUnresolvedKeys().add(key);
if (!result.getGeneratedBibDatabase().getEntryByKey(key).isPresent()) {
Optional<BibEntry> entry = masterDatabase.getEntryByKey(key);
if (entry.isPresent()) {
insertEntry(entry.get(), result);
resolveCrossReferences(entry.get(), result);
} else {
result.getUnresolvedKeys().add(key);
}
}
}

Expand Down

0 comments on commit 6342c8f

Please sign in to comment.