use of org.eclipse.che.multiuser.organization.spi.impl.MemberImpl in project che-server by eclipse-che.
the class OrganizationManagerTest method shouldRemoveMembersByOrganizationId.
@Test
public void shouldRemoveMembersByOrganizationId() throws Exception {
MemberImpl member1 = new MemberImpl("user1", "org1", singletonList("read"));
MemberImpl member2 = new MemberImpl("user2", "org1", singletonList("read"));
doReturn(new Page<>(singletonList(member1), 0, 1, 2)).doReturn(new Page<>(singletonList(member2), 1, 1, 2)).when(memberDao).getMembers(anyString(), anyInt(), anyLong());
manager.removeMembers("org1");
verify(memberDao, times(2)).getMembers("org1", 100, 0);
verify(memberDao).remove("user1", "org1");
verify(memberDao).remove("user2", "org1");
}
use of org.eclipse.che.multiuser.organization.spi.impl.MemberImpl in project che-server by eclipse-che.
the class OrganizationManagerTest method shouldCreateSuborganization.
@Test
public void shouldCreateSuborganization() throws Exception {
final OrganizationImpl parentOrganization = new OrganizationImpl("org123", "parentOrg", null);
when(organizationDao.getById(anyString())).thenReturn(parentOrganization);
final Organization toCreate = new OrganizationImpl(null, "orgName", parentOrganization.getId());
manager.create(toCreate);
verify(organizationDao).create(organizationCaptor.capture());
final OrganizationImpl createdOrganization = organizationCaptor.getValue();
assertEquals(createdOrganization.getName(), toCreate.getName());
assertEquals(createdOrganization.getQualifiedName(), parentOrganization.getQualifiedName() + "/" + toCreate.getName());
assertEquals(createdOrganization.getParent(), toCreate.getParent());
verify(eventService).publish(persistEventCaptor.capture());
assertEquals(persistEventCaptor.getValue().getOrganization(), createdOrganization);
verify(memberDao).store(new MemberImpl(USER_ID, createdOrganization.getId(), OrganizationDomain.getActions()));
}
use of org.eclipse.che.multiuser.organization.spi.impl.MemberImpl in project che-server by eclipse-che.
the class OrganizationManagerTest method shouldCreateOrganization.
@Test
public void shouldCreateOrganization() throws Exception {
final Organization toCreate = DtoFactory.newDto(OrganizationDto.class).withName("newOrg");
manager.create(toCreate);
verify(organizationDao).create(organizationCaptor.capture());
final OrganizationImpl createdOrganization = organizationCaptor.getValue();
assertEquals(createdOrganization.getName(), toCreate.getName());
assertEquals(createdOrganization.getQualifiedName(), toCreate.getName());
assertEquals(createdOrganization.getParent(), toCreate.getParent());
verify(eventService).publish(persistEventCaptor.capture());
assertEquals(persistEventCaptor.getValue().getOrganization(), createdOrganization);
verify(memberDao).store(new MemberImpl(USER_ID, createdOrganization.getId(), OrganizationDomain.getActions()));
}
use of org.eclipse.che.multiuser.organization.spi.impl.MemberImpl in project che-server by eclipse-che.
the class JpaMemberDao method getMember.
@Override
public MemberImpl getMember(String organizationId, String userId) throws NotFoundException, ServerException {
requireNonNull(organizationId, "Required non-null organization id");
requireNonNull(userId, "Required non-null user id");
try {
return new MemberImpl(getEntity(wildcardToNull(userId), organizationId));
} catch (RuntimeException e) {
throw new ServerException(e.getLocalizedMessage(), e);
}
}
use of org.eclipse.che.multiuser.organization.spi.impl.MemberImpl in project che-server by eclipse-che.
the class JpaMemberDao method getMembers.
@Override
@Transactional
public Page<MemberImpl> getMembers(String organizationId, int maxItems, long skipCount) throws ServerException {
requireNonNull(organizationId, "Required non-null organization 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<MemberImpl> members = manager.createNamedQuery("Member.getByOrganization", MemberImpl.class).setParameter("organizationId", organizationId).setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList().stream().map(MemberImpl::new).collect(toList());
final Long membersCount = manager.createNamedQuery("Member.getCountByOrganizationId", Long.class).setParameter("organizationId", organizationId).getSingleResult();
return new Page<>(members, skipCount, maxItems, membersCount);
} catch (RuntimeException e) {
throw new ServerException(e.getLocalizedMessage(), e);
}
}
Aggregations