Search in sources :

Example 1 with GroupMembership

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GroupMembership(org.olat.basesecurity.GroupMembership) IdentitiesOfGroupTableDataModel(org.olat.admin.securitygroup.gui.IdentitiesOfGroupTableDataModel) Date(java.util.Date) GroupMemberView(org.olat.admin.securitygroup.gui.GroupMemberView) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) HashSet(java.util.HashSet)

Example 2 with GroupMembership

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());
}
Also used : Group(org.olat.basesecurity.Group) GroupImpl(org.olat.basesecurity.model.GroupImpl) GroupMembership(org.olat.basesecurity.GroupMembership) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 3 with GroupMembership

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);
}
Also used : Group(org.olat.basesecurity.Group) GroupMembership(org.olat.basesecurity.GroupMembership) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 4 with GroupMembership

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());
}
Also used : Group(org.olat.basesecurity.Group) GroupMembership(org.olat.basesecurity.GroupMembership) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 5 with GroupMembership

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);
}
Also used : Group(org.olat.basesecurity.Group) GroupMembership(org.olat.basesecurity.GroupMembership) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

GroupMembership (org.olat.basesecurity.GroupMembership)40 Identity (org.olat.core.id.Identity)30 Test (org.junit.Test)26 Group (org.olat.basesecurity.Group)26 GroupImpl (org.olat.basesecurity.model.GroupImpl)8 Date (java.util.Date)6 EntityManager (javax.persistence.EntityManager)6 GroupMembershipImpl (org.olat.basesecurity.model.GroupMembershipImpl)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 GroupMemberView (org.olat.admin.securitygroup.gui.GroupMemberView)2 IdentitiesOfGroupTableDataModel (org.olat.admin.securitygroup.gui.IdentitiesOfGroupTableDataModel)2 SecurityGroupMembershipImpl (org.olat.basesecurity.SecurityGroupMembershipImpl)2 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)2