Search in sources :

Example 1 with MoveNode

use of ch.cyberduck.core.sds.io.swagger.client.model.MoveNode in project cyberduck by iterate-ch.

the class SDSMoveFeature method move.

@Override
public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) throws BackgroundException {
    try {
        final long nodeId = Long.parseLong(nodeid.getVersionId(file, new DisabledListProgressListener()));
        if (containerService.isContainer(file)) {
            final Node node = new NodesApi(session.getClient()).updateRoom(new UpdateRoomRequest().name(renamed.getName()), nodeId, StringUtils.EMPTY, null);
            nodeid.cache(renamed, file.attributes().getVersionId());
            nodeid.cache(file, null);
            return renamed.withAttributes(new SDSAttributesAdapter(session).toAttributes(node));
        } else {
            if (status.isExists()) {
                // Handle case insensitive. Find feature will have reported target to exist if same name with different case
                if (!new CaseInsensitivePathPredicate(file).test(renamed)) {
                    log.warn(String.format("Delete existing file %s", renamed));
                    new SDSDeleteFeature(session, nodeid).delete(Collections.singletonMap(renamed, status), connectionCallback, callback);
                }
            }
            if (new SimplePathPredicate(file.getParent()).test(renamed.getParent())) {
                // Rename only
                if (file.isDirectory()) {
                    new NodesApi(session.getClient()).updateFolder(new UpdateFolderRequest().name(renamed.getName()), nodeId, StringUtils.EMPTY, null);
                } else {
                    new NodesApi(session.getClient()).updateFile(new UpdateFileRequest().name(renamed.getName()), nodeId, StringUtils.EMPTY, null);
                }
            } else {
                // Move to different parent
                new NodesApi(session.getClient()).moveNodes(new MoveNodesRequest().resolutionStrategy(MoveNodesRequest.ResolutionStrategyEnum.OVERWRITE).addItemsItem(new MoveNode().id(nodeId).name(renamed.getName())).keepShareLinks(new HostPreferences(session.getHost()).getBoolean("sds.upload.sharelinks.keep")), Long.parseLong(nodeid.getVersionId(renamed.getParent(), new DisabledListProgressListener())), StringUtils.EMPTY, null);
            }
            nodeid.cache(renamed, file.attributes().getVersionId());
            nodeid.cache(file, null);
            // Copy original file attributes
            return renamed.withAttributes(new PathAttributes(file.attributes()).withVersionId(String.valueOf(nodeId)));
        }
    } catch (ApiException e) {
        throw new SDSExceptionMappingService(nodeid).map("Cannot rename {0}", e, file);
    }
}
Also used : CaseInsensitivePathPredicate(ch.cyberduck.core.CaseInsensitivePathPredicate) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) Node(ch.cyberduck.core.sds.io.swagger.client.model.Node) MoveNode(ch.cyberduck.core.sds.io.swagger.client.model.MoveNode) PathAttributes(ch.cyberduck.core.PathAttributes) MoveNode(ch.cyberduck.core.sds.io.swagger.client.model.MoveNode) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) NodesApi(ch.cyberduck.core.sds.io.swagger.client.api.NodesApi) UpdateRoomRequest(ch.cyberduck.core.sds.io.swagger.client.model.UpdateRoomRequest) MoveNodesRequest(ch.cyberduck.core.sds.io.swagger.client.model.MoveNodesRequest) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) UpdateFileRequest(ch.cyberduck.core.sds.io.swagger.client.model.UpdateFileRequest) UpdateFolderRequest(ch.cyberduck.core.sds.io.swagger.client.model.UpdateFolderRequest) ApiException(ch.cyberduck.core.sds.io.swagger.client.ApiException)

Aggregations

CaseInsensitivePathPredicate (ch.cyberduck.core.CaseInsensitivePathPredicate)1 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)1 PathAttributes (ch.cyberduck.core.PathAttributes)1 SimplePathPredicate (ch.cyberduck.core.SimplePathPredicate)1 HostPreferences (ch.cyberduck.core.preferences.HostPreferences)1 ApiException (ch.cyberduck.core.sds.io.swagger.client.ApiException)1 NodesApi (ch.cyberduck.core.sds.io.swagger.client.api.NodesApi)1 MoveNode (ch.cyberduck.core.sds.io.swagger.client.model.MoveNode)1 MoveNodesRequest (ch.cyberduck.core.sds.io.swagger.client.model.MoveNodesRequest)1 Node (ch.cyberduck.core.sds.io.swagger.client.model.Node)1 UpdateFileRequest (ch.cyberduck.core.sds.io.swagger.client.model.UpdateFileRequest)1 UpdateFolderRequest (ch.cyberduck.core.sds.io.swagger.client.model.UpdateFolderRequest)1 UpdateRoomRequest (ch.cyberduck.core.sds.io.swagger.client.model.UpdateRoomRequest)1