use of ch.cyberduck.core.AttributedList 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.AttributedList in project cyberduck by iterate-ch.
the class BrickListService method list.
public AttributedList<Path> list(final Path directory, final ListProgressListener listener, final int chunksize) throws BackgroundException {
try {
final AttributedList<Path> children = new AttributedList<>();
String cursor = null;
List<FileEntity> response;
final BrickApiClient client = new BrickApiClient(session);
do {
response = new FoldersApi(client).foldersListForPath(StringUtils.removeStart(directory.getAbsolute(), String.valueOf(Path.DELIMITER)), cursor, chunksize, null, null, null, null, null, null);
for (FileEntity entity : response) {
children.add(new Path(entity.getPath(), EnumSet.of("directory".equals(entity.getType()) ? Path.Type.directory : Path.Type.file), attributes.toAttributes(entity)));
}
if (client.getResponseHeaders().containsKey("X-Files-Cursor")) {
final Optional<String> header = client.getResponseHeaders().get("X-Files-Cursor").stream().findFirst();
cursor = header.orElse(null);
} else {
cursor = null;
}
listener.chunk(directory, children);
} while (cursor != null);
return children;
} catch (ApiException e) {
throw new BrickExceptionMappingService().map("Listing directory {0} failed", e, directory);
}
}
use of ch.cyberduck.core.AttributedList in project cyberduck by iterate-ch.
the class PathAttributesDictionary method deserialize.
public <T> PathAttributes deserialize(T serialized) {
final Deserializer dict = factory.create(serialized);
final PathAttributes attributes = new PathAttributes();
final String sizeObj = dict.stringForKey("Size");
if (sizeObj != null) {
attributes.setSize(Long.parseLong(sizeObj));
}
final String quotaObj = dict.stringForKey("Quota");
if (quotaObj != null) {
attributes.setQuota(Long.parseLong(quotaObj));
}
final String modifiedObj = dict.stringForKey("Modified");
if (modifiedObj != null) {
attributes.setModificationDate(Long.parseLong(modifiedObj));
}
final String createdObj = dict.stringForKey("Created");
if (createdObj != null) {
attributes.setCreationDate(Long.parseLong(createdObj));
}
final String revisionObj = dict.stringForKey("Revision");
if (revisionObj != null) {
attributes.setRevision(Long.parseLong(revisionObj));
}
final List<T> versionsObj = dict.listForKey("Versions");
if (versionsObj != null) {
final AttributedList<Path> versions = new AttributedList<>();
for (T versionDict : versionsObj) {
versions.add(new PathDictionary(factory).deserialize(versionDict));
}
attributes.setVersions(versions);
}
final String etagObj = dict.stringForKey("ETag");
if (etagObj != null) {
attributes.setETag(etagObj);
}
final Object permissionObj = dict.objectForKey("Permission");
if (permissionObj != null) {
attributes.setPermission(new PermissionDictionary().deserialize(permissionObj));
}
final Object aclObj = dict.objectForKey("Acl");
if (aclObj != null) {
attributes.setAcl(new AclDictionary().deserialize(aclObj));
}
if (dict.mapForKey("Link") != null) {
final Map<String, String> link = dict.mapForKey("Link");
attributes.setLink(new DescriptiveUrl(URI.create(link.get("Url")), DescriptiveUrl.Type.valueOf(link.get("Type"))));
} else {
final String linkObj = dict.stringForKey("Link");
if (linkObj != null) {
attributes.setLink(new DescriptiveUrl(URI.create(linkObj), DescriptiveUrl.Type.http));
}
}
if (dict.mapForKey("Checksum") != null) {
final Map<String, String> checksum = dict.mapForKey("Checksum");
attributes.setChecksum(new Checksum(HashAlgorithm.valueOf(checksum.get("Algorithm")), checksum.get("Hash")));
} else {
attributes.setChecksum(Checksum.parse(dict.stringForKey("Checksum")));
}
attributes.setVersionId(dict.stringForKey("Version"));
attributes.setFileId(dict.stringForKey("File Id"));
attributes.setLockId(dict.stringForKey("Lock Id"));
final String duplicateObj = dict.stringForKey("Duplicate");
if (duplicateObj != null) {
attributes.setDuplicate(Boolean.parseBoolean(duplicateObj));
}
final String hiddenObj = dict.stringForKey("Hidden");
if (hiddenObj != null) {
attributes.setHidden(Boolean.parseBoolean(hiddenObj));
}
attributes.setMetadata(Collections.emptyMap());
attributes.setRegion(dict.stringForKey("Region"));
attributes.setStorageClass(dict.stringForKey("Storage Class"));
final Object vaultObj = dict.objectForKey("Vault");
if (vaultObj != null) {
attributes.setVault(new PathDictionary(factory).deserialize(vaultObj));
}
final Map<String, String> customObj = dict.mapForKey("Custom");
if (customObj != null) {
attributes.setCustom(customObj);
}
return attributes;
}
use of ch.cyberduck.core.AttributedList in project cyberduck by iterate-ch.
the class DecryptingListProgressListener method visit.
@Override
public void visit(final AttributedList<Path> list, final int index, final Path f) {
try {
f.getType().add(Path.Type.encrypted);
if (f.attributes().getVersions().isEmpty()) {
list.set(index, vault.decrypt(session, f));
} else {
final AttributedList<Path> versions = new AttributedList<>();
for (Path version : f.attributes().getVersions()) {
versions.add(vault.decrypt(session, version));
}
list.set(index, vault.decrypt(session, f).withAttributes(new PathAttributes(f.attributes()).withVersions(versions)));
}
} catch (BackgroundException e) {
log.error(String.format("Failure %s decrypting %s", e, f));
list.remove(index);
}
}
use of ch.cyberduck.core.AttributedList in project cyberduck by iterate-ch.
the class CryptoAttributesFeature method find.
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) throws BackgroundException {
final PathAttributes attributes = new PathAttributes(delegate.find(vault.encrypt(session, file, true), listener));
if (file.isFile()) {
attributes.setSize(vault.toCleartextSize(0L, attributes.getSize()));
}
if (file.isDirectory()) {
attributes.setSize(-1L);
}
if (attributes.getVersions().isEmpty()) {
return attributes;
}
final AttributedList<Path> versions = new AttributedList<>();
for (Path version : attributes.getVersions()) {
versions.add(vault.decrypt(session, version));
}
return new PathAttributes(attributes).withVersions(versions);
}
Aggregations