Search in sources :

Example 11 with WorkspaceDto

use of org.eclipse.che.api.workspace.shared.dto.WorkspaceDto in project che by eclipse.

the class StartWorkspacePresenter method show.

/**
     * Shows special dialog which contains workspaces which can be started at this time.
     *
     * @param callback
     *         callback which is necessary to notify that workspace component started or failed
     * @param workspaces
     *         available workspaces which will be displayed
     */
public void show(List<WorkspaceDto> workspaces, Callback<Component, Exception> callback) {
    this.callback = callback;
    this.workspaces = workspaces;
    view.clearWorkspacesPanel();
    String workspaceName = browserAddress.getWorkspaceName();
    createWsWidgets(workspaces);
    for (WorkspaceDto workspace : workspaces) {
        if (workspaceName.equals(workspace.getConfig().getName())) {
            selectedWorkspace = workspace;
            break;
        }
    }
    view.setWsName(workspaceName);
    view.show();
}
Also used : WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)

Example 12 with WorkspaceDto

use of org.eclipse.che.api.workspace.shared.dto.WorkspaceDto in project che by eclipse.

the class BootstrapController method startWsAgentComponents.

@Inject
private void startWsAgentComponents(EventBus eventBus, final Map<String, Provider<WsAgentComponent>> components) {
    eventBus.addHandler(WorkspaceStartedEvent.TYPE, new WorkspaceStartedEvent.Handler() {

        @Override
        public void onWorkspaceStarted(WorkspaceStartedEvent event) {
            workspaceService.getWorkspace(event.getWorkspace().getId()).then(new Operation<WorkspaceDto>() {

                @Override
                public void apply(WorkspaceDto ws) throws OperationException {
                    MachineDto devMachineDto = ws.getRuntime().getDevMachine();
                    DevMachine devMachine = new DevMachine(devMachineDto);
                    if (appContext instanceof AppContextImpl) {
                        ((AppContextImpl) appContext).setProjectsRoot(Path.valueOf(devMachineDto.getRuntime().projectsRoot()));
                    }
                    wsAgentStateControllerProvider.get().initialize(devMachine);
                    wsAgentURLModifier.initialize(devMachine);
                    SortedMap<String, Provider<WsAgentComponent>> sortedComponents = new TreeMap<>();
                    sortedComponents.putAll(components);
                    startWsAgentComponents(sortedComponents.values().iterator());
                }
            }).catchError(new Operation<PromiseError>() {

                @Override
                public void apply(PromiseError err) throws OperationException {
                    Log.error(getClass(), err.getCause());
                    initializationFailed(err.getMessage());
                }
            });
        }
    });
}
Also used : DevMachine(org.eclipse.che.ide.api.machine.DevMachine) WorkspaceStartedEvent(org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Operation(org.eclipse.che.api.promises.client.Operation) AppContextImpl(org.eclipse.che.ide.context.AppContextImpl) MachineDto(org.eclipse.che.api.machine.shared.dto.MachineDto) PromiseError(org.eclipse.che.api.promises.client.PromiseError) SortedMap(java.util.SortedMap) WsAgentComponent(org.eclipse.che.ide.api.component.WsAgentComponent) OperationException(org.eclipse.che.api.promises.client.OperationException) Inject(com.google.inject.Inject)

Example 13 with WorkspaceDto

use of org.eclipse.che.api.workspace.shared.dto.WorkspaceDto in project che by eclipse.

the class WorkspaceService method updateProject.

@PUT
@Path("/{id}/project/{path:.*}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update the workspace project by replacing it with a new one", notes = "This operation can be performed only by the workspace owner")
@ApiResponses({ @ApiResponse(code = 200, message = "The project 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 project"), @ApiResponse(code = 404, message = "The workspace or the project not found"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public WorkspaceDto updateProject(@ApiParam("The workspace id") @PathParam("id") String id, @ApiParam("The path to the project") @PathParam("path") String path, @ApiParam(value = "The project update", required = true) ProjectConfigDto update) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException {
    requiredNotNull(update, "Project config");
    final WorkspaceImpl workspace = workspaceManager.getWorkspace(id);
    final List<ProjectConfigImpl> projects = workspace.getConfig().getProjects();
    final String normalizedPath = path.startsWith("/") ? path : '/' + path;
    if (!projects.removeIf(project -> project.getPath().equals(normalizedPath))) {
        throw new NotFoundException(format("Workspace '%s' doesn't contain project with path '%s'", id, normalizedPath));
    }
    projects.add(new ProjectConfigImpl(update));
    validator.validateConfig(workspace.getConfig());
    return linksInjector.injectLinks(asDto(workspaceManager.updateWorkspace(id, workspace)), getServiceContext());
}
Also used : 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) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) 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 14 with WorkspaceDto

use of org.eclipse.che.api.workspace.shared.dto.WorkspaceDto in project che by eclipse.

the class MavenProjectTypeTest method testMavenProject.

@Test
public void testMavenProject() throws Exception {
    WorkspaceDto usersWorkspaceMock = mock(WorkspaceDto.class);
    WorkspaceConfigDto workspaceConfigMock = mock(WorkspaceConfigDto.class);
    when(httpJsonRequestFactory.fromLink(eq(DtoFactory.newDto(Link.class).withMethod("GET").withHref("/workspace/")))).thenReturn(httpJsonRequest);
    when(httpJsonRequestFactory.fromLink(eq(DtoFactory.newDto(Link.class).withMethod("PUT").withHref("/workspace/" + "/project")))).thenReturn(httpJsonRequest);
    when(httpJsonRequest.request()).thenReturn(httpJsonResponse);
    when(httpJsonResponse.asDto(WorkspaceDto.class)).thenReturn(usersWorkspaceMock);
    final ProjectConfigDto projectConfig = DtoFactory.getInstance().createDto(ProjectConfigDto.class).withName("project").withPath("/myProject").withType(MavenAttributes.MAVEN_ID);
    when(usersWorkspaceMock.getConfig()).thenReturn(workspaceConfigMock);
    when(workspaceConfigMock.getProjects()).thenReturn(Collections.singletonList(projectConfig));
    Map<String, List<String>> attributes = new HashMap<>();
    attributes.put(MavenAttributes.ARTIFACT_ID, Collections.singletonList("myartifact"));
    attributes.put(MavenAttributes.GROUP_ID, Collections.singletonList("mygroup"));
    attributes.put(MavenAttributes.VERSION, Collections.singletonList("1.0"));
    attributes.put(MavenAttributes.PACKAGING, Collections.singletonList("jar"));
    RegisteredProject project = pm.createProject(DtoFactory.getInstance().createDto(ProjectConfigDto.class).withType("maven").withAttributes(attributes).withPath("/myProject").withName("myProject"), new HashMap<>(0));
    for (VirtualFileEntry file : project.getBaseFolder().getChildren()) {
        if (file.getName().equals("pom.xml")) {
            Model pom = Model.readFrom(file.getVirtualFile().getContent());
            Assert.assertEquals(pom.getVersion(), "1.0");
        }
    }
}
Also used : HashMap(java.util.HashMap) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Model(org.eclipse.che.ide.maven.tools.Model) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) List(java.util.List) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) Test(org.junit.Test)

Example 15 with WorkspaceDto

use of org.eclipse.che.api.workspace.shared.dto.WorkspaceDto in project che by eclipse.

the class SimpleGeneratorStrategyTest method prepareProject.

private void prepareProject() throws Exception {
    final String vfsUser = "dev";
    Set<ProjectTypeDef> pts = new HashSet<>();
    final ProjectTypeDef pt = new ProjectTypeDef("mytype", "mytype type", true, false) {
    };
    pts.add(pt);
    final ProjectTypeRegistry projectTypeRegistry = new ProjectTypeRegistry(pts);
    final EventService eventService = new EventService();
    //        final VirtualFileSystemRegistry vfsRegistry = new VirtualFileSystemRegistry();
    //        final MemoryFileSystemProvider memoryFileSystemProvider =
    //                new MemoryFileSystemProvider(workspace,
    //                                             eventService,
    //                                             new VirtualFileSystemUserContext() {
    //                    @Override
    //                    public VirtualFileSystemUser getVirtualFileSystemUser() {
    //                        return new VirtualFileSystemUser(vfsUser, vfsUserGroups);
    //                    }
    //                },
    //                                             vfsRegistry,
    //                                             SystemPathsFilter.ANY);
    //        vfsRegistry.registerProvider(workspace, memoryFileSystemProvider);
    WorkspaceDto usersWorkspaceMock = mock(WorkspaceDto.class);
    final ProjectConfigDto projectConfigDto = DtoFactory.getInstance().createDto(ProjectConfigDto.class).withPath("/my_project");
    WorkspaceConfigDto workspaceConfigMock = mock(WorkspaceConfigDto.class);
    when(usersWorkspaceMock.getConfig()).thenReturn(workspaceConfigMock);
    when(workspaceConfigMock.getProjects()).thenReturn(Collections.singletonList(projectConfigDto));
    ProjectHandlerRegistry handlerRegistry = new ProjectHandlerRegistry(new HashSet<>());
    //        pm = new ProjectManager(vfsRegistry,
    //                                       eventService,
    //                                       projectTypeRegistry,
    //                                       handlerRegistry,
    //                                       filterProvider,
    //                                       API_ENDPOINT,
    //                                       httpJsonRequestFactory);
    //        HttpJsonRequest httpJsonRequest = mock(HttpJsonRequest.class, new SelfReturningAnswer());
    //        when(httpJsonRequestFactory.fromLink(eq(DtoFactory.newDto(Link.class)
    //                                                          .withMethod("PUT")
    //                                                          .withHref(API_ENDPOINT + "/workspace/" + workspace + "/project"))))
    //                .thenReturn(httpJsonRequest);
    //        when(httpJsonRequestFactory.fromLink(eq(DtoFactory.newDto(Link.class)
    //                                                          .withMethod("GET")
    //                                                          .withHref(API_ENDPOINT + "/workspace/" + workspace))))
    //                .thenReturn(httpJsonRequest);
    //        when(httpJsonRequest.request()).thenReturn(httpJsonResponse);
    when(httpJsonResponse.asDto(WorkspaceDto.class)).thenReturn(usersWorkspaceMock);
    pm.createProject(DtoFactory.getInstance().createDto(ProjectConfigDto.class).withType(pt.getId()).withName("my_project").withPath("/my_project"), null);
}
Also used : ProjectTypeRegistry(org.eclipse.che.api.project.server.type.ProjectTypeRegistry) ProjectHandlerRegistry(org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) EventService(org.eclipse.che.api.core.notification.EventService) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) HashSet(java.util.HashSet)

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