Search in sources :

Example 16 with GroupMembership

use of org.olat.basesecurity.GroupMembership in project openolat by klemens.

the class GroupDAOTest method createGroupMembership.

@Test
public void createGroupMembership() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-1-");
    Group group = groupDao.createGroup();
    GroupMembership membership = groupDao.addMembershipTwoWay(group, id, "author");
    dbInstance.commit();
    Assert.assertNotNull(membership);
}
Also used : Group(org.olat.basesecurity.Group) GroupMembership(org.olat.basesecurity.GroupMembership) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 17 with GroupMembership

use of org.olat.basesecurity.GroupMembership in project openolat by klemens.

the class OLATUpgrade_10_0_0 method processSecurityGroup.

private void processSecurityGroup(Group group, String role, SecurityGroup secGroup) {
    if (secGroup == null)
        return;
    List<SecurityGroupMembershipImpl> oldMemberships = getMembershipsOfSecurityGroup(secGroup);
    for (SecurityGroupMembershipImpl oldMembership : oldMemberships) {
        GroupMembershipImpl membership = new GroupMembershipImpl();
        membership.setCreationDate(oldMembership.getCreationDate());
        membership.setLastModified(oldMembership.getLastModified());
        membership.setGroup(group);
        membership.setIdentity(oldMembership.getIdentity());
        membership.setRole(role);
        dbInstance.getCurrentEntityManager().persist(membership);
        Set<GroupMembership> members = ((GroupImpl) group).getMembers();
        if (members == null) {
            members = new HashSet<>();
            ((GroupImpl) group).setMembers(members);
        }
        members.add(membership);
    }
}
Also used : SecurityGroupMembershipImpl(org.olat.basesecurity.SecurityGroupMembershipImpl) GroupImpl(org.olat.basesecurity.model.GroupImpl) GroupMembership(org.olat.basesecurity.GroupMembership) GroupMembershipImpl(org.olat.basesecurity.model.GroupMembershipImpl) SecurityGroupMembershipImpl(org.olat.basesecurity.SecurityGroupMembershipImpl)

Example 18 with GroupMembership

use of org.olat.basesecurity.GroupMembership in project openolat by klemens.

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);
        }
    }
}
Also used : GroupMembership(org.olat.basesecurity.GroupMembership) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 19 with GroupMembership

use of org.olat.basesecurity.GroupMembership in project openolat by klemens.

the class GroupDAO method removeMembership.

public int removeMembership(Group group, Identity identity) {
    EntityManager em = dbInstance.getCurrentEntityManager();
    List<GroupMembership> memberships = em.createNamedQuery("membershipsByGroupAndIdentity", GroupMembership.class).setParameter("groupKey", group.getKey()).setParameter("identityKey", identity.getKey()).getResultList();
    for (GroupMembership membership : memberships) {
        em.remove(membership);
    }
    return memberships.size();
}
Also used : EntityManager(javax.persistence.EntityManager) GroupMembership(org.olat.basesecurity.GroupMembership)

Example 20 with GroupMembership

use of org.olat.basesecurity.GroupMembership in project openolat by klemens.

the class GroupDAO method addMembershipTwoWay.

/**
 * Add a membership to the group, in the set of the group too which can be
 * reloaded.
 */
public GroupMembership addMembershipTwoWay(Group group, Identity identity, String role) {
    GroupMembershipImpl membership = new GroupMembershipImpl();
    membership.setCreationDate(new Date());
    membership.setLastModified(new Date());
    membership.setGroup(group);
    membership.setIdentity(identity);
    membership.setRole(role);
    dbInstance.getCurrentEntityManager().persist(membership);
    Set<GroupMembership> members = ((GroupImpl) group).getMembers();
    if (members == null) {
        members = new HashSet<>();
        ((GroupImpl) group).setMembers(members);
    }
    members.add(membership);
    return membership;
}
Also used : GroupImpl(org.olat.basesecurity.model.GroupImpl) GroupMembership(org.olat.basesecurity.GroupMembership) GroupMembershipImpl(org.olat.basesecurity.model.GroupMembershipImpl) Date(java.util.Date)

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