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);
}
}
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());
}
Aggregations