Search in sources :

Example 1 with DeleteBatchJobStatus

use of com.dropbox.core.v2.files.DeleteBatchJobStatus in project cyberduck by iterate-ch.

the class DropboxBatchDeleteFeature method delete.

@Override
public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException {
    final ScheduledThreadPool scheduler = new ScheduledThreadPool();
    try {
        for (Path f : files.keySet()) {
            callback.delete(f);
        }
        final DbxUserFilesRequests requests = new DbxUserFilesRequests(session.getClient());
        final DeleteBatchLaunch job = requests.deleteBatch(files.keySet().stream().map(f -> new DeleteArg(f.getAbsolute())).collect(Collectors.toList()));
        final CountDownLatch signal = new CountDownLatch(1);
        final AtomicReference<BackgroundException> failure = new AtomicReference<>();
        scheduler.repeat(() -> {
            try {
                // Poll status
                final DeleteBatchJobStatus status = requests.deleteBatchCheck(job.getAsyncJobIdValue());
                if (status.isComplete()) {
                    final List<DeleteBatchResultEntry> entries = status.getCompleteValue().getEntries();
                    for (DeleteBatchResultEntry entry : entries) {
                        if (entry.isFailure()) {
                            switch(entry.getFailureValue().tag()) {
                                case PATH_LOOKUP:
                                    failure.set(new NotfoundException(entry.getFailureValue().toString()));
                                    break;
                                default:
                                    failure.set(new InteroperabilityException());
                            }
                        }
                    }
                    signal.countDown();
                }
                if (status.isFailed()) {
                    signal.countDown();
                }
            } catch (DbxException e) {
                failure.set(new DropboxExceptionMappingService().map(e));
                signal.countDown();
            }
        }, new HostPreferences(session.getHost()).getLong("dropbox.delete.poll.interval.ms"), TimeUnit.MILLISECONDS);
        Uninterruptibles.awaitUninterruptibly(signal);
        if (null != failure.get()) {
            throw failure.get();
        }
    } catch (DbxException e) {
        throw new DropboxExceptionMappingService().map(e);
    } finally {
        scheduler.shutdown();
    }
}
Also used : Path(ch.cyberduck.core.Path) DeleteBatchResultEntry(com.dropbox.core.v2.files.DeleteBatchResultEntry) NotfoundException(ch.cyberduck.core.exception.NotfoundException) InteroperabilityException(ch.cyberduck.core.exception.InteroperabilityException) DeleteBatchJobStatus(com.dropbox.core.v2.files.DeleteBatchJobStatus) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) DbxUserFilesRequests(com.dropbox.core.v2.files.DbxUserFilesRequests) ScheduledThreadPool(ch.cyberduck.core.threading.ScheduledThreadPool) DeleteBatchLaunch(com.dropbox.core.v2.files.DeleteBatchLaunch) DeleteArg(com.dropbox.core.v2.files.DeleteArg) BackgroundException(ch.cyberduck.core.exception.BackgroundException) DbxException(com.dropbox.core.DbxException)

Aggregations

Path (ch.cyberduck.core.Path)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)1 NotfoundException (ch.cyberduck.core.exception.NotfoundException)1 HostPreferences (ch.cyberduck.core.preferences.HostPreferences)1 ScheduledThreadPool (ch.cyberduck.core.threading.ScheduledThreadPool)1 DbxException (com.dropbox.core.DbxException)1 DbxUserFilesRequests (com.dropbox.core.v2.files.DbxUserFilesRequests)1 DeleteArg (com.dropbox.core.v2.files.DeleteArg)1 DeleteBatchJobStatus (com.dropbox.core.v2.files.DeleteBatchJobStatus)1 DeleteBatchLaunch (com.dropbox.core.v2.files.DeleteBatchLaunch)1 DeleteBatchResultEntry (com.dropbox.core.v2.files.DeleteBatchResultEntry)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1