Search in sources :

Example 1 with FilesApi

use of ch.cyberduck.core.storegate.io.swagger.client.api.FilesApi in project cyberduck by iterate-ch.

the class StoregateTimestampFeature method setTimestamp.

@Override
public void setTimestamp(final Path file, final TransferStatus status) throws BackgroundException {
    try {
        final FilesApi files = new FilesApi(session.getClient());
        files.filesUpdateFile(fileid.getFileId(file, new DisabledListProgressListener()), new UpdateFilePropertiesRequest().modified(new DateTime(status.getTimestamp())));
    } catch (ApiException e) {
        throw new StoregateExceptionMappingService(fileid).map("Failure to write attributes of {0}", e, file);
    }
}
Also used : UpdateFilePropertiesRequest(ch.cyberduck.core.storegate.io.swagger.client.model.UpdateFilePropertiesRequest) FilesApi(ch.cyberduck.core.storegate.io.swagger.client.api.FilesApi) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) DateTime(org.joda.time.DateTime) ApiException(ch.cyberduck.core.storegate.io.swagger.client.ApiException)

Example 2 with FilesApi

use of ch.cyberduck.core.storegate.io.swagger.client.api.FilesApi in project cyberduck by iterate-ch.

the class StoregateListService method list.

@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
    if (directory.isRoot()) {
        final AttributedList<Path> list = new AttributedList<>();
        for (RootFolder root : session.roots()) {
            switch(root.getRootFolderType()) {
                // My Files
                case 0:
                case // Common
                1:
                    final PathAttributes attr = new PathAttributes().withFileId(root.getId());
                    attr.setModificationDate(root.getModified().getMillis());
                    attr.setCreationDate(root.getCreated().getMillis());
                    list.add(new Path(PathNormalizer.normalize(root.getName()), EnumSet.of(Path.Type.directory, Path.Type.volume), attr));
                    break;
            }
        }
        listener.chunk(directory, list);
        return list;
    } else {
        try {
            final AttributedList<Path> children = new AttributedList<>();
            final StoregateAttributesFinderFeature attributes = new StoregateAttributesFinderFeature(session, fileid);
            int pageIndex = 0;
            FileContents files;
            do {
                files = new FilesApi(this.session.getClient()).filesGet(URIEncoder.encode(fileid.getPrefixedPath(directory)), pageIndex, chunksize, "Name asc", // All
                0, true, false, false);
                for (File f : files.getFiles()) {
                    final PathAttributes attrs = attributes.toAttributes(f);
                    final EnumSet<Path.Type> type = (f.getFlags() & 1) == 1 ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file);
                    final Path p = new Path(directory, f.getName(), type, attrs);
                    children.add(p);
                    listener.chunk(directory, children);
                }
                pageIndex++;
            } while (children.size() < files.getTotalRowCount());
            return children;
        } catch (ApiException e) {
            throw new StoregateExceptionMappingService(fileid).map("Listing directory {0} failed", e, directory);
        }
    }
}
Also used : Path(ch.cyberduck.core.Path) PathAttributes(ch.cyberduck.core.PathAttributes) FileContents(ch.cyberduck.core.storegate.io.swagger.client.model.FileContents) FilesApi(ch.cyberduck.core.storegate.io.swagger.client.api.FilesApi) AttributedList(ch.cyberduck.core.AttributedList) RootFolder(ch.cyberduck.core.storegate.io.swagger.client.model.RootFolder) File(ch.cyberduck.core.storegate.io.swagger.client.model.File) ApiException(ch.cyberduck.core.storegate.io.swagger.client.ApiException)

Example 3 with FilesApi

use of ch.cyberduck.core.storegate.io.swagger.client.api.FilesApi in project cyberduck by iterate-ch.

the class StoregateCopyFeature method copy.

@Override
public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback, final StreamListener listener) throws BackgroundException {
    try {
        final CopyFileRequest copy = new CopyFileRequest().name(target.getName()).parentID(fileid.getFileId(target.getParent(), new DisabledListProgressListener())).mode(// Overwrite
        1);
        final File file = new FilesApi(session.getClient()).filesCopy(fileid.getFileId(source, new DisabledListProgressListener()), copy);
        listener.sent(status.getLength());
        fileid.cache(target, file.getId());
        return target.withAttributes(new StoregateAttributesFinderFeature(session, fileid).toAttributes(file));
    } catch (ApiException e) {
        throw new StoregateExceptionMappingService(fileid).map("Cannot copy {0}", e, source);
    }
}
Also used : FilesApi(ch.cyberduck.core.storegate.io.swagger.client.api.FilesApi) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) CopyFileRequest(ch.cyberduck.core.storegate.io.swagger.client.model.CopyFileRequest) File(ch.cyberduck.core.storegate.io.swagger.client.model.File) ApiException(ch.cyberduck.core.storegate.io.swagger.client.ApiException)

Example 4 with FilesApi

use of ch.cyberduck.core.storegate.io.swagger.client.api.FilesApi in project cyberduck by iterate-ch.

the class StoregateDirectoryFeature method mkdir.

@Override
public Path mkdir(final Path folder, final TransferStatus status) throws BackgroundException {
    try {
        final FilesApi files = new FilesApi(session.getClient());
        final CreateFolderRequest request = new CreateFolderRequest();
        request.setName(folder.getName());
        request.setParentID(fileid.getFileId(folder.getParent(), new DisabledListProgressListener()));
        final File f = files.filesCreateFolder(request);
        fileid.cache(folder, f.getId());
        return folder.withAttributes(new StoregateAttributesFinderFeature(session, fileid).toAttributes(f));
    } catch (ApiException e) {
        throw new StoregateExceptionMappingService(fileid).map("Cannot create folder {0}", e, folder);
    }
}
Also used : FilesApi(ch.cyberduck.core.storegate.io.swagger.client.api.FilesApi) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) CreateFolderRequest(ch.cyberduck.core.storegate.io.swagger.client.model.CreateFolderRequest) File(ch.cyberduck.core.storegate.io.swagger.client.model.File) ApiException(ch.cyberduck.core.storegate.io.swagger.client.ApiException)

Example 5 with FilesApi

use of ch.cyberduck.core.storegate.io.swagger.client.api.FilesApi in project cyberduck by iterate-ch.

the class StoregateIdProvider method getFileId.

@Override
public String getFileId(final Path file, final ListProgressListener listener) throws BackgroundException {
    try {
        if (StringUtils.isNotBlank(file.attributes().getFileId())) {
            return file.attributes().getFileId();
        }
        if (cache.contains(new SimplePathPredicate(file))) {
            final String cached = cache.get(new SimplePathPredicate(file));
            if (log.isDebugEnabled()) {
                log.debug(String.format("Return cached fileid %s for file %s", cached, file));
            }
            return cached;
        }
        final String id = new FilesApi(session.getClient()).filesGet_1(URIEncoder.encode(this.getPrefixedPath(file))).getId();
        this.cache(file, id);
        return id;
    } catch (ApiException e) {
        throw new StoregateExceptionMappingService(this).map("Failure to read attributes of {0}", e, file);
    }
}
Also used : FilesApi(ch.cyberduck.core.storegate.io.swagger.client.api.FilesApi) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) ApiException(ch.cyberduck.core.storegate.io.swagger.client.ApiException)

Aggregations

ApiException (ch.cyberduck.core.storegate.io.swagger.client.ApiException)5 FilesApi (ch.cyberduck.core.storegate.io.swagger.client.api.FilesApi)5 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)3 File (ch.cyberduck.core.storegate.io.swagger.client.model.File)3 AttributedList (ch.cyberduck.core.AttributedList)1 Path (ch.cyberduck.core.Path)1 PathAttributes (ch.cyberduck.core.PathAttributes)1 SimplePathPredicate (ch.cyberduck.core.SimplePathPredicate)1 CopyFileRequest (ch.cyberduck.core.storegate.io.swagger.client.model.CopyFileRequest)1 CreateFolderRequest (ch.cyberduck.core.storegate.io.swagger.client.model.CreateFolderRequest)1 FileContents (ch.cyberduck.core.storegate.io.swagger.client.model.FileContents)1 RootFolder (ch.cyberduck.core.storegate.io.swagger.client.model.RootFolder)1 UpdateFilePropertiesRequest (ch.cyberduck.core.storegate.io.swagger.client.model.UpdateFilePropertiesRequest)1 DateTime (org.joda.time.DateTime)1