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