Search in sources :

Example 1 with WorkspaceDto

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());
}
Also used : CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) ApiParam(io.swagger.annotations.ApiParam) ApiOperation(io.swagger.annotations.ApiOperation) QueryParam(javax.ws.rs.QueryParam) Service(org.eclipse.che.api.core.rest.Service) Consumes(javax.ws.rs.Consumes) Example(io.swagger.annotations.Example) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) WsAgentHealthChecker(org.eclipse.che.api.agent.server.WsAgentHealthChecker) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) ImmutableMap(com.google.common.collect.ImmutableMap) LINK_REL_GET_WORKSPACES(org.eclipse.che.api.workspace.shared.Constants.LINK_REL_GET_WORKSPACES) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) WsAgentHealthStateDto(org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto) LINK_REL_GET_BY_NAMESPACE(org.eclipse.che.api.workspace.shared.Constants.LINK_REL_GET_BY_NAMESPACE) String.format(java.lang.String.format) SnapshotDto(org.eclipse.che.api.machine.shared.dto.SnapshotDto) List(java.util.List) BadRequestException(org.eclipse.che.api.core.BadRequestException) DtoConverter.asDto(org.eclipse.che.api.workspace.server.DtoConverter.asDto) Response(javax.ws.rs.core.Response) EnvironmentRecipeDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) ConflictException(org.eclipse.che.api.core.ConflictException) Api(io.swagger.annotations.Api) Named(javax.inject.Named) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) Collections.emptyMap(java.util.Collections.emptyMap) POST(javax.ws.rs.POST) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) CHE_WORKSPACE_AUTO_START(org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_AUTO_START) Maps(com.google.common.collect.Maps) NotFoundException(org.eclipse.che.api.core.NotFoundException) Collectors.toList(java.util.stream.Collectors.toList) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) ServerException(org.eclipse.che.api.core.ServerException) ApiResponse(io.swagger.annotations.ApiResponse) ExampleProperty(io.swagger.annotations.ExampleProperty) CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) CHE_WORKSPACE_AUTO_SNAPSHOT(org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_AUTO_SNAPSHOT) PUT(javax.ws.rs.PUT) CHE_WORKSPACE_AUTO_RESTORE(org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_AUTO_RESTORE) LINK_REL_CREATE_WORKSPACE(org.eclipse.che.api.workspace.shared.Constants.LINK_REL_CREATE_WORKSPACE) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with WorkspaceDto

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);
}
Also used : Timer(com.google.gwt.user.client.Timer) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Operation(org.eclipse.che.api.promises.client.Operation) WorkspaceStartingEvent(org.eclipse.che.ide.api.workspace.event.WorkspaceStartingEvent)

Example 3 with WorkspaceDto

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();
}
Also used : WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 4 with WorkspaceDto

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()));
        }
    });
}
Also used : DefaultWorkspaceComponent(org.eclipse.che.ide.workspace.DefaultWorkspaceComponent) PromiseError(org.eclipse.che.api.promises.client.PromiseError) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 5 with WorkspaceDto

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));
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Test(org.testng.annotations.Test)

Aggregations

WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)17 WorkspaceConfigDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto)7 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)6 Test (org.testng.annotations.Test)5 Response (com.jayway.restassured.response.Response)4 List (java.util.List)4 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)3 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Maps (com.google.common.collect.Maps)2 Api (io.swagger.annotations.Api)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiParam (io.swagger.annotations.ApiParam)2 ApiResponse (io.swagger.annotations.ApiResponse)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Example (io.swagger.annotations.Example)2 ExampleProperty (io.swagger.annotations.ExampleProperty)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 Collections.emptyMap (java.util.Collections.emptyMap)2