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