Search in sources :

Example 71 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 72 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)

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