use of org.olat.basesecurity.GroupMembership in project openolat by klemens.
the class GroupDAOTest method countMembers.
@Test
public void countMembers() {
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-4-");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-5-");
Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-6-");
Group group = groupDao.createGroup();
GroupMembership membership1 = groupDao.addMembershipTwoWay(group, id1, "pilot");
GroupMembership membership2 = groupDao.addMembershipTwoWay(group, id2, "pilot");
GroupMembership membership3 = groupDao.addMembershipTwoWay(group, id3, "copilot");
dbInstance.commit();
Assert.assertNotNull(membership1);
Assert.assertNotNull(membership2);
Assert.assertNotNull(membership3);
dbInstance.commitAndCloseSession();
int numOfMembers = groupDao.countMembers(group);
Assert.assertEquals(3, numOfMembers);
}
use of org.olat.basesecurity.GroupMembership in project openolat by klemens.
the class GroupDAOTest method removeMembership.
@Test
public void removeMembership() {
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-7-");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-8-");
Group group = groupDao.createGroup();
GroupMembership membership1 = groupDao.addMembershipTwoWay(group, id1, "pilot");
GroupMembership membership2 = groupDao.addMembershipTwoWay(group, id2, "pilot");
Assert.assertNotNull(membership1);
Assert.assertNotNull(membership2);
dbInstance.commitAndCloseSession();
// check
List<GroupMembership> memberships = groupDao.getMemberships(group, "pilot");
Assert.assertEquals(2, memberships.size());
// remove
groupDao.removeMembership(group, id1);
dbInstance.commitAndCloseSession();
// check
List<GroupMembership> deletedMemberships = groupDao.getMemberships(group, "pilot");
Assert.assertEquals(1, deletedMemberships.size());
Identity stayingMember = deletedMemberships.get(0).getIdentity();
Assert.assertNotNull(stayingMember);
Assert.assertEquals(id2, stayingMember);
}
use of org.olat.basesecurity.GroupMembership in project openolat by klemens.
the class GroupDAOTest method removeMemberships_identity.
@Test
public void removeMemberships_identity() {
//
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-9-");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-10-");
Group group1 = groupDao.createGroup();
GroupMembership membership1 = groupDao.addMembershipTwoWay(group1, id1, "pilot");
GroupMembership membership2 = groupDao.addMembershipTwoWay(group1, id2, "pilot");
Assert.assertNotNull(membership1);
Assert.assertNotNull(membership2);
dbInstance.commitAndCloseSession();
Group group2 = groupDao.createGroup();
GroupMembership membership3 = groupDao.addMembershipTwoWay(group2, id1, "passanger");
GroupMembership membership4 = groupDao.addMembershipTwoWay(group2, id2, "passanger");
Assert.assertNotNull(membership3);
Assert.assertNotNull(membership4);
dbInstance.commitAndCloseSession();
// check
List<GroupMembership> memberships = groupDao.getMemberships(group1, "pilot");
Assert.assertEquals(2, memberships.size());
// remove
groupDao.removeMemberships(id1);
dbInstance.commitAndCloseSession();
// check
List<GroupMembership> deletedMemberships1 = groupDao.getMemberships(group1, "pilot");
Assert.assertEquals(1, deletedMemberships1.size());
Assert.assertEquals(membership2, deletedMemberships1.get(0));
List<GroupMembership> deletedMemberships2 = groupDao.getMemberships(group2, "passanger");
Assert.assertEquals(1, deletedMemberships2.size());
Assert.assertEquals(membership4, deletedMemberships2.get(0));
}
use of org.olat.basesecurity.GroupMembership in project openolat by klemens.
the class GroupDAO method removeMemberships.
public int removeMemberships(Group group) {
EntityManager em = dbInstance.getCurrentEntityManager();
List<GroupMembership> memberships = em.createNamedQuery("membershipsByGroup", GroupMembership.class).setParameter("groupKey", group.getKey()).getResultList();
for (GroupMembership membership : memberships) {
em.remove(membership);
}
return memberships.size();
}
use of org.olat.basesecurity.GroupMembership in project openolat by klemens.
the class GroupDAO method removeMembership.
public int removeMembership(Group group, IdentityRef identity, String role) {
EntityManager em = dbInstance.getCurrentEntityManager();
List<GroupMembership> memberships = em.createNamedQuery("membershipsByGroupIdentityAndRole", GroupMembership.class).setParameter("groupKey", group.getKey()).setParameter("identityKey", identity.getKey()).setParameter("role", role).getResultList();
for (GroupMembership membership : memberships) {
em.remove(membership);
}
return memberships.size();
}
Aggregations