Search in sources :

Example 41 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.

the class OrganizationDaoTest method shouldGetByParent.

@Test
public void shouldGetByParent() throws Exception {
    final OrganizationImpl parent = organizations[0];
    final OrganizationImpl child1 = new OrganizationImpl("child1", "childTest1", parent.getId());
    final OrganizationImpl child2 = new OrganizationImpl("child2", "childTest2", parent.getId());
    final OrganizationImpl child3 = new OrganizationImpl("child3", "childTest3", parent.getId());
    tckRepository.createAll(asList(child1, child2, child3));
    final Page<OrganizationImpl> children = organizationDao.getByParent(parent.getId(), 1, 1);
    assertEquals(children.getTotalItemsCount(), 3);
    assertEquals(children.getItemsCount(), 1);
    assertTrue(children.getItems().contains(child1) ^ children.getItems().contains(child2) ^ children.getItems().contains(child3));
}
Also used : OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 42 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.

the class OrganizationDaoTest method shouldThrowConflictExceptionOnUpdatingOrganizationNameToExistingOne.

@Test(expectedExceptions = ConflictException.class)
public void shouldThrowConflictExceptionOnUpdatingOrganizationNameToExistingOne() throws Exception {
    final OrganizationImpl toUpdate = new OrganizationImpl(organizations[0].getId(), organizations[1].getName(), "new-parent");
    organizationDao.update(toUpdate);
}
Also used : OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 43 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.

the class OrganizationDaoTest method shouldThrowConflictExceptionOnCreatingOrganizationWithExistingId.

@Test(expectedExceptions = ConflictException.class)
public void shouldThrowConflictExceptionOnCreatingOrganizationWithExistingId() throws Exception {
    final OrganizationImpl organization = new OrganizationImpl(organizations[0].getId(), "Test", null);
    organizationDao.create(organization);
    assertEquals(organizationDao.getById(organization.getId()), organization);
}
Also used : OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 44 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.

the class JpaMemberDao method getOrganizations.

@Override
@Transactional
public Page<OrganizationImpl> getOrganizations(String userId, int maxItems, long skipCount) throws ServerException {
    requireNonNull(userId, "Required non-null user id");
    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();
        final List<OrganizationImpl> result = manager.createNamedQuery("Member.getOrganizations", OrganizationImpl.class).setParameter("userId", userId).setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList();
        final Long organizationsCount = manager.createNamedQuery("Member.getOrganizationsCount", Long.class).setParameter("userId", userId).getSingleResult();
        return new Page<>(result, skipCount, maxItems, organizationsCount);
    } 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 45 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.

the class JpaOrganizationDao method doUpdate.

@Transactional
protected void doUpdate(OrganizationImpl update) throws NotFoundException {
    final EntityManager manager = managerProvider.get();
    if (manager.find(OrganizationImpl.class, update.getId()) == null) {
        throw new NotFoundException(format("Couldn't update organization with id '%s' because it doesn't exist", update.getId()));
    }
    manager.merge(update);
    manager.flush();
}
Also used : EntityManager(javax.persistence.EntityManager) NotFoundException(org.eclipse.che.api.core.NotFoundException) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Transactional(com.google.inject.persist.Transactional)

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