Search in sources :

Example 1 with BusinessGroupMembershipsChanges

use of org.olat.group.model.BusinessGroupMembershipsChanges 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 2 with BusinessGroupMembershipsChanges

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

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)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 GroupRoles (org.olat.basesecurity.GroupRoles)2 Identity (org.olat.core.id.Identity)2 Roles (org.olat.core.id.Roles)2 BusinessGroup (org.olat.group.BusinessGroup)2 BusinessGroupMembershipChange (org.olat.group.model.BusinessGroupMembershipChange)2 BusinessGroupMembershipsChanges (org.olat.group.model.BusinessGroupMembershipsChanges)2 BusinessGroupModifiedEvent (org.olat.group.ui.edit.BusinessGroupModifiedEvent)2