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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations