Search in sources :

Example 1 with AttributedList

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

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);
    }
}
Also used : Path(ch.cyberduck.core.Path) FoldersApi(ch.cyberduck.core.brick.io.swagger.client.api.FoldersApi) FileEntity(ch.cyberduck.core.brick.io.swagger.client.model.FileEntity) AttributedList(ch.cyberduck.core.AttributedList) ApiException(ch.cyberduck.core.brick.io.swagger.client.ApiException)

Example 3 with AttributedList

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;
}
Also used : Path(ch.cyberduck.core.Path) PathAttributes(ch.cyberduck.core.PathAttributes) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) AttributedList(ch.cyberduck.core.AttributedList) Checksum(ch.cyberduck.core.io.Checksum)

Example 4 with AttributedList

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);
    }
}
Also used : Path(ch.cyberduck.core.Path) AttributedList(ch.cyberduck.core.AttributedList) PathAttributes(ch.cyberduck.core.PathAttributes) BackgroundException(ch.cyberduck.core.exception.BackgroundException)

Example 5 with AttributedList

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);
}
Also used : Path(ch.cyberduck.core.Path) AttributedList(ch.cyberduck.core.AttributedList) PathAttributes(ch.cyberduck.core.PathAttributes)

Aggregations

AttributedList (ch.cyberduck.core.AttributedList)94 Path (ch.cyberduck.core.Path)92 Test (org.junit.Test)50 Host (ch.cyberduck.core.Host)34 PathAttributes (ch.cyberduck.core.PathAttributes)34 TestProtocol (ch.cyberduck.core.TestProtocol)33 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)32 NullSession (ch.cyberduck.core.NullSession)32 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)31 ListProgressListener (ch.cyberduck.core.ListProgressListener)30 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)24 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)19 NullLocal (ch.cyberduck.core.NullLocal)18 Delete (ch.cyberduck.core.features.Delete)18 IntegrationTest (ch.cyberduck.test.IntegrationTest)17 IOException (java.io.IOException)17 NotfoundException (ch.cyberduck.core.exception.NotfoundException)16 SimplePathPredicate (ch.cyberduck.core.SimplePathPredicate)14 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)13 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)9