Search in sources :

Example 81 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class IndexedFileDeleteConsumer method accept.

@Override
public void accept(Path path) {
    try {
        VirtualFileSystem virtualFileSystem = vfsProvider.getVirtualFileSystem();
        SearcherProvider searcherProvider = virtualFileSystem.getSearcherProvider();
        Searcher searcher = searcherProvider.getSearcher(virtualFileSystem);
        Path innerPath = root.toPath().relativize(path);
        searcher.delete("/" + innerPath.toString(), true);
    } catch (ServerException e) {
        LOG.error("Issue happened during removing deleted file from index", e);
    }
}
Also used : Path(java.nio.file.Path) ServerException(org.eclipse.che.api.core.ServerException) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) Searcher(org.eclipse.che.api.vfs.search.Searcher) SearcherProvider(org.eclipse.che.api.vfs.search.SearcherProvider)

Example 82 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class ExtensionCasesTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    new File(root, "/project1").mkdir();
    List<ProjectConfig> projects = new ArrayList<>();
    projects.add(DtoFactory.newDto(ProjectConfigDto.class).withPath("/project1").withName("project1Name").withType("primary1"));
    workspaceHolder = new TestWorkspaceHolder(projects);
    ProjectTypeRegistry projectTypeRegistry = new ProjectTypeRegistry(new HashSet<>());
    projectTypeRegistry.registerProjectType(new PT1());
    //projectTypeRegistry.registerProjectType(new PT3());
    //ProjectHandlerRegistry projectHandlerRegistry = new ProjectHandlerRegistry(new HashSet<>());
    projectRegistry = new ProjectRegistry(workspaceHolder, vfsProvider, projectTypeRegistry, projectHandlerRegistry, eventService);
    projectRegistry.initProjects();
    pm = new ProjectManager(vfsProvider, projectTypeRegistry, projectRegistry, projectHandlerRegistry, null, fileWatcherNotificationHandler, fileTreeWatcher, workspaceHolder, fileWatcherManager);
    pm.initWatcher();
    projectHandlerRegistry.register(new ProjectInitHandler() {

        @Override
        public void onProjectInitialized(ProjectRegistry registry, FolderEntry projectFolder) throws ServerException, NotFoundException, ConflictException, ForbiddenException {
            projectFolder.createFile("generated", "test".getBytes());
            projectFolder.createFolder("project2");
            projectRegistry.setProjectType("/project1/project2", BaseProjectType.ID, false);
        //System.out.println(">>S>>> "+projectRegistry);
        }

        @Override
        public String getProjectType() {
            return "primary1";
        }
    });
}
Also used : ProjectTypeRegistry(org.eclipse.che.api.project.server.type.ProjectTypeRegistry) ProjectInitHandler(org.eclipse.che.api.project.server.handlers.ProjectInitHandler) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) ArrayList(java.util.ArrayList) NotFoundException(org.eclipse.che.api.core.NotFoundException) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) File(java.io.File) Before(org.junit.Before)

Example 83 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class PlainJavaInitHandler method initializeClasspath.

@Override
protected void initializeClasspath(IJavaProject javaProject) throws ServerException {
    IClasspathEntry[] projectClasspath;
    try {
        projectClasspath = javaProject.getRawClasspath();
    } catch (JavaModelException e) {
        LOG.warn("Can't get classpath for: " + javaProject.getProject().getFullPath().toOSString(), e);
        throw new ServerException(e);
    }
    //default classpath
    IClasspathEntry[] defaultClasspath = new IClasspathEntry[] { JavaCore.newSourceEntry(javaProject.getPath()) };
    if (!Arrays.equals(defaultClasspath, projectClasspath)) {
        //classpath is already initialized
        return;
    }
    RegisteredProject project = projectRegistryProvider.get().getProject(javaProject.getPath().toOSString());
    List<String> sourceFolders = project.getAttributes().get(Constants.SOURCE_FOLDER);
    List<String> library = project.getAttributes().get(LIBRARY_FOLDER);
    classpathBuilder.generateClasspath(javaProject, sourceFolders, library);
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) ServerException(org.eclipse.che.api.core.ServerException) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject)

Example 84 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class ProjectService method uploadProjectFromZip.

@POST
@Path("/upload/zipproject/{path:.*}")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Upload zip project", notes = "Upload project from local zip", response = ProjectConfigDto.class)
@ApiResponses({ @ApiResponse(code = 200, message = ""), @ApiResponse(code = 401, message = "User not authorized to call this operation"), @ApiResponse(code = 403, message = "Forbidden operation"), @ApiResponse(code = 409, message = "Resource already exists"), @ApiResponse(code = 500, message = "Unsupported source type") })
public List<SourceEstimation> uploadProjectFromZip(@ApiParam(value = "Path in the project", required = true) @PathParam("path") String path, @ApiParam(value = "Force rewrite existing project", allowableValues = "true,false") @QueryParam("force") boolean force, Iterator<FileItem> formData) throws ServerException, IOException, ConflictException, ForbiddenException, NotFoundException, BadRequestException {
    // Not all importers uses virtual file system API. In this case virtual file system API doesn't get events and isn't able to set
    final FolderEntry baseProjectFolder = (FolderEntry) getVirtualFile(path, force);
    int stripNumber = 0;
    String projectName = "";
    String projectDescription = "";
    FileItem contentItem = null;
    while (formData.hasNext()) {
        FileItem item = formData.next();
        if (!item.isFormField()) {
            if (contentItem == null) {
                contentItem = item;
            } else {
                throw new ServerException("More then one upload file is found but only one is expected. ");
            }
        } else {
            switch(item.getFieldName()) {
                case ("name"):
                    projectName = item.getString().trim();
                    break;
                case ("description"):
                    projectDescription = item.getString().trim();
                    break;
                case ("skipFirstLevel"):
                    stripNumber = Boolean.parseBoolean(item.getString().trim()) ? 1 : 0;
                    break;
            }
        }
    }
    if (contentItem == null) {
        throw new ServerException("Cannot find zip file for upload.");
    }
    try (InputStream zip = contentItem.getInputStream()) {
        baseProjectFolder.getVirtualFile().unzip(zip, true, stripNumber);
    }
    return resolveSources(path);
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) ServerException(org.eclipse.che.api.core.ServerException) InputStream(java.io.InputStream) 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 85 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class ProjectService method uploadZip.

private static Response uploadZip(VirtualFile parent, Iterator<FileItem> formData) throws ForbiddenException, ConflictException, ServerException {
    try {
        FileItem contentItem = null;
        boolean overwrite = false;
        boolean skipFirstLevel = false;
        while (formData.hasNext()) {
            FileItem item = formData.next();
            if (!item.isFormField()) {
                if (contentItem == null) {
                    contentItem = item;
                } else {
                    throw new ServerException("More then one upload file is found but only one should be. ");
                }
            } else if ("overwrite".equals(item.getFieldName())) {
                overwrite = Boolean.parseBoolean(item.getString().trim());
            } else if ("skipFirstLevel".equals(item.getFieldName())) {
                skipFirstLevel = Boolean.parseBoolean(item.getString().trim());
            }
        }
        if (contentItem == null) {
            throw new ServerException("Cannot find file for upload. ");
        }
        try {
            importZip(parent, contentItem.getInputStream(), overwrite, skipFirstLevel);
        } catch (IOException ioe) {
            throw new ServerException(ioe.getMessage(), ioe);
        }
        return Response.ok("", MediaType.TEXT_HTML).build();
    } catch (ForbiddenException | ConflictException | ServerException e) {
        HtmlErrorFormatter.sendErrorAsHTML(e);
        // never thrown
        throw e;
    }
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) IOException(java.io.IOException)

Aggregations

ServerException (org.eclipse.che.api.core.ServerException)143 IOException (java.io.IOException)51 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)37 NotFoundException (org.eclipse.che.api.core.NotFoundException)37 ConflictException (org.eclipse.che.api.core.ConflictException)32 File (java.io.File)22 Test (org.testng.annotations.Test)20 ArrayList (java.util.ArrayList)19 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)19 List (java.util.List)15 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)15 Map (java.util.Map)13 Transactional (com.google.inject.persist.Transactional)12 BadRequestException (org.eclipse.che.api.core.BadRequestException)12 InputStream (java.io.InputStream)11 Unlocker (org.eclipse.che.commons.lang.concurrent.Unlocker)10 String.format (java.lang.String.format)9 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 HashMap (java.util.HashMap)8