Search in sources :

Example 66 with NotFoundException

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

the class MavenServerService method getEffectivePom.

/**
     * Returns maven effective pom file.
     *
     * @param projectPath
     *         path to the opened pom file
     * @return content of the effective pom
     * @throws ServerException
     *         when getting mount point has a problem
     * @throws NotFoundException
     *         when current pom file isn't exist
     * @throws ForbiddenException
     *         when response code is 403
     */
@GET
@Path("effective/pom")
@Produces(TEXT_XML)
public String getEffectivePom(@QueryParam("projectpath") String projectPath) throws ServerException, NotFoundException, ForbiddenException {
    RegisteredProject project = projectRegistry.getProject(projectPath);
    if (project == null) {
        throw new NotFoundException("Project " + projectPath + " doesn't exist");
    }
    MavenServerWrapper mavenServer = wrapperManager.getMavenServer(MavenWrapperManager.ServerType.DOWNLOAD);
    try {
        mavenServer.customize(projectManager.copyWorkspaceCache(), terminal, notifier, false, false);
        VirtualFileEntry pomFile = project.getBaseFolder().getChild("pom.xml");
        if (pomFile == null) {
            throw new NotFoundException("pom.xml doesn't exist");
        }
        return mavenServer.getEffectivePom(pomFile.getVirtualFile().toIoFile(), Collections.emptyList(), Collections.emptyList());
    } finally {
        wrapperManager.release(mavenServer);
    }
}
Also used : MavenServerWrapper(org.eclipse.che.plugin.maven.server.MavenServerWrapper) NotFoundException(org.eclipse.che.api.core.NotFoundException) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 67 with NotFoundException

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

the class JpaProfileDao method getById.

@Override
@Transactional
public ProfileImpl getById(String userId) throws NotFoundException, ServerException {
    requireNonNull(userId, "Required non-null id");
    try {
        final EntityManager manager = managerProvider.get();
        final ProfileImpl profile = manager.find(ProfileImpl.class, userId);
        if (profile == null) {
            throw new NotFoundException(format("Couldn't find profile for user with id '%s'", userId));
        }
        manager.refresh(profile);
        return profile;
    } catch (RuntimeException x) {
        throw new ServerException(x.getLocalizedMessage(), x);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) ProfileImpl(org.eclipse.che.api.user.server.model.impl.ProfileImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Transactional(com.google.inject.persist.Transactional)

Example 68 with NotFoundException

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

the class JpaUserDao method doUpdate.

@Transactional
protected void doUpdate(UserImpl update) throws NotFoundException {
    final EntityManager manager = managerProvider.get();
    final UserImpl user = manager.find(UserImpl.class, update.getId());
    if (user == null) {
        throw new NotFoundException(format("Couldn't update user with id '%s' because it doesn't exist", update.getId()));
    }
    final String password = update.getPassword();
    if (password != null) {
        update.setPassword(encryptor.encrypt(password));
    } else {
        update.setPassword(user.getPassword());
    }
    manager.merge(update);
    manager.flush();
}
Also used : EntityManager(javax.persistence.EntityManager) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Transactional(com.google.inject.persist.Transactional)

Example 69 with NotFoundException

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

the class JpaUserDao method getByAliasAndPassword.

@Override
@Transactional
public UserImpl getByAliasAndPassword(String emailOrName, String password) throws NotFoundException, ServerException {
    requireNonNull(emailOrName, "Required non-null email or name");
    requireNonNull(password, "Required non-null password");
    try {
        final UserImpl user = managerProvider.get().createNamedQuery("User.getByAliasAndPassword", UserImpl.class).setParameter("alias", emailOrName).getSingleResult();
        if (!encryptor.test(password, user.getPassword())) {
            throw new NotFoundException(format("User with email or name '%s' and given password doesn't exist", emailOrName));
        }
        return erasePassword(user);
    } catch (NoResultException x) {
        throw new NotFoundException(format("User with email or name '%s' and given password doesn't exist", emailOrName));
    } catch (RuntimeException x) {
        throw new ServerException(x.getLocalizedMessage(), x);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) NoResultException(javax.persistence.NoResultException) Transactional(com.google.inject.persist.Transactional)

Example 70 with NotFoundException

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

the class JpaSshDao method doRemove.

@Transactional
protected void doRemove(String owner, String service, String name) throws NotFoundException {
    EntityManager manager = managerProvider.get();
    SshPairImpl entity = manager.find(SshPairImpl.class, new SshPairPrimaryKey(owner, service, name));
    if (entity == null) {
        throw new NotFoundException(format("Ssh pair with service '%s' and name '%s' was not found.", service, name));
    }
    manager.remove(entity);
    manager.flush();
}
Also used : EntityManager(javax.persistence.EntityManager) SshPairImpl(org.eclipse.che.api.ssh.server.model.impl.SshPairImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Transactional(com.google.inject.persist.Transactional)

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