Search in sources :

Example 36 with NotFoundException

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

the class JpaAccountDao method getById.

@Override
@Transactional
public AccountImpl getById(String id) throws NotFoundException, ServerException {
    requireNonNull(id, "Required non-null account id");
    final EntityManager manager = managerProvider.get();
    try {
        AccountImpl account = manager.find(AccountImpl.class, id);
        if (account == null) {
            throw new NotFoundException(format("Account with id '%s' was not found", id));
        }
        return account;
    } catch (RuntimeException x) {
        throw new ServerException(x.getLocalizedMessage(), x);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) AccountImpl(org.eclipse.che.account.spi.AccountImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Transactional(com.google.inject.persist.Transactional)

Example 37 with NotFoundException

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

the class RemoteOAuthTokenProvider method getToken.

/** {@inheritDoc} */
@Override
public OAuthToken getToken(String oauthProviderName, String userId) throws IOException {
    if (userId.isEmpty()) {
        return null;
    }
    try {
        UriBuilder ub = UriBuilder.fromUri(apiEndpoint).path(OAuthAuthenticationService.class).path(OAuthAuthenticationService.class, "token").queryParam("oauth_provider", oauthProviderName);
        Link getTokenLink = DtoFactory.newDto(Link.class).withHref(ub.build().toString()).withMethod("GET");
        return httpJsonRequestFactory.fromLink(getTokenLink).request().asDto(OAuthToken.class);
    } catch (NotFoundException ne) {
        LOG.warn("Token not found for user {}", userId);
        return null;
    } catch (ServerException | UnauthorizedException | ForbiddenException | ConflictException | BadRequestException e) {
        LOG.warn("Exception on token retrieval, message : {}", e.getLocalizedMessage());
        return null;
    }
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) NotFoundException(org.eclipse.che.api.core.NotFoundException) BadRequestException(org.eclipse.che.api.core.BadRequestException) UriBuilder(javax.ws.rs.core.UriBuilder) Link(org.eclipse.che.api.core.rest.shared.dto.Link)

Example 38 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException 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 39 with NotFoundException

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

the class ProjectManagerWriteTest method testInvalidUpdateConfig.

@Test
public void testInvalidUpdateConfig() throws Exception {
    ProjectConfig pc = new NewProjectConfigImpl(null, BaseProjectType.ID, null, "name", "descr", null, null, null);
    try {
        pm.updateProject(pc);
        fail("ConflictException: Project path is not defined");
    } catch (ConflictException e) {
    }
    pc = new NewProjectConfigImpl("/nothing", BaseProjectType.ID, null, "name", "descr", null, null, null);
    try {
        pm.updateProject(pc);
        fail("NotFoundException: Project '/nothing' doesn't exist.");
    } catch (NotFoundException e) {
    }
}
Also used : NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) ConflictException(org.eclipse.che.api.core.ConflictException) NotFoundException(org.eclipse.che.api.core.NotFoundException) Test(org.junit.Test)

Example 40 with NotFoundException

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

the class ProjectService method copy.

@POST
@Path("/copy/{path:.*}")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Copy resource", notes = "Copy resource to a new location which is specified in a query parameter")
@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 = "Resource already exists"), @ApiResponse(code = 500, message = "Internal Server Error") })
public Response copy(@ApiParam("Path to a resource") @PathParam("path") String path, @ApiParam(value = "Path to a new location", required = true) @QueryParam("to") String newParent, CopyOptions copyOptions) throws NotFoundException, ForbiddenException, ConflictException, ServerException {
    final VirtualFileEntry entry = projectManager.asVirtualFileEntry(path);
    // used to indicate over write of destination
    boolean isOverWrite = false;
    // used to hold new name set in request body
    String newName = entry.getName();
    if (copyOptions != null) {
        if (copyOptions.getOverWrite() != null) {
            isOverWrite = copyOptions.getOverWrite();
        }
        if (copyOptions.getName() != null) {
            newName = copyOptions.getName();
        }
    }
    final VirtualFileEntry copy = projectManager.copyTo(path, newParent, newName, isOverWrite);
    final URI location = getServiceContext().getServiceUriBuilder().path(getClass(), copy.isFile() ? "getFile" : "getChildren").build(new String[] { copy.getPath().toString().substring(1) }, false);
    if (copy.isFolder()) {
        try {
            final RegisteredProject project = projectManager.getProject(copy.getPath().toString());
            final String name = project.getName();
            final String projectType = project.getProjectType().getId();
            logProjectCreatedEvent(name, projectType);
        } catch (NotFoundException ignore) {
        }
    }
    return Response.created(location).build();
}
Also used : 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) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

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