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());
}
use of org.eclipse.che.api.workspace.shared.dto.WorkspaceDto in project che by eclipse.
the class WorkspaceEventsHandler method onWorkspaceStarting.
private void onWorkspaceStarting(final String workspaceId) {
// TODO timer is a workaround. Is needed because for some reason after receiving of event workspace starting
// get workspace event should contain runtime but it doesn't
new Timer() {
@Override
public void run() {
workspaceServiceClient.getWorkspace(workspaceId).then(new Operation<WorkspaceDto>() {
@Override
public void apply(WorkspaceDto workspace) throws OperationException {
String devMachineName = getDevMachineName(workspace);
if (devMachineName != null) {
subscribeOnWsAgentOutputChannel(workspace, devMachineName);
}
workspaceComponent.setCurrentWorkspace(workspace);
loader.show(LoaderPresenter.Phase.STARTING_WORKSPACE_RUNTIME);
eventBus.fireEvent(new WorkspaceStartingEvent(workspace));
}
});
}
}.schedule(1000);
}
use of org.eclipse.che.api.workspace.shared.dto.WorkspaceDto in project che by eclipse.
the class CreateWorkspacePresenter method show.
/**
* Shows special dialog window which allows set up workspace which will be created.
*
* @param workspaces
* list of existing workspaces
*/
public void show(List<WorkspaceDto> workspaces, final Callback<Component, Exception> callback) {
this.callback = callback;
workspacesNames.clear();
for (WorkspaceDto workspace : workspaces) {
workspacesNames.add(workspace.getConfig().getName());
}
Promise<List<RecipeDescriptor>> recipes = recipeService.getAllRecipes();
recipes.then(new Operation<List<RecipeDescriptor>>() {
@Override
public void apply(List<RecipeDescriptor> recipeDescriptors) throws OperationException {
CreateWorkspacePresenter.this.recipes = recipeDescriptors;
}
});
String workspaceName = browserAddress.getWorkspaceName();
view.setWorkspaceName(workspaceName);
validateCreateWorkspaceForm();
view.show();
}
use of org.eclipse.che.api.workspace.shared.dto.WorkspaceDto in project che by eclipse.
the class CreateWorkspacePresenter method createWorkspace.
private void createWorkspace() {
WorkspaceConfigDto workspaceConfig = getWorkspaceConfig();
workspaceClient.create(workspaceConfig, null).then(new Operation<WorkspaceDto>() {
@Override
public void apply(WorkspaceDto workspace) throws OperationException {
DefaultWorkspaceComponent component = wsComponentProvider.get();
component.startWorkspace(workspace, callback);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
callback.onFailure(new Exception(arg.getCause()));
}
});
}
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));
}
Aggregations