use of com.dropbox.core.v2.files.DbxUserFilesRequests 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();
}
}
use of com.dropbox.core.v2.files.DbxUserFilesRequests in project cyberduck by iterate-ch.
the class DropboxSearchFeature method search.
@Override
public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException {
try {
final AttributedList<Path> list = new AttributedList<>();
long start = 0;
SearchV2Result result = new DbxUserFilesRequests(session.getClient(workdir)).searchV2Builder(regex.toPattern().pattern()).withOptions(SearchOptions.newBuilder().withPath(containerService.getKey(workdir)).build()).start();
this.parse(workdir, listener, list, result);
while (result.getHasMore()) {
this.parse(workdir, listener, list, result = new DbxUserFilesRequests(session.getClient(workdir)).searchContinueV2(result.getCursor()));
if (this.parse(workdir, listener, list, result)) {
return null;
}
}
return list;
} catch (DbxException e) {
throw new DropboxExceptionMappingService().map("Failure to read attributes of {0}", e, workdir);
}
}
use of com.dropbox.core.v2.files.DbxUserFilesRequests in project cyberduck by iterate-ch.
the class DropboxTemporaryUrlProvider method toDownloadUrl.
@Override
public DescriptiveUrl toDownloadUrl(final Path file, final Void options, final PasswordCallback callback) throws BackgroundException {
try {
if (log.isDebugEnabled()) {
log.debug(String.format("Create temporary link for %s", file));
}
// This link will expire in four hours and afterwards you will get 410 Gone.
final String link = new DbxUserFilesRequests(session.getClient(file)).getTemporaryLink(containerService.getKey(file)).getLink();
// Determine expiry time for URL
final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
expiry.add(Calendar.HOUR, 4);
return new DescriptiveUrl(URI.create(link), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Temporary", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())));
} catch (DbxException e) {
throw new DropboxExceptionMappingService().map(e);
}
}
use of com.dropbox.core.v2.files.DbxUserFilesRequests in project cyberduck by iterate-ch.
the class DropboxWriteFeature method write.
@Override
public HttpResponseOutputStream<Metadata> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
try {
final DbxUserFilesRequests files = new DbxUserFilesRequests(session.getClient(file));
final UploadSessionStartUploader start = files.uploadSessionStart();
new DefaultStreamCloser().close(start.getOutputStream());
final String sessionId = start.finish().getSessionId();
if (log.isDebugEnabled()) {
log.debug(String.format("Obtained session id %s for upload %s", sessionId, file));
}
final UploadSessionAppendV2Uploader uploader = open(files, sessionId, 0L);
return new SegmentingUploadProxyOutputStream(file, status, files, uploader, sessionId);
} catch (DbxException ex) {
throw new DropboxExceptionMappingService().map("Upload failed.", ex, file);
}
}
use of com.dropbox.core.v2.files.DbxUserFilesRequests in project cyberduck by iterate-ch.
the class DropboxReadFeature method read.
@Override
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
try {
final DownloadBuilder builder = new DbxUserFilesRequests(session.getClient(file)).downloadBuilder(containerService.getKey(file));
if (status.isAppend()) {
final HttpRange range = HttpRange.withStatus(status);
builder.range(range.getStart());
}
final DbxDownloader<FileMetadata> downloader = builder.start();
return downloader.getInputStream();
} catch (DbxException e) {
throw new DropboxExceptionMappingService().map("Download {0} failed", e, file);
}
}
Aggregations