Search in sources :

Example 26 with ProjectConfigDto

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

the class DtoConverter method asDto.

/** Converts {@link ProjectConfig} to {@link ProjectConfigDto}. */
public static ProjectConfigDto asDto(ProjectConfig projectCfg) {
    final ProjectConfigDto projectConfigDto = newDto(ProjectConfigDto.class).withName(projectCfg.getName()).withDescription(projectCfg.getDescription()).withPath(projectCfg.getPath()).withType(projectCfg.getType()).withAttributes(projectCfg.getAttributes()).withMixins(projectCfg.getMixins());
    final SourceStorage source = projectCfg.getSource();
    if (source != null) {
        projectConfigDto.withSource(newDto(SourceStorageDto.class).withLocation(source.getLocation()).withType(source.getType()).withParameters(source.getParameters()));
    }
    return projectConfigDto;
}
Also used : SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)

Example 27 with ProjectConfigDto

use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto 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 28 with ProjectConfigDto

use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto 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)

Example 29 with ProjectConfigDto

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

the class MavenModelImporter method onFactoryAccepted.

@Override
public void onFactoryAccepted(FactoryAcceptedEvent event) {
    final FactoryDto factory = event.getFactory();
    final List<ProjectConfigDto> projects = factory.getWorkspace().getProjects();
    final List<String> paths = new ArrayList<>();
    for (ProjectConfigDto project : projects) {
        if (MavenAttributes.MAVEN_ID.equals(project.getType())) {
            paths.add(project.getPath());
        }
    }
    if (!paths.isEmpty()) {
        reimport(paths);
    }
}
Also used : FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) ArrayList(java.util.ArrayList)

Example 30 with ProjectConfigDto

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

the class WorkspaceServiceTest method shouldAddProject.

@Test
public void shouldAddProject() throws Exception {
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    when(wsManager.updateWorkspace(any(), any())).thenReturn(workspace);
    final ProjectConfigDto projectDto = createProjectDto();
    final int projectsSizeBefore = workspace.getConfig().getProjects().size();
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(projectDto).when().post(SECURE_PATH + "/workspace/" + workspace.getId() + "/project");
    assertEquals(response.getStatusCode(), 200);
    assertEquals(new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT).getConfig().getProjects().size(), projectsSizeBefore + 1);
    verify(validator).validateConfig(workspace.getConfig());
    verify(wsManager).updateWorkspace(any(), any());
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Test(org.testng.annotations.Test)

Aggregations

ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)30 Test (org.testng.annotations.Test)14 List (java.util.List)13 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)10 LinkedList (java.util.LinkedList)10 ContainerResponse (org.everrest.core.impl.ContainerResponse)10 Collections.singletonList (java.util.Collections.singletonList)9 LinkedHashMap (java.util.LinkedHashMap)7 Resource (org.eclipse.che.ide.api.resources.Resource)6 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)5 SourceStorageDto (org.eclipse.che.api.workspace.shared.dto.SourceStorageDto)5 WorkspaceConfigDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto)5 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)5 Optional (com.google.common.base.Optional)4 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Function (org.eclipse.che.api.promises.client.Function)3 FunctionException (org.eclipse.che.api.promises.client.FunctionException)3