Skip to content
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 some bugs with PDF imports #12297

Merged
merged 5 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update from code review
  • Loading branch information
InAnYan committed Dec 18, 2024
commit becf8655ead66e4267b344afd7476ef89084f5c6
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import javax.swing.undo.UndoManager;

Expand Down Expand Up @@ -145,42 +144,46 @@ public void startSearch() {
}

public void startImport() {
Path directory = this.getSearchDirectory();
List<Path> fileList = checkedFileListProperty.stream()
.map(item -> item.getValue().getPath())
.filter(path -> path.toFile().isFile())
.collect(Collectors.toList());
List<Path> fileList = checkedFileListProperty
.stream()
.map(TreeItem::getValue)
.map(FileNodeViewModel::getPath)
.filter(Files::isRegularFile)
.toList();

if (fileList.isEmpty()) {
LOGGER.warn("There are no valid files checked");
LOGGER.warn("There are no valid files checked for import");
return;
}
resultList.clear();

importFilesBackgroundTask = importHandler.importFilesInBackground(fileList, bibDatabase, preferences.getFilePreferences(), TransferMode.LINK)
.onRunning(() -> {
progressValueProperty.bind(importFilesBackgroundTask.workDonePercentageProperty());
progressTextProperty.bind(importFilesBackgroundTask.messageProperty());
taskActiveProperty.setValue(true);
})
.onFinished(() -> {
progressValueProperty.unbind();
progressTextProperty.unbind();
taskActiveProperty.setValue(false);
})
.onSuccess(resultList::addAll);
importFilesBackgroundTask = importHandler
.importFilesInBackground(fileList, bibDatabase, preferences.getFilePreferences(), TransferMode.LINK)
.onRunning(() -> {
progressValueProperty.bind(importFilesBackgroundTask.workDonePercentageProperty());
progressTextProperty.bind(importFilesBackgroundTask.messageProperty());
taskActiveProperty.setValue(true);
})
.onFinished(() -> {
progressValueProperty.unbind();
progressTextProperty.unbind();
taskActiveProperty.setValue(false);
})
.onSuccess(resultList::addAll);
importFilesBackgroundTask.executeWith(taskExecutor);
}

/**
* This starts the export of all files of all selected nodes in the file tree view.
*/
public void startExport() {
List<Path> fileList = checkedFileListProperty.stream()
.map(item -> item.getValue().getPath())
.filter(path -> path.toFile().isFile())
.toList();
List<Path> fileList = checkedFileListProperty
.stream()
.map(item -> item.getValue().getPath())
.filter(Files::isRegularFile)
.toList();
if (fileList.isEmpty()) {
LOGGER.warn("There are no valid files checked");
LOGGER.warn("There are no valid files checked for export");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,10 @@ public ParserResult importDatabase(Path filePath) throws IOException {
return new ParserResult(List.of(entry));
}

/**
* A modified version of {@link PdfMergeMetadataImporter#importDatabase(Path)}, but it
* relativizes the {@code filePath} if there are working directories before parsing it
* into {@link PdfMergeMetadataImporter#importDatabase(Path)}
* (Otherwise no path modification happens).
*
* @param filePath The unrelativized {@code filePath}.
*/
public ParserResult importDatabase(Path filePath, BibDatabaseContext context, FilePreferences filePreferences) throws IOException {
Objects.requireNonNull(context);
Objects.requireNonNull(filePreferences);

List<Path> directories = context.getFileDirectories(filePreferences);

// filePath = FileUtil.relativize(filePath, directories);

return importDatabase(filePath);
}

Expand Down
Loading