use of org.olat.core.util.mail.MailPackage in project openolat by klemens.
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 klemens.
the class BusinessGroupServiceTest method testUpdateMembership.
@Test
public void testUpdateMembership() {
// create a group with owner and participant
Identity ureqIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mship-u-");
Identity ownerIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mship-o-");
Identity partIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mship-p-");
BusinessGroup group = businessGroupService.createBusinessGroup(ureqIdentity, "Up-mship", "updateMembership", 0, 10, false, false, null);
businessGroupRelationDao.addRole(ownerIdentity, group, GroupRoles.coach.name());
businessGroupRelationDao.addRole(partIdentity, group, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
// update memberships
MailPackage mailing = new MailPackage(false);
List<BusinessGroup> groups = Collections.singletonList(group);
MembershipModification membersMod = new MembershipModification();
membersMod.getAddOwners().add(partIdentity);
membersMod.getAddParticipants().add(ownerIdentity);
businessGroupService.updateMembership(ureqIdentity, membersMod, groups, mailing);
dbInstance.commitAndCloseSession();
// check if the participant is owner too and the owner is participant too
boolean partIsOwner = businessGroupService.hasRoles(partIdentity, group, GroupRoles.coach.name());
Assert.assertTrue(partIsOwner);
boolean partIsPart = businessGroupService.hasRoles(partIdentity, group, GroupRoles.participant.name());
Assert.assertTrue(partIsPart);
boolean ownerIsOwner = businessGroupService.hasRoles(ownerIdentity, group, GroupRoles.coach.name());
Assert.assertTrue(ownerIsOwner);
boolean ownerIsPart = businessGroupService.hasRoles(ownerIdentity, group, GroupRoles.participant.name());
Assert.assertTrue(ownerIsPart);
}
use of org.olat.core.util.mail.MailPackage 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.core.util.mail.MailPackage in project openolat by klemens.
the class BusinessGroupMembershipProcessorTest method testUnlinkMemberOfBusinessGroup.
@Test
public void testUnlinkMemberOfBusinessGroup() {
// create a group with members
Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-1");
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-2");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");
BusinessGroup businessGroup = businessGroupDao.createAndPersist(coach, "mbr-proc-1", "mbr-proc-desc", -1, -1, false, false, false, false, false);
businessGroupRelationDao.addRole(id1, businessGroup, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id2, businessGroup, GroupRoles.participant.name());
// create a publisher
SubscriptionContext context = new SubscriptionContext(businessGroup, "");
PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
Assert.assertNotNull(publisher);
dbInstance.commitAndCloseSession();
// subscribe
notificationManager.subscribe(coach, context, publisherData);
notificationManager.subscribe(id1, context, publisherData);
notificationManager.subscribe(id2, context, publisherData);
dbInstance.commitAndCloseSession();
// remove id1 and check subscription
MailPackage mailing = new MailPackage(false);
List<Identity> identitiesToRemove = Collections.singletonList(id1);
businessGroupService.removeParticipants(coach, identitiesToRemove, businessGroup, mailing);
// wait for the remove of subscription
waitForCondition(new CheckUnsubscription(id1, context, dbInstance, notificationManager), 5000);
// check that subscription of id1 was deleted but not the ones of id2 and coach
boolean subscribedId1 = notificationManager.isSubscribed(id1, context);
Assert.assertFalse(subscribedId1);
boolean subscribedId2 = notificationManager.isSubscribed(id2, context);
Assert.assertTrue(subscribedId2);
boolean subscribedCoach = notificationManager.isSubscribed(coach, context);
Assert.assertTrue(subscribedCoach);
}
use of org.olat.core.util.mail.MailPackage in project openolat by klemens.
the class AbstractMemberListController method doChangePermission.
protected void doChangePermission(UserRequest ureq, MemberPermissionChangeEvent e, boolean sendMail) {
MailPackage mailing = new MailPackage(sendMail);
if (repoEntry != null) {
List<RepositoryEntryPermissionChangeEvent> changes = Collections.singletonList((RepositoryEntryPermissionChangeEvent) e);
repositoryManager.updateRepositoryEntryMemberships(getIdentity(), ureq.getUserSession().getRoles(), repoEntry, changes, mailing);
}
businessGroupService.updateMemberships(getIdentity(), e.getGroupChanges(), mailing);
// make sure all is committed before loading the model again (I see issues without)
DBFactory.getInstance().commitAndCloseSession();
reloadModel();
}
Aggregations