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