Search in sources :

Example 1 with ProjectItemModifiedEvent

use of org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent in project che by eclipse.

the class ProjectService method createFile.

@POST
@Path("/file/{parent:.*}")
@Consumes({ MediaType.MEDIA_TYPE_WILDCARD })
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Create file", notes = "Create a new file in a project. If file type isn't specified the server will resolve its type.")
@ApiResponses({ @ApiResponse(code = 201, message = ""), @ApiResponse(code = 403, message = "User not authorized to call this operation"), @ApiResponse(code = 404, message = "Not found"), @ApiResponse(code = 409, message = "File already exists"), @ApiResponse(code = 500, message = "Internal Server Error") })
public Response createFile(@ApiParam(value = "Path to a target directory", required = true) @PathParam("parent") String parentPath, @ApiParam(value = "New file name", required = true) @QueryParam("name") String fileName, InputStream content) throws NotFoundException, ConflictException, ForbiddenException, ServerException {
    final FolderEntry parent = projectManager.asFolder(parentPath);
    if (parent == null) {
        throw new NotFoundException("Parent not found for " + parentPath);
    }
    final FileEntry newFile = parent.createFile(fileName, content);
    eventService.publish(new ProjectItemModifiedEvent(ProjectItemModifiedEvent.EventType.CREATED, workspace, newFile.getProject(), newFile.getPath().toString(), false));
    final URI location = getServiceContext().getServiceUriBuilder().clone().path(getClass(), "getFile").build(new String[] { newFile.getPath().toString().substring(1) }, false);
    return Response.created(location).entity(injectFileLinks(asDto(newFile))).build();
}
Also used : ProjectItemModifiedEvent(org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent) NotFoundException(org.eclipse.che.api.core.NotFoundException) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with ProjectItemModifiedEvent

use of org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent in project che by eclipse.

the class ProjectService method updateFile.

@PUT
@Path("/file/{path:.*}")
@Consumes({ MediaType.MEDIA_TYPE_WILDCARD })
@ApiOperation(value = "Update file", notes = "Update an existing file with new content")
@ApiResponses({ @ApiResponse(code = 200, message = ""), @ApiResponse(code = 403, message = "User not authorized to call this operation"), @ApiResponse(code = 404, message = "Not found"), @ApiResponse(code = 500, message = "Internal Server Error") })
public Response updateFile(@ApiParam(value = "Full path to a file", required = true) @PathParam("path") String path, InputStream content) throws NotFoundException, ForbiddenException, ServerException {
    final FileEntry file = projectManager.asFile(path);
    if (file == null) {
        throw new NotFoundException("File not found for " + path);
    }
    file.updateContent(content);
    eventService.publish(new ProjectItemModifiedEvent(ProjectItemModifiedEvent.EventType.UPDATED, workspace, file.getProject(), file.getPath().toString(), false));
    return Response.ok().build();
}
Also used : ProjectItemModifiedEvent(org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent) NotFoundException(org.eclipse.che.api.core.NotFoundException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with ProjectItemModifiedEvent

use of org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent in project che by eclipse.

the class DeltaProcessingTest method testAddClass.

@Test
public void testAddClass() throws Exception {
    File workspace = new File(BaseTest.class.getResource("/projects").getFile());
    ResourceChangedEvent event = new ResourceChangedEvent(workspace, new ProjectItemModifiedEvent(ProjectItemModifiedEvent.EventType.CREATED, "projects", "test", "/test/src/main/java/org/eclipse/che/test/NewClass.java", false));
    NameEnvironmentAnswer answer = project.newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY).findType(CharOperation.splitOn('.', "org.eclipse.che.test.NewClass".toCharArray()));
    assertThat(answer).isNull();
    FileOutputStream outputStream = new FileOutputStream(new File(workspace, "/test/src/main/java/org/eclipse/che/test/NewClass.java"));
    outputStream.write("package org.eclipse.che.test;\n public class NewClass{}\n".getBytes());
    outputStream.close();
    JavaModelManager.getJavaModelManager().deltaState.resourceChanged(event);
    answer = project.newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY).findType(CharOperation.splitOn('.', "org.eclipse.che.test.NewClass".toCharArray()));
    assertThat(answer).isNotNull();
}
Also used : NameEnvironmentAnswer(org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer) ProjectItemModifiedEvent(org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent) FileOutputStream(java.io.FileOutputStream) ResourceChangedEvent(org.eclipse.che.jdt.core.resources.ResourceChangedEvent) File(java.io.File) Test(org.junit.Test)

Example 4 with ProjectItemModifiedEvent

use of org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent in project che by eclipse.

the class DeltaProcessingTest method testRemoveClass.

@Test
public void testRemoveClass() throws Exception {
    ResourceChangedEvent event = new ResourceChangedEvent(new File(BaseTest.class.getResource("/projects").getFile()), new ProjectItemModifiedEvent(ProjectItemModifiedEvent.EventType.DELETED, "projects", "test", "/test/src/main/java/org/eclipse/che/test/MyClass.java", false));
    NameEnvironmentAnswer answer = project.newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY).findType(CharOperation.splitOn('.', "org.eclipse.che.test.MyClass".toCharArray()));
    assertThat(answer).isNotNull();
    JavaModelManager.getJavaModelManager().deltaState.resourceChanged(event);
    answer = project.newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY).findType(CharOperation.splitOn('.', "org.eclipse.che.test.MyClass".toCharArray()));
    assertThat(answer).isNull();
}
Also used : NameEnvironmentAnswer(org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer) ProjectItemModifiedEvent(org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent) ResourceChangedEvent(org.eclipse.che.jdt.core.resources.ResourceChangedEvent) File(java.io.File) Test(org.junit.Test)

Example 5 with ProjectItemModifiedEvent

use of org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent in project che by eclipse.

the class DeltaProcessingTest method testRemoveFolder.

@Test
public void testRemoveFolder() throws Exception {
    ResourceChangedEvent event = new ResourceChangedEvent(new File(BaseTest.class.getResource("/projects").getFile()), new ProjectItemModifiedEvent(ProjectItemModifiedEvent.EventType.DELETED, "projects", "test", "/test/src/main/java/org/eclipse/che/test", true));
    NameEnvironmentAnswer answer = project.newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY).findType(CharOperation.splitOn('.', "org.eclipse.che.test.MyClass".toCharArray()));
    assertThat(answer).isNotNull();
    JavaModelManager.getJavaModelManager().deltaState.resourceChanged(event);
    answer = project.newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY).findType(CharOperation.splitOn('.', "org.eclipse.che.test.MyClass".toCharArray()));
    assertThat(answer).isNull();
}
Also used : NameEnvironmentAnswer(org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer) ProjectItemModifiedEvent(org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent) ResourceChangedEvent(org.eclipse.che.jdt.core.resources.ResourceChangedEvent) File(java.io.File) Test(org.junit.Test)

Aggregations

ProjectItemModifiedEvent (org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent)7 File (java.io.File)4 ResourceChangedEvent (org.eclipse.che.jdt.core.resources.ResourceChangedEvent)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Path (javax.ws.rs.Path)3 NameEnvironmentAnswer (org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer)3 Test (org.junit.Test)3 URI (java.net.URI)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 PUT (javax.ws.rs.PUT)1 BaseTest (org.eclipse.che.plugin.java.server.che.BaseTest)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1