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

[WIP] Fix issue no warning message #11904

Closed
Closed
Show file tree
Hide file tree
Changes from 6 commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where the Undo/Redo buttons were active even when all libraries are closed. [#11837](https://github.com/JabRef/jabref/issues/11837)
- We fixed an issue where recently opened files were not displayed in the main menu properly. [#9042](https://github.com/JabRef/jabref/issues/9042)
- We fixed an issue where the DOI lookup would show an error when a DOI was found for an entry. [#11850](https://github.com/JabRef/jabref/issues/11850)
- We fixed an issue where we display warning message for moving attached open files. [#10121](https://github.com/JabRef/jabref/issues/10121)

### Removed

Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/jabref/gui/cleanup/CleanupAction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.gui.cleanup;

import java.nio.file.FileSystemException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
Expand Down Expand Up @@ -31,6 +33,7 @@ public class CleanupAction extends SimpleCommand {
private final StateManager stateManager;
private final TaskExecutor taskExecutor;
private final UndoManager undoManager;
private List<FileSystemException> exceptions;

private boolean isCanceled;
private int modifiedEntriesCount;
Expand All @@ -47,6 +50,7 @@ public CleanupAction(Supplier<LibraryTab> tabSupplier,
this.stateManager = stateManager;
this.taskExecutor = taskExecutor;
this.undoManager = undoManager;
this.exceptions = new ArrayList<>();

this.executable.bind(ActionHelper.needsEntriesSelected(stateManager));
}
Expand Down Expand Up @@ -113,6 +117,8 @@ private void doCleanup(BibDatabaseContext databaseContext, CleanupPreferences pr
for (FieldChange change : changes) {
ce.addEdit(new UndoableFieldChange(change));
}

exceptions = cleaner.getFileSystemExceptions();
}

private void showResults() {
Expand All @@ -132,6 +138,20 @@ private void showResults() {
} else {
dialogService.notify(Localization.lang("%0 entries needed a clean up", Integer.toString(modifiedEntriesCount)));
}

if (!exceptions.isEmpty()) {
showExceptions();
}
}

private void showExceptions() {
StringBuilder sb = new StringBuilder();
sb.append(Localization.lang("The following errors occurred while moving files:")).append("\n\n");
for (FileSystemException exception : exceptions) {
FileSystemException fse = exception;
sb.append("- ").append(Localization.lang("Could not move file %0. Please close this file and retry.", fse.getFile())).append("\n");
}
dialogService.showErrorDialogAndWait(Localization.lang("File Move Errors"), sb.toString());
}

private void cleanup(BibDatabaseContext databaseContext, CleanupPreferences cleanupPreferences) {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/jabref/logic/cleanup/CleanupWorker.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.logic.cleanup;

import java.nio.file.FileSystemException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand All @@ -15,11 +16,13 @@ public class CleanupWorker {
private final BibDatabaseContext databaseContext;
private final FilePreferences filePreferences;
private final TimestampPreferences timestampPreferences;
private final List<FileSystemException> fileSystemExceptions;

public CleanupWorker(BibDatabaseContext databaseContext, FilePreferences filePreferences, TimestampPreferences timestampPreferences) {
this.databaseContext = databaseContext;
this.filePreferences = filePreferences;
this.timestampPreferences = timestampPreferences;
this.fileSystemExceptions = new ArrayList<>();
}

public List<FieldChange> cleanup(CleanupPreferences preset, BibEntry entry) {
Expand All @@ -31,6 +34,10 @@ public List<FieldChange> cleanup(CleanupPreferences preset, BibEntry entry) {
List<FieldChange> changes = new ArrayList<>();
for (CleanupJob job : jobs) {
changes.addAll(job.cleanup(entry));

if (job instanceof MoveFilesCleanup) {
fileSystemExceptions.addAll(((MoveFilesCleanup) job).getFileSystemExceptions());
}
}

return changes;
Expand Down Expand Up @@ -86,4 +93,8 @@ private CleanupJob toJob(CleanupPreferences.CleanupStep action) {
throw new UnsupportedOperationException(action.name());
};
}

public List<FileSystemException> getFileSystemExceptions() {
return fileSystemExceptions;
}
}
11 changes: 10 additions & 1 deletion src/main/java/org/jabref/logic/cleanup/MoveFilesCleanup.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.jabref.logic.cleanup;

import java.io.IOException;
import java.nio.file.FileSystemException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
Expand All @@ -18,15 +20,16 @@
import org.slf4j.LoggerFactory;

public class MoveFilesCleanup implements CleanupJob {

private static final Logger LOGGER = LoggerFactory.getLogger(MoveFilesCleanup.class);

private final BibDatabaseContext databaseContext;
private final FilePreferences filePreferences;
private final List<FileSystemException> fileSystemExceptions;

public MoveFilesCleanup(BibDatabaseContext databaseContext, FilePreferences filePreferences) {
this.databaseContext = Objects.requireNonNull(databaseContext);
this.filePreferences = Objects.requireNonNull(filePreferences);
this.fileSystemExceptions = new ArrayList<>();
}

@Override
Expand All @@ -41,6 +44,8 @@ public List<FieldChange> cleanup(BibEntry entry) {
if (fileChanged) {
changed = true;
}
} catch (FileSystemException exception) {
fileSystemExceptions.add(exception);
Comment on lines +47 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not adding all IOException? They are logged below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this change based on the previous PR (#11484). I also think that it's better to add all of IOException.

Thanks for the input.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think, we overlooked that thing in the PR (because of other comments 😅).

Side thing: Don't forget to run the OpenRewrite task and check checkstyle 😅

} catch (IOException exception) {
LOGGER.error("Error while moving file {}", file.getLink(), exception);
}
Expand All @@ -53,4 +58,8 @@ public List<FieldChange> cleanup(BibEntry entry) {

return Collections.emptyList();
}

public List<FileSystemException> getFileSystemExceptions() {
return fileSystemExceptions;
}
}
4 changes: 4 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2797,3 +2797,7 @@ Warning\:\ The\ selected\ directory\ is\ not\ a\ valid\ directory.=Warning: The
Currently\ selected\ JStyle\:\ '%0' = Currently selected JStyle: '%0'
Currently\ selected\ CSL\ Style\:\ '%0' = Currently selected CSL Style: '%0'
Store\ url\ for\ downloaded\ file=Store url for downloaded file

File\ Move\ Errors=File Move Errors
Could\ not\ move\ file\ %0.\ Please\ close\ this\ file\ and\ retry.=Could not move file %0. Please close this file and retry.
The\ following\ errors\ occurred\ while\ moving\ files:=The following errors occurred while moving files:
Loading