use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class GroupController method reloadData.
public void reloadData() {
// refresh view
List<GroupMembership> combo = groupDao.getMemberships(group, role);
List<GroupMemberView> views = new ArrayList<GroupMemberView>(combo.size());
Map<Long, GroupMemberView> idToViews = new HashMap<Long, GroupMemberView>();
Set<Long> loadStatus = new HashSet<Long>();
for (GroupMembership co : combo) {
Identity identity = co.getIdentity();
Date addedAt = co.getCreationDate();
String onlineStatus = null;
if (chatEnabled) {
if (getIdentity().equals(identity)) {
onlineStatus = "me";
} else if (sessionManager.isOnline(identity.getKey())) {
loadStatus.add(identity.getKey());
} else {
onlineStatus = Presence.unavailable.name();
}
}
GroupMemberView member = new GroupMemberView(identity, addedAt, onlineStatus);
views.add(member);
idToViews.put(identity.getKey(), member);
}
if (loadStatus.size() > 0) {
List<Long> statusToLoadList = new ArrayList<Long>(loadStatus);
Map<Long, String> statusMap = imService.getBuddyStatus(statusToLoadList);
for (Long toLoad : statusToLoadList) {
String status = statusMap.get(toLoad);
GroupMemberView member = idToViews.get(toLoad);
if (status == null) {
member.setOnlineStatus(Presence.available.name());
} else {
member.setOnlineStatus(status);
}
}
}
List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(usageIdentifyer, isAdministrativeUser);
identitiesTableModel = new IdentitiesOfGroupTableDataModel(views, getLocale(), userPropertyHandlers, isAdministrativeUser);
tableCtr.setTableDataModel(identitiesTableModel);
}
use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class GroupDAOTest method createGroupMembership_v2.
@Test
public void createGroupMembership_v2() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-1-");
Group group = groupDao.createGroup();
GroupMembership membership = groupDao.addMembershipTwoWay(group, id, "author");
dbInstance.commit();
Assert.assertNotNull(membership);
dbInstance.getCurrentEntityManager().detach(group);
dbInstance.commitAndCloseSession();
GroupImpl loadedGroup = (GroupImpl) groupDao.loadGroup(group.getKey());
Assert.assertNotNull(loadedGroup);
Set<GroupMembership> members = loadedGroup.getMembers();
Assert.assertNotNull(members);
Assert.assertEquals(1, members.size());
}
use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class GroupDAOTest method hasRole.
@Test
public void hasRole() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-2-");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-2b-");
Group group = groupDao.createGroup();
GroupMembership membership = groupDao.addMembershipTwoWay(group, id, "author");
dbInstance.commit();
Assert.assertNotNull(membership);
dbInstance.commitAndCloseSession();
boolean hasRole = groupDao.hasRole(group, id, "author");
Assert.assertTrue(hasRole);
// negative tests
boolean hasNotRole = groupDao.hasRole(group, id, "pilot");
Assert.assertFalse(hasNotRole);
boolean id2_hasNotRole = groupDao.hasRole(group, id2, "author");
Assert.assertFalse(id2_hasNotRole);
}
use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class GroupDAOTest method removeMemberships_groupAndRole.
@Test
public void removeMemberships_groupAndRole() {
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-12-");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-13-");
Group group = groupDao.createGroup();
GroupMembership membership1 = groupDao.addMembershipTwoWay(group, id1, "pilot");
GroupMembership membership2 = groupDao.addMembershipTwoWay(group, id2, "copilot");
Assert.assertNotNull(membership1);
Assert.assertNotNull(membership2);
dbInstance.commitAndCloseSession();
// check
int numOfMembers = groupDao.countMembers(group);
Assert.assertEquals(2, numOfMembers);
// remove
int numOfDeletedRows = groupDao.removeMemberships(group, "pilot");
dbInstance.commitAndCloseSession();
Assert.assertEquals(1, numOfDeletedRows);
// check
List<GroupMembership> deletedMemberships = groupDao.getMemberships(group, "pilot");
Assert.assertTrue(deletedMemberships.isEmpty());
List<GroupMembership> lastMemberships = groupDao.getMemberships(group, "copilot");
Assert.assertEquals(1, lastMemberships.size());
}
use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
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);
}
Aggregations