Search in sources :

Example 1 with ApiException

use of ch.cyberduck.core.box.io.swagger.client.ApiException in project cyberduck by iterate-ch.

the class BoxListService method list.

protected AttributedList<Path> list(final Path directory, final ListProgressListener listener, final int chunksize) throws BackgroundException {
    try {
        final AttributedList<Path> list = new AttributedList<>();
        int offset = 0;
        Items items;
        do {
            items = new FoldersApi(new BoxApiClient(session.getClient())).getFoldersIdItems(directory.isRoot() ? "0" : fileid.getFileId(directory, listener), BoxAttributesFinderFeature.DEFAULT_FIELDS, false, null, (long) offset, (long) chunksize, StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY);
            for (Object entry : items.getEntries()) {
                if (!(entry instanceof Map)) {
                    log.error(String.format("Unexpected entry %s", entry));
                    continue;
                }
                final Object type = ((Map) entry).get("type");
                if (!(type instanceof String)) {
                    log.error(String.format("Missing type %s", type));
                    continue;
                }
                switch(type.toString()) {
                    case "file":
                        final File file = new JSON().getContext(null).readValue(new JSON().getContext(null).writeValueAsString(entry), File.class);
                        list.add(new Path(directory, file.getName(), EnumSet.of(Path.Type.file), attributes.toAttributes(file)));
                        break;
                    case "folder":
                        final Folder folder = new JSON().getContext(null).readValue(new JSON().getContext(null).writeValueAsString(entry), Folder.class);
                        list.add(new Path(directory, folder.getName(), EnumSet.of(Path.Type.directory), attributes.toAttributes(folder)));
                        break;
                }
                listener.chunk(directory, list);
            }
            offset += chunksize;
        } while (items.getEntries().size() == chunksize);
        return list;
    } catch (ApiException e) {
        throw new BoxExceptionMappingService(fileid).map("Listing directory {0} failed", e, directory);
    } catch (JsonProcessingException e) {
        throw new DefaultIOExceptionMappingService().map("Listing directory {0} failed", e, directory);
    }
}
Also used : Path(ch.cyberduck.core.Path) JSON(ch.cyberduck.core.box.io.swagger.client.JSON) Folder(ch.cyberduck.core.box.io.swagger.client.model.Folder) FoldersApi(ch.cyberduck.core.box.io.swagger.client.api.FoldersApi) AttributedList(ch.cyberduck.core.AttributedList) Items(ch.cyberduck.core.box.io.swagger.client.model.Items) DefaultIOExceptionMappingService(ch.cyberduck.core.DefaultIOExceptionMappingService) Map(java.util.Map) File(ch.cyberduck.core.box.io.swagger.client.model.File) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ApiException(ch.cyberduck.core.box.io.swagger.client.ApiException)

Example 2 with ApiException

use of ch.cyberduck.core.box.io.swagger.client.ApiException in project cyberduck by iterate-ch.

the class BoxSession method login.

@Override
public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
    authorizationService.setTokens(authorizationService.authorize(host, prompt, cancel, OAuth2AuthorizationService.FlowType.AuthorizationCode));
    try {
        final Credentials credentials = host.getCredentials();
        credentials.setUsername(new UsersApi(new BoxApiClient(client)).getUsersMe(Collections.emptyList()).getLogin());
        credentials.setSaved(true);
    } catch (ApiException e) {
        throw new BoxExceptionMappingService(fileid).map(e);
    }
}
Also used : UsersApi(ch.cyberduck.core.box.io.swagger.client.api.UsersApi) Credentials(ch.cyberduck.core.Credentials) ApiException(ch.cyberduck.core.box.io.swagger.client.ApiException)

Example 3 with ApiException

use of ch.cyberduck.core.box.io.swagger.client.ApiException in project cyberduck by iterate-ch.

the class BoxShareFeature method createFileSharedLink.

private DescriptiveUrl createFileSharedLink(final Path file, final PasswordCallback callback) throws BackgroundException {
    try {
        final String password = this.prompt(file, callback);
        final File link = new SharedLinksFilesApi(new BoxApiClient(session.getClient())).putFilesIdAddSharedLink("shared_link", fileid.getFileId(file, new DisabledListProgressListener()), new FilesFileIdaddSharedLinkBody().sharedLink(new FilesfileIdaddSharedLinkSharedLink().password(password)));
        return new DescriptiveUrl(URI.create(link.getSharedLink().getDownloadUrl()), DescriptiveUrl.Type.signed);
    } catch (ApiException e) {
        throw new BoxExceptionMappingService(fileid).map(e);
    }
}
Also used : DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) FilesFileIdaddSharedLinkBody(ch.cyberduck.core.box.io.swagger.client.model.FilesFileIdaddSharedLinkBody) SharedLinksFilesApi(ch.cyberduck.core.box.io.swagger.client.api.SharedLinksFilesApi) FilesfileIdaddSharedLinkSharedLink(ch.cyberduck.core.box.io.swagger.client.model.FilesfileIdaddSharedLinkSharedLink) File(ch.cyberduck.core.box.io.swagger.client.model.File) ApiException(ch.cyberduck.core.box.io.swagger.client.ApiException)

Example 4 with ApiException

use of ch.cyberduck.core.box.io.swagger.client.ApiException in project cyberduck by iterate-ch.

the class BoxMoveFeature method move.

@Override
public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback delete, final ConnectionCallback callback) throws BackgroundException {
    try {
        if (status.isExists()) {
            new BoxDeleteFeature(session, fileid).delete(Collections.singletonList(renamed), callback, delete);
        }
        final String id = fileid.getFileId(file, new DisabledListProgressListener());
        if (file.isDirectory()) {
            final Folder result = new FoldersApi(new BoxApiClient(session.getClient())).putFoldersId(id, new FoldersFolderIdBody().name(renamed.getName()).parent(new FoldersfolderIdParent().id(fileid.getFileId(renamed.getParent(), new DisabledListProgressListener()))), null, BoxAttributesFinderFeature.DEFAULT_FIELDS);
            fileid.cache(file, null);
            fileid.cache(renamed, id);
            return renamed.withAttributes(new BoxAttributesFinderFeature(session, fileid).toAttributes(result));
        }
        final File result = new FilesApi(new BoxApiClient(session.getClient())).putFilesId(id, new FilesFileIdBody().name(renamed.getName()).parent(new FilesfileIdParent().id(fileid.getFileId(renamed.getParent(), new DisabledListProgressListener()))), null, BoxAttributesFinderFeature.DEFAULT_FIELDS);
        fileid.cache(file, null);
        fileid.cache(renamed, id);
        return renamed.withAttributes(new BoxAttributesFinderFeature(session, fileid).toAttributes(result));
    } catch (ApiException e) {
        throw new BoxExceptionMappingService(fileid).map("Cannot rename {0}", e, file);
    }
}
Also used : FoldersFolderIdBody(ch.cyberduck.core.box.io.swagger.client.model.FoldersFolderIdBody) FilesfileIdParent(ch.cyberduck.core.box.io.swagger.client.model.FilesfileIdParent) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) Folder(ch.cyberduck.core.box.io.swagger.client.model.Folder) FilesFileIdBody(ch.cyberduck.core.box.io.swagger.client.model.FilesFileIdBody) FoldersApi(ch.cyberduck.core.box.io.swagger.client.api.FoldersApi) FilesApi(ch.cyberduck.core.box.io.swagger.client.api.FilesApi) FoldersfolderIdParent(ch.cyberduck.core.box.io.swagger.client.model.FoldersfolderIdParent) File(ch.cyberduck.core.box.io.swagger.client.model.File) ApiException(ch.cyberduck.core.box.io.swagger.client.ApiException)

Example 5 with ApiException

use of ch.cyberduck.core.box.io.swagger.client.ApiException in project cyberduck by iterate-ch.

the class BoxShareFeature method createFolderSharedLink.

private DescriptiveUrl createFolderSharedLink(final Path file, final PasswordCallback callback) throws BackgroundException {
    try {
        final String password = this.prompt(file, callback);
        final Folder link = new SharedLinksFoldersApi(new BoxApiClient(session.getClient())).putFoldersIdAddSharedLink("shared_link", fileid.getFileId(file, new DisabledListProgressListener()), new FoldersFolderIdaddSharedLinkBody().sharedLink(new FoldersfolderIdaddSharedLinkSharedLink().password(password)));
        return new DescriptiveUrl(URI.create(link.getSharedLink().getUrl()), DescriptiveUrl.Type.signed);
    } catch (ApiException e) {
        throw new BoxExceptionMappingService(fileid).map(e);
    }
}
Also used : FoldersFolderIdaddSharedLinkBody(ch.cyberduck.core.box.io.swagger.client.model.FoldersFolderIdaddSharedLinkBody) FoldersfolderIdaddSharedLinkSharedLink(ch.cyberduck.core.box.io.swagger.client.model.FoldersfolderIdaddSharedLinkSharedLink) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) Folder(ch.cyberduck.core.box.io.swagger.client.model.Folder) SharedLinksFoldersApi(ch.cyberduck.core.box.io.swagger.client.api.SharedLinksFoldersApi) ApiException(ch.cyberduck.core.box.io.swagger.client.ApiException)

Aggregations

ApiException (ch.cyberduck.core.box.io.swagger.client.ApiException)5 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)3 File (ch.cyberduck.core.box.io.swagger.client.model.File)3 Folder (ch.cyberduck.core.box.io.swagger.client.model.Folder)3 DescriptiveUrl (ch.cyberduck.core.DescriptiveUrl)2 FoldersApi (ch.cyberduck.core.box.io.swagger.client.api.FoldersApi)2 AttributedList (ch.cyberduck.core.AttributedList)1 Credentials (ch.cyberduck.core.Credentials)1 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)1 Path (ch.cyberduck.core.Path)1 JSON (ch.cyberduck.core.box.io.swagger.client.JSON)1 FilesApi (ch.cyberduck.core.box.io.swagger.client.api.FilesApi)1 SharedLinksFilesApi (ch.cyberduck.core.box.io.swagger.client.api.SharedLinksFilesApi)1 SharedLinksFoldersApi (ch.cyberduck.core.box.io.swagger.client.api.SharedLinksFoldersApi)1 UsersApi (ch.cyberduck.core.box.io.swagger.client.api.UsersApi)1 FilesFileIdBody (ch.cyberduck.core.box.io.swagger.client.model.FilesFileIdBody)1 FilesFileIdaddSharedLinkBody (ch.cyberduck.core.box.io.swagger.client.model.FilesFileIdaddSharedLinkBody)1 FilesfileIdParent (ch.cyberduck.core.box.io.swagger.client.model.FilesfileIdParent)1 FilesfileIdaddSharedLinkSharedLink (ch.cyberduck.core.box.io.swagger.client.model.FilesfileIdaddSharedLinkSharedLink)1 FoldersFolderIdBody (ch.cyberduck.core.box.io.swagger.client.model.FoldersFolderIdBody)1