use of com.dropbox.core.v2.files.DeleteBatchLaunch 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();
}
}
Aggregations