Search in sources :

Example 1 with UpdateRoomRequest

use of ch.cyberduck.core.sds.io.swagger.client.model.UpdateRoomRequest 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)

Example 2 with UpdateRoomRequest

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

the class SDSTouchFeatureTest method testQuota.

@Test
public void testQuota() throws Exception {
    final SDSNodeIdProvider nodeid = new SDSNodeIdProvider(session);
    final Path room = new SDSDirectoryFeature(session, nodeid).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
    final UpdateRoomRequest updateRoomRequest = new UpdateRoomRequest();
    final long quota = 1L + PreferencesFactory.get().getInteger("sds.upload.multipart.chunksize");
    updateRoomRequest.setQuota(quota);
    assertEquals(quota, new NodesApi(session.getClient()).updateRoom(updateRoomRequest, Long.valueOf(room.attributes().getVersionId()), StringUtils.EMPTY, null).getQuota(), 0L);
    assertTrue(new SDSTouchFeature(session, nodeid).isSupported(room.withAttributes(new SDSAttributesFinderFeature(session, nodeid).find(room)), StringUtils.EMPTY));
    assertEquals(quota, room.attributes().getQuota());
    final byte[] content = RandomUtils.nextBytes(2);
    final TransferStatus status = new TransferStatus();
    status.setLength(2L);
    final Path test = new Path(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final SDSMultipartWriteFeature writer = new SDSMultipartWriteFeature(session, nodeid);
    final HttpResponseOutputStream<Node> out = writer.write(test, status, new DisabledConnectionCallback());
    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    PathAttributes attr;
    final long timestamp = System.currentTimeMillis();
    do {
        attr = new SDSAttributesFinderFeature(session, nodeid).find(room);
        if (System.currentTimeMillis() - timestamp > Duration.ofMinutes(1L).toMillis()) {
            fail();
        }
    } while (attr.getSize() != 2L);
    assertFalse(new SDSTouchFeature(session, nodeid).isSupported(room.withAttributes(attr), StringUtils.EMPTY));
    assertEquals(quota, attr.getQuota());
    assertEquals(2L, attr.getSize());
    new SDSDeleteFeature(session, nodeid).delete(Arrays.asList(test, room), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) Node(ch.cyberduck.core.sds.io.swagger.client.model.Node) PathAttributes(ch.cyberduck.core.PathAttributes) NodesApi(ch.cyberduck.core.sds.io.swagger.client.api.NodesApi) UpdateRoomRequest(ch.cyberduck.core.sds.io.swagger.client.model.UpdateRoomRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

PathAttributes (ch.cyberduck.core.PathAttributes)2 NodesApi (ch.cyberduck.core.sds.io.swagger.client.api.NodesApi)2 Node (ch.cyberduck.core.sds.io.swagger.client.model.Node)2 UpdateRoomRequest (ch.cyberduck.core.sds.io.swagger.client.model.UpdateRoomRequest)2 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)1 CaseInsensitivePathPredicate (ch.cyberduck.core.CaseInsensitivePathPredicate)1 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)1 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)1 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)1 Path (ch.cyberduck.core.Path)1 SimplePathPredicate (ch.cyberduck.core.SimplePathPredicate)1 Delete (ch.cyberduck.core.features.Delete)1 StreamCopier (ch.cyberduck.core.io.StreamCopier)1 HostPreferences (ch.cyberduck.core.preferences.HostPreferences)1 ApiException (ch.cyberduck.core.sds.io.swagger.client.ApiException)1 MoveNode (ch.cyberduck.core.sds.io.swagger.client.model.MoveNode)1 MoveNodesRequest (ch.cyberduck.core.sds.io.swagger.client.model.MoveNodesRequest)1 UpdateFileRequest (ch.cyberduck.core.sds.io.swagger.client.model.UpdateFileRequest)1 UpdateFolderRequest (ch.cyberduck.core.sds.io.swagger.client.model.UpdateFolderRequest)1 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)1