use of org.eclipse.che.api.workspace.shared.dto.WorkspaceDto in project che by eclipse.
the class CommandManagerImpl method update.
@Override
public Promise<CommandImpl> update(final String commandName, final CommandImpl command) {
final String name;
if (commandName.equals(command.getName())) {
name = commandName;
} else {
name = getUniqueCommandName(command.getType(), command.getName());
}
final CommandDto commandDto = dtoFactory.createDto(CommandDto.class).withName(name).withCommandLine(command.getCommandLine()).withType(command.getType()).withAttributes(command.getAttributes());
return workspaceServiceClient.updateCommand(appContext.getWorkspaceId(), commandName, commandDto).then(new Function<WorkspaceDto, CommandImpl>() {
@Override
public CommandImpl apply(WorkspaceDto arg) throws FunctionException {
final CommandImpl updatedCommand = new CommandImpl(commandDto.getName(), command.getCommandLine(), command.getType(), command.getAttributes());
commands.remove(commandName);
commands.put(updatedCommand.getName(), updatedCommand);
fireCommandUpdated(updatedCommand);
return updatedCommand;
}
});
}
use of org.eclipse.che.api.workspace.shared.dto.WorkspaceDto in project che by eclipse.
the class WorkspaceServiceTest method shouldUseUsernameAsNamespaceWhenStartingWorkspaceFromConfigWithoutNamespace.
@Test
public void shouldUseUsernameAsNamespaceWhenStartingWorkspaceFromConfigWithoutNamespace() throws Exception {
final WorkspaceImpl workspace = createWorkspace(createConfigDto());
when(wsManager.startWorkspace(anyObject(), anyString(), anyBoolean())).thenReturn(workspace);
when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
final WorkspaceDto workspaceDto = DtoConverter.asDto(workspace);
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(workspaceDto.getConfig()).when().post(SECURE_PATH + "/workspace/runtime" + "?temporary=true");
assertEquals(response.getStatusCode(), 200);
verify(validator).validateConfig(any());
verify(wsManager).startWorkspace(any(), eq(NAMESPACE), eq(true));
}
use of org.eclipse.che.api.workspace.shared.dto.WorkspaceDto in project che by eclipse.
the class WorkspaceServiceTest method shouldStartWorkspaceFromConfig.
@Test
public void shouldStartWorkspaceFromConfig() throws Exception {
final WorkspaceImpl workspace = createWorkspace(createConfigDto());
when(wsManager.startWorkspace(anyObject(), anyString(), anyBoolean())).thenReturn(workspace);
when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
final WorkspaceDto workspaceDto = DtoConverter.asDto(workspace);
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(workspaceDto.getConfig()).when().post(SECURE_PATH + "/workspace/runtime" + "?namespace=test" + "&temporary=true");
assertEquals(response.getStatusCode(), 200);
verify(validator).validateConfig(any());
verify(wsManager).startWorkspace(any(), eq("test"), eq(true));
}
use of org.eclipse.che.api.workspace.shared.dto.WorkspaceDto in project che by eclipse.
the class WorkspaceServiceTest method shouldUpdateTheWorkspace.
@Test
public void shouldUpdateTheWorkspace() throws Exception {
final WorkspaceImpl workspace = createWorkspace(createConfigDto());
when(wsManager.updateWorkspace(any(), any())).thenReturn(workspace);
when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
final WorkspaceDto workspaceDto = DtoConverter.asDto(workspace);
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(workspaceDto).when().put(SECURE_PATH + "/workspace/" + workspace.getId());
assertEquals(response.getStatusCode(), 200);
assertEquals(new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT), workspace);
verify(validator).validateWorkspace(any());
}
use of org.eclipse.che.api.workspace.shared.dto.WorkspaceDto in project che by eclipse.
the class WorkspaceService method updateCommand.
@PUT
@Path("/{id}/command/{name}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update the workspace command by replacing the command with a new one", notes = "This operation can be performed only by the workspace owner")
@ApiResponses({ @ApiResponse(code = 200, message = "The command successfully updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to update the workspace"), @ApiResponse(code = 404, message = "The workspace or the command not found"), @ApiResponse(code = 409, message = "The Command with such name already exists"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public WorkspaceDto updateCommand(@ApiParam("The workspace id") @PathParam("id") String id, @ApiParam("The name of the command") @PathParam("name") String cmdName, @ApiParam(value = "The command update", required = true) CommandDto update) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException {
requiredNotNull(update, "Command update");
final WorkspaceImpl workspace = workspaceManager.getWorkspace(id);
final List<CommandImpl> commands = workspace.getConfig().getCommands();
if (!commands.removeIf(cmd -> cmd.getName().equals(cmdName))) {
throw new NotFoundException(format("Workspace '%s' doesn't contain command '%s'", id, cmdName));
}
commands.add(new CommandImpl(update));
validator.validateConfig(workspace.getConfig());
return linksInjector.injectLinks(asDto(workspaceManager.updateWorkspace(workspace.getId(), workspace)), getServiceContext());
}
Aggregations