Search in sources :

Example 21 with ProjectConfigDto

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

the class ProjectServiceTest method testGetNotValidProject.

@Test
public void testGetNotValidProject() throws Exception {
    //MountPoint mountPoint = pm.getProjectsRoot(workspace).getVirtualFile().getMountPoint();
    vfsProvider.getVirtualFileSystem().getRoot().createFolder("not_project");
    // to refresh
    projectRegistry.initProjects();
    ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/not_project", "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
    ProjectConfigDto badProject = (ProjectConfigDto) response.getEntity();
    assertNotNull(badProject);
    assertEquals(badProject.getName(), "not_project");
    assertNotNull(badProject.getProblems());
    assertTrue(badProject.getProblems().size() > 0);
    assertEquals(11, badProject.getProblems().get(0).getCode());
    validateProjectLinks(badProject);
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Test(org.testng.annotations.Test)

Example 22 with ProjectConfigDto

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

the class ProjectServiceTest method addMockedProjectConfigDto.

private void addMockedProjectConfigDto(org.eclipse.che.api.project.server.type.ProjectTypeDef myProjectType, String projectName) throws ForbiddenException, ServerException, NotFoundException, ConflictException {
    final ProjectConfigDto testProjectConfigMock = mock(ProjectConfigDto.class);
    when(testProjectConfigMock.getPath()).thenReturn("/" + projectName);
    when(testProjectConfigMock.getName()).thenReturn(projectName);
    when(testProjectConfigMock.getDescription()).thenReturn("my test project");
    when(testProjectConfigMock.getType()).thenReturn("my_project_type");
    when(testProjectConfigMock.getSource()).thenReturn(DtoFactory.getInstance().createDto(SourceStorageDto.class));
    //        when(testProjectConfigMock.getModules()).thenReturn(modules);
    //        when(testProjectConfigMock.findModule(anyString())).thenReturn(testProjectConfigMock);
    Map<String, List<String>> attr = new HashMap<>();
    for (Attribute attribute : myProjectType.getAttributes()) {
        attr.put(attribute.getName(), attribute.getValue().getList());
    }
    when(testProjectConfigMock.getAttributes()).thenReturn(attr);
    projects.add(testProjectConfigMock);
    pm.createProject(testProjectConfigMock, null);
}
Also used : SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Attribute(org.eclipse.che.api.core.model.project.type.Attribute) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 23 with ProjectConfigDto

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

the class ProjectServiceTest method testCreateBatchProjects.

@Test
public void testCreateBatchProjects() throws Exception {
    //prepare first project
    final String projectName1 = "testProject1";
    final String projectTypeId1 = "testProjectType1";
    final String projectPath1 = "/testProject1";
    createTestProjectType(projectTypeId1);
    phRegistry.register(createProjectHandlerFor(projectName1, projectTypeId1));
    //prepare inner project
    final String innerProjectName = "innerProject";
    final String innerProjectTypeId = "testProjectType2";
    final String innerProjectPath = "/testProject1/innerProject";
    createTestProjectType(innerProjectTypeId);
    phRegistry.register(createProjectHandlerFor(innerProjectName, innerProjectTypeId));
    //prepare project to import
    final String importProjectName = "testImportProject";
    final String importProjectTypeId = "testImportProjectType";
    final String importProjectPath = "/testImportProject";
    final String importType = "importType";
    final String[] paths = { "a", "b", "test.txt" };
    final List<String> children = new ArrayList<>(Arrays.asList(paths));
    registerImporter(importType, prepareZipArchiveBasedOn(children));
    createTestProjectType(importProjectTypeId);
    Map<String, List<String>> headers = new HashMap<>();
    headers.put("Content-Type", singletonList(APPLICATION_JSON));
    try (InputStream content = getClass().getResourceAsStream("batchNewProjectConfigs.json")) {
        ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/batch", "http://localhost:8080/api", headers, ByteStreams.toByteArray(content), null);
        assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
        final List<ProjectConfigDto> result = (List<ProjectConfigDto>) response.getEntity();
        assertNotNull(result);
        assertEquals(result.size(), 3);
        final ProjectConfigDto importProjectConfig = result.get(0);
        checkProjectIsCreated(importProjectName, importProjectPath, importProjectTypeId, importProjectConfig);
        final ProjectConfigDto config1 = result.get(1);
        checkProjectIsCreated(projectName1, projectPath1, projectTypeId1, config1);
        final ProjectConfigDto innerProjectConfig = result.get(2);
        checkProjectIsCreated(innerProjectName, innerProjectPath, innerProjectTypeId, innerProjectConfig);
    }
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 24 with ProjectConfigDto

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

the class ProjectServiceTest method testImportProject.

@Test
public void testImportProject() throws Exception {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ZipOutputStream zipOut = new ZipOutputStream(bout);
    zipOut.putNextEntry(new ZipEntry("folder1/"));
    zipOut.putNextEntry(new ZipEntry("folder1/file1.txt"));
    zipOut.write("to be or not to be".getBytes(Charset.defaultCharset()));
    zipOut.close();
    final InputStream zip = new ByteArrayInputStream(bout.toByteArray());
    final String importType = "_123_";
    registerImporter(importType, zip);
    final String myType = "chuck_project_type";
    final ProjectConfigDto newProjectConfig = DtoFactory.getInstance().createDto(ProjectConfigDto.class).withPath("/new_project").withName("new_project").withDescription("import test").withType(myType);
    projects.add(newProjectConfig);
    Map<String, List<String>> headers = new HashMap<>();
    headers.put("Content-Type", singletonList(APPLICATION_JSON));
    String json = "{\n" + "            \"location\": null,\n" + "            \"type\": \"%s\"\n" + "}";
    byte[] b = format(json, importType).getBytes(Charset.defaultCharset());
    ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/import/new_project", "http://localhost:8080/api", headers, b, null);
    assertEquals(response.getStatus(), 204);
    RegisteredProject newProject = pm.getProject("new_project");
    assertNotNull(newProject);
//assertNotNull(newProject.getConfig());
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 25 with ProjectConfigDto

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

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