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);
}
}
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);
}
}
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())));
}
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);
}
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);
}
Aggregations