use of org.eclipse.che.api.project.shared.dto.MoveOptions in project che by eclipse.
the class ProjectServiceTest method testMoveFileWithRename.
@Test
public void testMoveFileWithRename() throws Exception {
RegisteredProject myProject = pm.getProject("my_project");
myProject.getBaseFolder().createFolder("a/b/c");
((FolderEntry) myProject.getBaseFolder().getChild("a/b")).createFile("test.txt", "to be or not no be".getBytes(Charset.defaultCharset()));
// name for file after move
final String destinationName = "copyOfTestForMove.txt";
Map<String, List<String>> headers = new HashMap<>();
headers.put(CONTENT_TYPE, singletonList(APPLICATION_JSON));
MoveOptions descriptor = DtoFactory.getInstance().createDto(MoveOptions.class);
descriptor.setName(destinationName);
descriptor.setOverWrite(false);
ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/move/my_project/a/b/test.txt?to=/my_project/a/b/c", "http://localhost:8080/api", headers, DtoFactory.getInstance().toJson(descriptor).getBytes(Charset.defaultCharset()), null);
assertEquals(response.getStatus(), 201, "Error: " + response.getEntity());
assertEquals(response.getHttpHeaders().getFirst("Location"), URI.create(format("http://localhost:8080/api/project/file/my_project/a/b/c/%s", destinationName)));
VirtualFileEntry theTargetFile = myProject.getBaseFolder().getChild(format("a/b/c/%s", destinationName));
// new
assertNotNull(theTargetFile);
}
use of org.eclipse.che.api.project.shared.dto.MoveOptions in project che by eclipse.
the class ProjectServiceClientImpl method move.
/** {@inheritDoc} */
@Override
public Promise<Void> move(Path source, Path target, String newName, boolean overwrite) {
final String url = getBaseUrl() + MOVE + path(source.toString()) + "?to=" + URL.encodeQueryString(target.toString());
final MoveOptions moveOptions = dtoFactory.createDto(MoveOptions.class);
moveOptions.setName(newName);
moveOptions.setOverWrite(overwrite);
return reqFactory.createPostRequest(url, moveOptions).loader(loaderFactory.newLoader("Moving...")).send();
}
Aggregations