use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class BusinessGroupArchiver method appendIdentityTable.
private void appendIdentityTable(StringBuffer buf, List<GroupMembership> members, String role, String title, Translator translator) {
appendTitle(buf, title);
appendIdentityTableHeader(buf, translator);
for (GroupMembership membership : members) {
if (role.equals(membership.getRole())) {
Identity identity = membership.getIdentity();
Date addedTo = membership.getCreationDate();
appendIdentity(buf, identity, addedTo, translator);
}
}
}
use of org.olat.basesecurity.GroupMembership in project openolat by klemens.
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 klemens.
the class GroupDAOTest method getMemberships.
@Test
public void getMemberships() {
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();
List<GroupMembership> members = groupDao.getMemberships(group, "author");
Assert.assertNotNull(members);
Assert.assertEquals(1, members.size());
}
use of org.olat.basesecurity.GroupMembership in project openolat by klemens.
the class GroupDAOTest method removeMembership_byRole.
@Test
public void removeMembership_byRole() {
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");
GroupMembership membership2alt = groupDao.addMembershipTwoWay(group, id2, "commander");
Assert.assertNotNull(membership1);
Assert.assertNotNull(membership2);
Assert.assertNotNull(membership2alt);
dbInstance.commitAndCloseSession();
// check
List<GroupMembership> memberships = groupDao.getMemberships(group, "pilot");
Assert.assertEquals(2, memberships.size());
List<GroupMembership> membershipsAlt = groupDao.getMemberships(group, "commander");
Assert.assertEquals(1, membershipsAlt.size());
// remove
groupDao.removeMembership(group, id2, "pilot");
dbInstance.commitAndCloseSession();
// check pilots
List<GroupMembership> stayingMemberships = groupDao.getMemberships(group, "pilot");
Assert.assertEquals(1, stayingMemberships.size());
Identity stayingMember = stayingMemberships.get(0).getIdentity();
Assert.assertNotNull(stayingMember);
Assert.assertEquals(id1, stayingMember);
// check commanders
List<GroupMembership> stayingMembershipsAlt = groupDao.getMemberships(group, "commander");
Assert.assertEquals(1, stayingMembershipsAlt.size());
Identity stayingMemberAlt = stayingMembershipsAlt.get(0).getIdentity();
Assert.assertNotNull(stayingMemberAlt);
Assert.assertEquals(id2, stayingMemberAlt);
}
use of org.olat.basesecurity.GroupMembership in project openolat by klemens.
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());
}
Aggregations