Search in sources :

Example 6 with ProjectItemModifiedEvent

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

the class ProjectService method createFolder.

@POST
@Path("/folder/{path:.*}")
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Create a folder", notes = "Create a folder is a specified project")
@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 createFolder(@ApiParam(value = "Path to a new folder destination", required = true) @PathParam("path") String path) throws ConflictException, ForbiddenException, ServerException, NotFoundException {
    final FolderEntry newFolder = projectManager.getProjectsRoot().createFolder(path);
    final URI location = getServiceContext().getServiceUriBuilder().clone().path(getClass(), "getChildren").build(new String[] { newFolder.getPath().toString().substring(1) }, false);
    eventService.publish(new ProjectItemModifiedEvent(ProjectItemModifiedEvent.EventType.CREATED, workspace, newFolder.getProject(), newFolder.getPath().toString(), true));
    return Response.created(location).entity(injectFolderLinks(asDto(newFolder))).build();
}
Also used : ProjectItemModifiedEvent(org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with ProjectItemModifiedEvent

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

the class RenameTypeTest method helperQualifiedName.

private void helperQualifiedName(String oldName, String newName, String textFileName, String filePatterns) throws Exception {
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), oldName);
    IType classA = getType(cu, oldName);
    String content = getFileContents(getTestPath() + name.getMethodName() + TEST_INPUT_INFIX + textFileName);
    IProject project = classA.getJavaProject().getProject();
    IFile file = project.getFile(textFileName);
    file.create(new ByteArrayInputStream(content.getBytes()), true, null);
    ResourceChangedEvent event = new ResourceChangedEvent(new File(BaseTest.class.getResource("/projects").getFile()), new ProjectItemModifiedEvent(ProjectItemModifiedEvent.EventType.CREATED, "projects", fProject.getElementName(), file.getFullPath().toOSString(), false));
    JavaModelManager.getJavaModelManager().deltaState.resourceChanged(event);
    RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(classA, newName);
    descriptor.setUpdateQualifiedNames(true);
    descriptor.setFileNamePatterns(filePatterns);
    assertEquals("was supposed to pass", null, performRefactoring(descriptor));
    ICompilationUnit newcu = getPackageP().getCompilationUnit(newName + ".java");
    assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName(newName)), newcu.getSource());
    InputStreamReader reader = new InputStreamReader(file.getContents(true));
    StringBuffer newContent = new StringBuffer();
    try {
        int ch;
        while ((ch = reader.read()) != -1) newContent.append((char) ch);
    } finally {
        reader.close();
    }
    String definedContent = getFileContents(getTestPath() + name.getMethodName() + TEST_OUTPUT_INFIX + textFileName);
    assertEqualLines("invalid updating", definedContent, newContent.toString());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IFile(org.eclipse.core.resources.IFile) ProjectItemModifiedEvent(org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent) InputStreamReader(java.io.InputStreamReader) IProject(org.eclipse.core.resources.IProject) IType(org.eclipse.jdt.core.IType) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceChangedEvent(org.eclipse.che.jdt.core.resources.ResourceChangedEvent) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IFile(org.eclipse.core.resources.IFile) File(java.io.File) BaseTest(org.eclipse.che.plugin.java.server.che.BaseTest)

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