Search in sources :

Example 1 with DbxUserFilesRequests

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();
    }
}
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)

Example 2 with DbxUserFilesRequests

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);
    }
}
Also used : Path(ch.cyberduck.core.Path) DbxUserFilesRequests(com.dropbox.core.v2.files.DbxUserFilesRequests) AttributedList(ch.cyberduck.core.AttributedList) SearchV2Result(com.dropbox.core.v2.files.SearchV2Result) DbxException(com.dropbox.core.DbxException)

Example 3 with DbxUserFilesRequests

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);
    }
}
Also used : DbxUserFilesRequests(com.dropbox.core.v2.files.DbxUserFilesRequests) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) Calendar(java.util.Calendar) DbxException(com.dropbox.core.DbxException)

Example 4 with DbxUserFilesRequests

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);
    }
}
Also used : DbxUserFilesRequests(com.dropbox.core.v2.files.DbxUserFilesRequests) UploadSessionAppendV2Uploader(com.dropbox.core.v2.files.UploadSessionAppendV2Uploader) DefaultStreamCloser(ch.cyberduck.core.io.DefaultStreamCloser) UploadSessionStartUploader(com.dropbox.core.v2.files.UploadSessionStartUploader) DbxException(com.dropbox.core.DbxException)

Example 5 with DbxUserFilesRequests

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);
    }
}
Also used : DownloadBuilder(com.dropbox.core.v2.files.DownloadBuilder) DbxUserFilesRequests(com.dropbox.core.v2.files.DbxUserFilesRequests) FileMetadata(com.dropbox.core.v2.files.FileMetadata) DbxException(com.dropbox.core.DbxException) HttpRange(ch.cyberduck.core.http.HttpRange)

Aggregations

DbxException (com.dropbox.core.DbxException)9 DbxUserFilesRequests (com.dropbox.core.v2.files.DbxUserFilesRequests)8 Path (ch.cyberduck.core.Path)3 AttributedList (ch.cyberduck.core.AttributedList)2 FileMetadata (com.dropbox.core.v2.files.FileMetadata)2 ListFolderResult (com.dropbox.core.v2.files.ListFolderResult)2 IOException (java.io.IOException)2 DescriptiveUrl (ch.cyberduck.core.DescriptiveUrl)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)1 NotfoundException (ch.cyberduck.core.exception.NotfoundException)1 Delete (ch.cyberduck.core.features.Delete)1 HttpRange (ch.cyberduck.core.http.HttpRange)1 DefaultStreamCloser (ch.cyberduck.core.io.DefaultStreamCloser)1 HostPreferences (ch.cyberduck.core.preferences.HostPreferences)1 ScheduledThreadPool (ch.cyberduck.core.threading.ScheduledThreadPool)1 DbxClientV2 (com.dropbox.core.v2.DbxClientV2)1 DbxRawClientV2 (com.dropbox.core.v2.DbxRawClientV2)1 CommitInfo (com.dropbox.core.v2.files.CommitInfo)1 CreateFolderResult (com.dropbox.core.v2.files.CreateFolderResult)1