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);
}
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);
}
}
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);
}
}
}
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();
}
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;
}
Aggregations