use of org.olat.core.util.mail.MailPackage in project OpenOLAT by OpenOLAT.
the class BusinessGroupServiceImpl method transferFirstIdentityFromWaitingToParticipant.
/**
* Don't forget to lock the business group before calling this method.
* @param ureqIdentity
* @param group
* @param mailing
* @param syncIM
*/
private void transferFirstIdentityFromWaitingToParticipant(Identity ureqIdentity, BusinessGroup group, MailPackage mailing, List<BusinessGroupModifiedEvent.Deferred> events) {
// Check if waiting-list is enabled and auto-rank-up
if (group.getWaitingListEnabled() != null && group.getWaitingListEnabled().booleanValue() && group.getAutoCloseRanksEnabled() != null && group.getAutoCloseRanksEnabled().booleanValue()) {
// Check if participant is not full
Integer maxSize = group.getMaxParticipants();
int reservations = reservationDao.countReservations(group.getResource());
int partipiciantSize = businessGroupRelationDAO.countRoles(group, GroupRoles.participant.name());
if (maxSize != null && (partipiciantSize + reservations) < maxSize.intValue()) {
// ok it has free places => get first identities from waiting list
List<Identity> identities = businessGroupRelationDAO.getMembersOrderByDate(group, GroupRoles.waiting.name());
int counter = 0;
int freeSlot = maxSize - (partipiciantSize + reservations);
for (Identity firstWaitingListIdentity : identities) {
if (counter >= freeSlot) {
break;
}
// Check if firstWaitingListIdentity is not allready in participant-group
if (!businessGroupRelationDAO.hasRole(firstWaitingListIdentity, group, GroupRoles.participant.name())) {
// move the identity from the waitinglist to the participant group
ActionType formerStickyActionType = ThreadLocalUserActivityLogger.getStickyActionType();
try {
// OLAT-4955: force add-participant and remove-from-waitinglist logging actions
// that get triggered in the next two methods to be of ActionType admin
// This is needed to make sure the targetIdentity ends up in the o_loggingtable
ThreadLocalUserActivityLogger.setStickyActionType(ActionType.admin);
// Don't send mails for the sub-actions "adding to group" and "remove from waiting list", instead
// send a specific "graduate from waiting list" mailing a few lines below
MailPackage subMailing = new MailPackage(false);
addParticipant(ureqIdentity, null, firstWaitingListIdentity, group, subMailing, events);
removeFromWaitingList(ureqIdentity, firstWaitingListIdentity, group, subMailing, events);
} finally {
ThreadLocalUserActivityLogger.setStickyActionType(formerStickyActionType);
}
// Send mail to let user know he is now in group
if (mailing == null) {
mailing = new MailPackage(true);
}
BusinessGroupMailing.sendEmail(null, firstWaitingListIdentity, group, MailType.graduateFromWaitingListToParticpant, mailing);
counter++;
}
}
}
}
}
use of org.olat.core.util.mail.MailPackage in project OpenOLAT by OpenOLAT.
the class AbstractBusinessGroupListController method finishUserManagement.
private void finishUserManagement(MembershipModification mod, List<BusinessGroup> groups, MailTemplate template, boolean sendMail) {
MailPackage mailing = new MailPackage(template, getWindowControl().getBusinessControl().getAsString(), sendMail);
businessGroupService.updateMembership(getIdentity(), mod, groups, mailing);
MailHelper.printErrorsAndWarnings(mailing.getResult(), getWindowControl(), false, getLocale());
}
use of org.olat.core.util.mail.MailPackage 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.core.util.mail.MailPackage in project openolat by klemens.
the class RepositoryEntryMembershipProcessorTest method testRemoveParticipant.
@Test
public void testRemoveParticipant() {
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
// create a group with members
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-1");
Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-2");
Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");
repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name());
repositoryEntryRelationDao.addRole(member, re, GroupRoles.coach.name());
repositoryEntryRelationDao.addRole(member, re, GroupRoles.participant.name());
repositoryEntryRelationDao.addRole(participant, re, GroupRoles.participant.name());
// create a publisher
SubscriptionContext context = new SubscriptionContext(re.getOlatResource(), "");
PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
Assert.assertNotNull(publisher);
dbInstance.commitAndCloseSession();
// subscribe
notificationManager.subscribe(owner, context, publisherData);
notificationManager.subscribe(member, context, publisherData);
notificationManager.subscribe(participant, context, publisherData);
dbInstance.commitAndCloseSession();
// remove member and participant as participant of the repo entry
List<Identity> removeIdentities = new ArrayList<>(2);
removeIdentities.add(member);
removeIdentities.add(participant);
MailPackage mailing = new MailPackage(false);
repositoryManager.removeParticipants(owner, removeIdentities, re, mailing, false);
// wait for the remove of subscription
waitForCondition(new CheckUnsubscription(participant, context, dbInstance, notificationManager), 5000);
sleep(1000);
// check that subscription of id1 was deleted but not the ones of id2 and coach
boolean subscribedPart = notificationManager.isSubscribed(participant, context);
Assert.assertFalse(subscribedPart);
boolean subscribedMember = notificationManager.isSubscribed(member, context);
Assert.assertTrue(subscribedMember);
boolean subscribedOwner = notificationManager.isSubscribed(owner, context);
Assert.assertTrue(subscribedOwner);
}
use of org.olat.core.util.mail.MailPackage in project openolat by klemens.
the class RepositoryEntryMembershipProcessorTest method testRemoveCoach_withBusinessGroups.
@Test
public void testRemoveCoach_withBusinessGroups() {
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
// create a group with members
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-1");
Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-2");
Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");
repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name());
repositoryEntryRelationDao.addRole(member, re, GroupRoles.coach.name());
repositoryEntryRelationDao.addRole(coach, re, GroupRoles.coach.name());
BusinessGroup businessGroup = businessGroupDao.createAndPersist(coach, "mbr-proc-1", "mbr-proc-desc", -1, -1, false, false, false, false, false);
businessGroupRelationDao.addRelationToResource(businessGroup, re);
// create a publisher
SubscriptionContext context = new SubscriptionContext(re.getOlatResource(), "");
PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
Assert.assertNotNull(publisher);
dbInstance.commitAndCloseSession();
// subscribe
notificationManager.subscribe(owner, context, publisherData);
notificationManager.subscribe(member, context, publisherData);
notificationManager.subscribe(coach, context, publisherData);
dbInstance.commitAndCloseSession();
// remove member and coach as coach of the repo entry
List<Identity> removeIdentities = new ArrayList<>(2);
removeIdentities.add(member);
removeIdentities.add(coach);
repositoryManager.removeTutors(owner, removeIdentities, re, new MailPackage(false));
// wait for the remove of subscription
waitForCondition(new CheckUnsubscription(member, context, dbInstance, notificationManager), 5000);
sleep(1000);
// check that subscription of id1 was deleted but not the ones of id2 and coach
boolean subscribedMember = notificationManager.isSubscribed(member, context);
Assert.assertFalse(subscribedMember);
boolean subscribedCoach = notificationManager.isSubscribed(coach, context);
Assert.assertTrue(subscribedCoach);
boolean subscribedOwner = notificationManager.isSubscribed(owner, context);
Assert.assertTrue(subscribedOwner);
}
Aggregations