Search in sources :

Example 16 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.

the class JpaOrganizationDao method getSuborganizations.

@Override
@Transactional
public Page<OrganizationImpl> getSuborganizations(String parentQualifiedName, int maxItems, long skipCount) throws ServerException {
    requireNonNull(parentQualifiedName, "Required non-null parent qualified name");
    checkArgument(skipCount <= Integer.MAX_VALUE, "The number of items to skip can't be greater than " + Integer.MAX_VALUE);
    try {
        final EntityManager manager = managerProvider.get();
        List<OrganizationImpl> result = manager.createNamedQuery("Organization.getSuborganizations", OrganizationImpl.class).setParameter("qualifiedName", parentQualifiedName + "/%").setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList();
        final long suborganizationsCount = manager.createNamedQuery("Organization.getSuborganizationsCount", Long.class).setParameter("qualifiedName", parentQualifiedName + "/%").getSingleResult();
        return new Page<>(result, skipCount, maxItems, suborganizationsCount);
    } catch (RuntimeException e) {
        throw new ServerException(e.getLocalizedMessage(), e);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) Page(org.eclipse.che.api.core.Page) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Transactional(com.google.inject.persist.Transactional)

Example 17 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.

the class JpaOrganizationDao method getById.

@Override
@Transactional
public OrganizationImpl getById(String organizationId) throws NotFoundException, ServerException {
    requireNonNull(organizationId, "Required non-null organization id");
    try {
        final EntityManager manager = managerProvider.get();
        OrganizationImpl organization = manager.find(OrganizationImpl.class, organizationId);
        if (organization == null) {
            throw new NotFoundException(format("Organization with id '%s' doesn't exist", organizationId));
        }
        return organization;
    } catch (RuntimeException e) {
        throw new ServerException(e.getLocalizedMessage(), e);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Transactional(com.google.inject.persist.Transactional)

Example 18 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.

the class OrganizationDaoTest method shouldRemoveOrganization.

@Test(dependsOnMethods = "shouldThrowNotFoundExceptionOnGettingNonExistingOrganizationById")
public void shouldRemoveOrganization() throws Exception {
    // given
    final OrganizationImpl organization = organizations[0];
    // when
    organizationDao.remove(organization.getId());
    // then
    assertNull(notFoundToNull(() -> organizationDao.getById(organization.getId())));
}
Also used : OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 19 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.

the class OrganizationDaoTest method shouldGetSuborganizations.

@Test
public void shouldGetSuborganizations() throws Exception {
    final OrganizationImpl parent = organizations[0];
    final OrganizationImpl child1 = new OrganizationImpl("child1", parent.getQualifiedName() + "/childTest1", parent.getId());
    final OrganizationImpl child2 = new OrganizationImpl("child2", child1.getQualifiedName() + "/childTest2", child1.getId());
    final OrganizationImpl child3 = new OrganizationImpl("child3", parent.getQualifiedName() + "/childTest3", parent.getId());
    tckRepository.createAll(asList(child1, child2, child3));
    final List<OrganizationImpl> suborganizations = Pages.stream((maxItems, skipCount) -> organizationDao.getSuborganizations(parent.getQualifiedName(), maxItems, skipCount), 1).collect(Collectors.toList());
    assertEquals(suborganizations.size(), 3);
}
Also used : Listeners(org.testng.annotations.Listeners) Assert.assertNull(org.testng.Assert.assertNull) TckRepository(org.eclipse.che.commons.test.tck.repository.TckRepository) Page(org.eclipse.che.api.core.Page) BeforeMethod(org.testng.annotations.BeforeMethod) Assert.assertEquals(org.testng.Assert.assertEquals) Callable(java.util.concurrent.Callable) Test(org.testng.annotations.Test) TckRepositoryException(org.eclipse.che.commons.test.tck.repository.TckRepositoryException) AfterMethod(org.testng.annotations.AfterMethod) Collectors(java.util.stream.Collectors) NotFoundException(org.eclipse.che.api.core.NotFoundException) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Inject(javax.inject.Inject) List(java.util.List) TckListener(org.eclipse.che.commons.test.tck.TckListener) OrganizationDao(org.eclipse.che.multiuser.organization.spi.OrganizationDao) Arrays.asList(java.util.Arrays.asList) Assert.assertTrue(org.testng.Assert.assertTrue) ConflictException(org.eclipse.che.api.core.ConflictException) Pages(org.eclipse.che.api.core.Pages) NameGenerator(org.eclipse.che.commons.lang.NameGenerator) EventService(org.eclipse.che.api.core.notification.EventService) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 20 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.

the class OrganizationDaoTest method shouldUpdateOrganization.

@Test
public void shouldUpdateOrganization() throws Exception {
    final OrganizationImpl toUpdate = new OrganizationImpl(organizations[0].getId(), "new-name", null);
    organizationDao.update(toUpdate);
    final OrganizationImpl updated = organizationDao.getById(toUpdate.getId());
    assertEquals(toUpdate, updated);
}
Also used : OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Aggregations

OrganizationImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl)100 Test (org.testng.annotations.Test)56 Transactional (com.google.inject.persist.Transactional)18 BeforeMethod (org.testng.annotations.BeforeMethod)16 EntityManager (javax.persistence.EntityManager)14 MemberImpl (org.eclipse.che.multiuser.organization.spi.impl.MemberImpl)14 Organization (org.eclipse.che.multiuser.organization.shared.model.Organization)13 Response (io.restassured.response.Response)12 Page (org.eclipse.che.api.core.Page)10 ServerException (org.eclipse.che.api.core.ServerException)8 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)8 OrganizationDao (org.eclipse.che.multiuser.organization.spi.OrganizationDao)8 OrganizationDistributedResourcesImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl)7 TypeLiteral (com.google.inject.TypeLiteral)6 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)6 NotFoundException (org.eclipse.che.api.core.NotFoundException)6 OrganizationDto (org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto)6 UserDevfilePermissionImpl (org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl)6 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)5 DBInitializer (org.eclipse.che.core.db.DBInitializer)5