Search in sources :

Example 31 with NotFoundException

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

the class Workspace method createResource.

public void createResource(IResource resource, int updateFlags) throws CoreException {
    try {
        IPath path = resource.getFullPath();
        switch(resource.getType()) {
            case IResource.FILE:
                String newName = path.lastSegment();
                VirtualFileEntry child = getProjectsRoot().getChild(path.removeLastSegments(1).toOSString());
                if (child == null) {
                    throw new NotFoundException("Can't find parent folder: " + path.removeLastSegments(1).toOSString());
                }
                FolderEntry entry = (FolderEntry) child;
                entry.createFile(newName, new byte[0]);
                break;
            case IResource.FOLDER:
                getProjectsRoot().createFolder(path.toOSString());
                break;
            case IResource.PROJECT:
                ProjectConfigImpl projectConfig = new ProjectConfigImpl();
                projectConfig.setPath(resource.getName());
                projectConfig.setName(resource.getName());
                projectConfig.setType(BaseProjectType.ID);
                projectManager.get().createProject(projectConfig, new HashMap<>());
                break;
            default:
                throw new UnsupportedOperationException();
        }
    } catch (ForbiddenException | ConflictException | ServerException | NotFoundException e) {
        throw new CoreException(new Status(0, ResourcesPlugin.getPluginId(), e.getMessage(), e));
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) IPath(org.eclipse.core.runtime.IPath) ConflictException(org.eclipse.che.api.core.ConflictException) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) NotFoundException(org.eclipse.che.api.core.NotFoundException) CoreException(org.eclipse.core.runtime.CoreException) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)

Example 32 with NotFoundException

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

the class ProjectManagerWriteTest method testImportProjectWithoutImporterFailed.

@Test
public void testImportProjectWithoutImporterFailed() throws Exception {
    SourceStorage sourceConfig = DtoFactory.newDto(SourceStorageDto.class).withType("nothing");
    try {
        pm.importProject("/testImportProject", sourceConfig, false, () -> new ProjectImportOutputWSLineConsumer("testImportProject", "ws", 300));
        fail("NotFoundException: Unable import sources project from 'null'. Sources type 'nothing' is not supported.");
    } catch (NotFoundException e) {
    }
}
Also used : SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) NotFoundException(org.eclipse.che.api.core.NotFoundException) ProjectImportOutputWSLineConsumer(org.eclipse.che.api.project.server.importer.ProjectImportOutputWSLineConsumer) Test(org.junit.Test)

Example 33 with NotFoundException

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

the class LocalWorkspaceFolderPathProvider method getPath.

@Override
public String getPath(@Assisted("workspace") String workspaceId) throws IOException {
    if (!isWindows && hostProjectsFolder != null) {
        return hostProjectsFolder;
    }
    try {
        WorkspaceManager workspaceManager = this.workspaceManager.get();
        Workspace workspace = workspaceManager.getWorkspace(workspaceId);
        String wsName = workspace.getConfig().getName();
        return doGetPathByName(wsName);
    } catch (NotFoundException | ServerException e) {
        throw new IOException(e.getLocalizedMessage());
    }
}
Also used : WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException) IOException(java.io.IOException) Workspace(org.eclipse.che.api.core.model.workspace.Workspace)

Example 34 with NotFoundException

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

the class DockerProcess method checkAlive.

@Override
public void checkAlive() throws MachineException, NotFoundException {
    // Read pid from file and run 'kill -0 [pid]' command.
    final String isAliveCmd = format("[ -r %1$s ] && kill -0 $(cat %1$s) || echo 'Unable read PID file'", pidFilePath);
    final ListLineConsumer output = new ListLineConsumer();
    final String[] command = { "/bin/sh", "-c", isAliveCmd };
    Exec exec;
    try {
        exec = docker.createExec(CreateExecParams.create(container, command).withDetach(false));
    } catch (IOException e) {
        throw new MachineException(format("Error occurs while initializing command %s in docker container %s: %s", Arrays.toString(command), container, e.getMessage()), e);
    }
    try {
        docker.startExec(StartExecParams.create(exec.getId()), new LogMessagePrinter(output));
    } catch (IOException e) {
        throw new MachineException(format("Error occurs while executing command %s in docker container %s: %s", Arrays.toString(exec.getCommand()), container, e.getMessage()), e);
    }
    // 'kill -0 [pid]' is silent if process is running or print "No such process" message otherwise
    if (!output.getText().isEmpty()) {
        throw new NotFoundException(format("Process with pid %s not found", getPid()));
    }
}
Also used : ListLineConsumer(org.eclipse.che.api.core.util.ListLineConsumer) Exec(org.eclipse.che.plugin.docker.client.Exec) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) NotFoundException(org.eclipse.che.api.core.NotFoundException) IOException(java.io.IOException)

Example 35 with NotFoundException

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

the class OAuthAuthenticationService method token.

/**
     * Gets OAuth token for user.
     *
     * @param oauthProvider
     *         OAuth provider name
     * @return OAuthToken
     * @throws ServerException
     */
@GET
@Path("token")
@Produces(MediaType.APPLICATION_JSON)
public OAuthToken token(@Required @QueryParam("oauth_provider") String oauthProvider) throws ServerException, BadRequestException, NotFoundException, ForbiddenException {
    OAuthAuthenticator provider = getAuthenticator(oauthProvider);
    final Subject subject = EnvironmentContext.getCurrent().getSubject();
    try {
        OAuthToken token = provider.getToken(subject.getUserId());
        if (token == null) {
            token = provider.getToken(subject.getUserName());
        }
        if (token != null) {
            return token;
        }
        throw new NotFoundException("OAuth token for user " + subject.getUserId() + " was not found");
    } catch (IOException e) {
        throw new ServerException(e.getLocalizedMessage(), e);
    }
}
Also used : OAuthToken(org.eclipse.che.api.auth.shared.dto.OAuthToken) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException) IOException(java.io.IOException) Subject(org.eclipse.che.commons.subject.Subject) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

NotFoundException (org.eclipse.che.api.core.NotFoundException)72 ServerException (org.eclipse.che.api.core.ServerException)29 ConflictException (org.eclipse.che.api.core.ConflictException)19 Transactional (com.google.inject.persist.Transactional)16 IOException (java.io.IOException)13 EntityManager (javax.persistence.EntityManager)13 Path (javax.ws.rs.Path)13 Test (org.testng.annotations.Test)12 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)11 Produces (javax.ws.rs.Produces)10 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 ArrayList (java.util.ArrayList)9 BadRequestException (org.eclipse.che.api.core.BadRequestException)9 Instance (org.eclipse.che.api.machine.server.spi.Instance)9 GET (javax.ws.rs.GET)7 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)7 SourceNotFoundException (org.eclipse.che.api.machine.server.exception.SourceNotFoundException)6 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)6 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)6