Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesImportTask.java')
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesImportTask.java57
1 files changed, 34 insertions, 23 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesImportTask.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesImportTask.java
index acdf1441..38172b94 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesImportTask.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesImportTask.java
@@ -53,30 +53,41 @@ public class NotesImportTask {
executor.submit(() -> {
Log.i(TAG, "… Fetching notes IDs");
final var status = new ImportStatus();
- final var remoteIds = notesAPI.getNotesIDs().blockingSingle();
- status.total = remoteIds.size();
- status$.postValue(status);
- Log.i(TAG, "… Total count: " + remoteIds.size());
- final var latch = new CountDownLatch(remoteIds.size());
- for (long id : remoteIds) {
- fetchExecutor.submit(() -> {
- try {
- repo.addNote(localAccount.getId(), notesAPI.getNote(id).blockingSingle().getResponse());
- } catch (Throwable t) {
- Log.w(TAG, "Could not import note with remoteId " + id + ": " + t.getMessage());
- status.warnings.add(t);
- }
- status.count++;
- status$.postValue(status);
- latch.countDown();
- });
- }
try {
- latch.await();
- Log.i(TAG, "IMPORT FINISHED");
- callback.onSuccess(null);
- } catch (InterruptedException e) {
- callback.onError(e);
+ final var remoteIds = notesAPI.getNotesIDs().blockingSingle();
+ status.total = remoteIds.size();
+ status$.postValue(status);
+ Log.i(TAG, "… Total count: " + remoteIds.size());
+ final var latch = new CountDownLatch(remoteIds.size());
+ for (long id : remoteIds) {
+ fetchExecutor.submit(() -> {
+ try {
+ repo.addNote(localAccount.getId(), notesAPI.getNote(id).blockingSingle().getResponse());
+ } catch (Throwable t) {
+ Log.w(TAG, "Could not import note with remoteId " + id + ": " + t.getMessage());
+ status.warnings.add(t);
+ }
+ status.count++;
+ status$.postValue(status);
+ latch.countDown();
+ });
+ }
+ try {
+ latch.await();
+ Log.i(TAG, "IMPORT FINISHED");
+ callback.onSuccess(null);
+ } catch (InterruptedException e) {
+ callback.onError(e);
+ }
+ } catch (Throwable t) {
+ final Throwable cause = t.getCause();
+ if (t.getClass() == RuntimeException.class && cause != null) {
+ Log.e(TAG, "Could not fetch list of note IDs: " + cause.getMessage());
+ callback.onError(cause);
+ } else {
+ Log.e(TAG, "Could not fetch list of note IDs: " + t.getMessage());
+ callback.onError(t);
+ }
}
});
return status$;