Search in sources :

Example 6 with BusinessGroupMembershipChange

use of org.olat.group.model.BusinessGroupMembershipChange in project OpenOLAT by OpenOLAT.

the class BusinessGroupServiceImpl method updateMemberships.

@Override
public void updateMemberships(final Identity ureqIdentity, final List<BusinessGroupMembershipChange> changes, MailPackage mailing) {
    Roles ureqRoles = securityManager.getRoles(ureqIdentity);
    Map<Long, BusinessGroupMembershipsChanges> changesMap = new HashMap<Long, BusinessGroupMembershipsChanges>();
    for (BusinessGroupMembershipChange change : changes) {
        BusinessGroupMembershipsChanges changesWrapper;
        if (changesMap.containsKey(change.getGroupKey())) {
            changesWrapper = changesMap.get(change.getGroupKey());
        } else {
            changesWrapper = new BusinessGroupMembershipsChanges();
            changesMap.put(change.getGroupKey(), changesWrapper);
        }
        Identity id = change.getMember();
        if (change.getTutor() != null) {
            if (change.getTutor().booleanValue()) {
                changesWrapper.addTutors.add(id);
            } else {
                changesWrapper.removeTutors.add(id);
            }
        }
        if (change.getParticipant() != null) {
            if (change.getParticipant().booleanValue()) {
                changesWrapper.addParticipants.add(id);
            } else {
                changesWrapper.removeParticipants.add(id);
            }
        }
        if (change.getWaitingList() != null) {
            if (change.getWaitingList().booleanValue()) {
                changesWrapper.addToWaitingList.add(id);
            } else {
                changesWrapper.removeFromWaitingList.add(id);
            }
        }
    }
    List<BusinessGroupModifiedEvent.Deferred> events = new ArrayList<BusinessGroupModifiedEvent.Deferred>();
    List<BusinessGroup> groups = loadBusinessGroups(changesMap.keySet());
    for (BusinessGroup group : groups) {
        BusinessGroupMembershipsChanges changesWrapper = changesMap.get(group.getKey());
        group = businessGroupDAO.loadForUpdate(group);
        for (Identity id : changesWrapper.addToWaitingList) {
            addToWaitingList(ureqIdentity, id, group, mailing, events);
        }
        for (Identity id : changesWrapper.removeFromWaitingList) {
            removeFromWaitingList(ureqIdentity, id, group, mailing, events);
        }
        for (Identity id : changesWrapper.addTutors) {
            addOwner(ureqIdentity, ureqRoles, id, group, mailing, events);
        }
        for (Identity id : changesWrapper.removeTutors) {
            removeOwner(ureqIdentity, id, group, events);
        }
        for (Identity id : changesWrapper.addParticipants) {
            addParticipant(ureqIdentity, ureqRoles, id, group, mailing, events);
        }
        for (Identity id : changesWrapper.removeParticipants) {
            removeParticipant(ureqIdentity, id, group, mailing, events);
        }
        // release lock
        dbInstance.commit();
    }
    BusinessGroupModifiedEvent.fireDeferredEvents(events);
}
Also used : HashMap(java.util.HashMap) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) BusinessGroupModifiedEvent(org.olat.group.ui.edit.BusinessGroupModifiedEvent) BusinessGroupMembershipChange(org.olat.group.model.BusinessGroupMembershipChange) BusinessGroupMembershipsChanges(org.olat.group.model.BusinessGroupMembershipsChanges) Identity(org.olat.core.id.Identity)

Example 7 with BusinessGroupMembershipChange

use of org.olat.group.model.BusinessGroupMembershipChange in project OpenOLAT by OpenOLAT.

the class AbstractMemberListController method doChangePermission.

protected void doChangePermission(UserRequest ureq, MemberPermissionChangeEvent changes, List<Identity> members, boolean sendMail) {
    MailPackage mailing = new MailPackage(sendMail);
    if (repoEntry != null) {
        List<RepositoryEntryPermissionChangeEvent> repoChanges = changes.generateRepositoryChanges(members);
        repositoryManager.updateRepositoryEntryMemberships(getIdentity(), ureq.getUserSession().getRoles(), repoEntry, repoChanges, mailing);
    }
    // commit all changes to the group memberships
    List<BusinessGroupMembershipChange> allModifications = changes.generateBusinessGroupMembershipChange(members);
    businessGroupService.updateMemberships(getIdentity(), allModifications, mailing);
    reloadModel();
}
Also used : BusinessGroupMembershipChange(org.olat.group.model.BusinessGroupMembershipChange) MailPackage(org.olat.core.util.mail.MailPackage) RepositoryEntryPermissionChangeEvent(org.olat.repository.model.RepositoryEntryPermissionChangeEvent)

Example 8 with BusinessGroupMembershipChange

use of org.olat.group.model.BusinessGroupMembershipChange in project openolat by klemens.

the class BusinessGroupServiceTest method testUpdateMemberships.

@Test
public void testUpdateMemberships() {
    // create a group with owner and participant
    Identity ureqIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mships-u-");
    Identity ownerIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mships-o-");
    Identity partIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mships-p-");
    BusinessGroup group = businessGroupService.createBusinessGroup(ureqIdentity, "Up-mships", "updateMemberships", 0, 10, false, false, null);
    businessGroupRelationDao.addRole(ownerIdentity, group, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(partIdentity, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // invert the roles
    BusinessGroupMembershipChange change1 = new BusinessGroupMembershipChange(ownerIdentity, group.getKey());
    change1.setTutor(Boolean.FALSE);
    change1.setParticipant(Boolean.TRUE);
    BusinessGroupMembershipChange change2 = new BusinessGroupMembershipChange(partIdentity, group.getKey());
    change2.setTutor(Boolean.TRUE);
    change2.setParticipant(Boolean.FALSE);
    List<BusinessGroupMembershipChange> changes = new ArrayList<BusinessGroupMembershipChange>();
    changes.add(change1);
    changes.add(change2);
    businessGroupService.updateMemberships(ureqIdentity, changes, new MailPackage(false));
    dbInstance.commitAndCloseSession();
    // check the result
    boolean partIsOwner = businessGroupService.hasRoles(partIdentity, group, GroupRoles.coach.name());
    Assert.assertTrue(partIsOwner);
    boolean partIsPart = businessGroupService.hasRoles(partIdentity, group, GroupRoles.participant.name());
    Assert.assertFalse(partIsPart);
    boolean ownerIsPart = businessGroupService.hasRoles(ownerIdentity, group, GroupRoles.participant.name());
    Assert.assertTrue(ownerIsPart);
    boolean ownerIsOwner = businessGroupService.hasRoles(ownerIdentity, group, GroupRoles.coach.name());
    Assert.assertFalse(ownerIsOwner);
}
Also used : BusinessGroupMembershipChange(org.olat.group.model.BusinessGroupMembershipChange) MailPackage(org.olat.core.util.mail.MailPackage) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 9 with BusinessGroupMembershipChange

use of org.olat.group.model.BusinessGroupMembershipChange in project openolat by klemens.

the class GroupOverviewController method doAddToGroups.

private void doAddToGroups(AddToGroupsEvent e, boolean sendMail) {
    List<BusinessGroupMembershipChange> changes = new ArrayList<BusinessGroupMembershipChange>();
    if (e.getOwnerGroupKeys() != null && !e.getOwnerGroupKeys().isEmpty()) {
        for (Long tutorGroupKey : e.getOwnerGroupKeys()) {
            BusinessGroupMembershipChange change = new BusinessGroupMembershipChange(identity, tutorGroupKey);
            change.setTutor(Boolean.TRUE);
            changes.add(change);
        }
    }
    if (e.getParticipantGroupKeys() != null && !e.getParticipantGroupKeys().isEmpty()) {
        for (Long partGroupKey : e.getParticipantGroupKeys()) {
            BusinessGroupMembershipChange change = new BusinessGroupMembershipChange(identity, partGroupKey);
            change.setParticipant(Boolean.TRUE);
            changes.add(change);
        }
    }
    MailPackage mailing = new MailPackage(sendMail);
    businessGroupService.updateMemberships(getIdentity(), changes, mailing);
}
Also used : BusinessGroupMembershipChange(org.olat.group.model.BusinessGroupMembershipChange) MailPackage(org.olat.core.util.mail.MailPackage) ArrayList(java.util.ArrayList)

Example 10 with BusinessGroupMembershipChange

use of org.olat.group.model.BusinessGroupMembershipChange in project OpenOLAT by OpenOLAT.

the class BusinessGroupServiceTest method testUpdateMemberships.

@Test
public void testUpdateMemberships() {
    // create a group with owner and participant
    Identity ureqIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mships-u-");
    Identity ownerIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mships-o-");
    Identity partIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mships-p-");
    BusinessGroup group = businessGroupService.createBusinessGroup(ureqIdentity, "Up-mships", "updateMemberships", 0, 10, false, false, null);
    businessGroupRelationDao.addRole(ownerIdentity, group, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(partIdentity, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // invert the roles
    BusinessGroupMembershipChange change1 = new BusinessGroupMembershipChange(ownerIdentity, group.getKey());
    change1.setTutor(Boolean.FALSE);
    change1.setParticipant(Boolean.TRUE);
    BusinessGroupMembershipChange change2 = new BusinessGroupMembershipChange(partIdentity, group.getKey());
    change2.setTutor(Boolean.TRUE);
    change2.setParticipant(Boolean.FALSE);
    List<BusinessGroupMembershipChange> changes = new ArrayList<BusinessGroupMembershipChange>();
    changes.add(change1);
    changes.add(change2);
    businessGroupService.updateMemberships(ureqIdentity, changes, new MailPackage(false));
    dbInstance.commitAndCloseSession();
    // check the result
    boolean partIsOwner = businessGroupService.hasRoles(partIdentity, group, GroupRoles.coach.name());
    Assert.assertTrue(partIsOwner);
    boolean partIsPart = businessGroupService.hasRoles(partIdentity, group, GroupRoles.participant.name());
    Assert.assertFalse(partIsPart);
    boolean ownerIsPart = businessGroupService.hasRoles(ownerIdentity, group, GroupRoles.participant.name());
    Assert.assertTrue(ownerIsPart);
    boolean ownerIsOwner = businessGroupService.hasRoles(ownerIdentity, group, GroupRoles.coach.name());
    Assert.assertFalse(ownerIsOwner);
}
Also used : BusinessGroupMembershipChange(org.olat.group.model.BusinessGroupMembershipChange) MailPackage(org.olat.core.util.mail.MailPackage) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

BusinessGroupMembershipChange (org.olat.group.model.BusinessGroupMembershipChange)22 Identity (org.olat.core.id.Identity)16 MailPackage (org.olat.core.util.mail.MailPackage)16 ArrayList (java.util.ArrayList)14 List (java.util.List)6 MailTemplate (org.olat.core.util.mail.MailTemplate)6 MemberPermissionChangeEvent (org.olat.group.ui.main.MemberPermissionChangeEvent)6 RepositoryEntryPermissionChangeEvent (org.olat.repository.model.RepositoryEntryPermissionChangeEvent)6 Roles (org.olat.core.id.Roles)4 MailerResult (org.olat.core.util.mail.MailerResult)4 BusinessGroup (org.olat.group.BusinessGroup)4 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2 VelocityContext (org.apache.velocity.VelocityContext)2 Context (org.apache.velocity.context.Context)2 Test (org.junit.Test)2 GroupRoles (org.olat.basesecurity.GroupRoles)2 SecurityGroup (org.olat.basesecurity.SecurityGroup)2 ValidationError (org.olat.core.gui.components.form.ValidationError)2 Translator (org.olat.core.gui.translator.Translator)2