use of org.olat.core.util.mail.ContactList in project openolat by klemens.
the class PublishController method sendInvitation.
private void sendInvitation(List<Identity> identities, MailTemplate mailTemplate) {
ContactList contactList = new ContactList("Invitation");
contactList.addAllIdentites(identities);
boolean success = false;
try {
MailContext context = new MailContextImpl(binder, null, getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setFromId(getIdentity());
bundle.setContactList(contactList);
bundle.setContent(mailTemplate.getSubjectTemplate(), mailTemplate.getBodyTemplate());
MailerResult result = mailManager.sendMessage(bundle);
success = result.isSuccessful();
} catch (Exception e) {
logError("Error on sending invitation mail to contactlist, invalid address.", e);
}
if (success) {
showInfo("invitation.mail.success");
} else {
showError("invitation.mail.failure");
}
}
use of org.olat.core.util.mail.ContactList in project OpenOLAT by OpenOLAT.
the class EPShareListController method sendInvitation.
/**
* sends a link to the map to permitted users by email
*
* @param ureq
* @param wrapper
*/
private void sendInvitation(UserRequest ureq, EPSharePolicyWrapper wrapper) {
EPMapPolicy.Type shareType = wrapper.getType();
List<Identity> identitiesToMail = new ArrayList<Identity>();
Invitation invitation = null;
if (shareType.equals(EPMapPolicy.Type.allusers)) {
return;
} else if (shareType.equals(EPMapPolicy.Type.invitation)) {
invitation = wrapper.getInvitation();
} else if (shareType.equals(EPMapPolicy.Type.group)) {
List<BusinessGroup> groups = wrapper.getGroups();
List<Identity> members = businessGroupService.getMembers(groups, GroupRoles.coach.name(), GroupRoles.participant.name());
identitiesToMail.addAll(members);
} else if (shareType.equals(EPMapPolicy.Type.user)) {
identitiesToMail = wrapper.getIdentities();
}
wrapper.setInvitationSend(true);
ContactList contactList = null;
if (identitiesToMail.size() == 1) {
contactList = new ContactList(identitiesToMail.get(0).getUser().getProperty(UserConstants.EMAIL, ureq.getLocale()));
} else {
contactList = new ContactList(translate("map.share.invitation.mail.list"));
}
contactList.addAllIdentites(identitiesToMail);
String busLink = "";
if (invitation != null) {
contactList.add(invitation.getMail());
busLink = getInvitationLink(invitation, map);
} else {
BusinessControlFactory bCF = BusinessControlFactory.getInstance();
ContextEntry mapCE = bCF.createContextEntry(map.getOlatResource());
ArrayList<ContextEntry> cEList = new ArrayList<ContextEntry>();
cEList.add(mapCE);
busLink = bCF.getAsURIString(cEList, true);
}
boolean success = false;
try {
String first = getIdentity().getUser().getProperty(UserConstants.FIRSTNAME, null);
String last = getIdentity().getUser().getProperty(UserConstants.LASTNAME, null);
String sender = first + " " + last;
String[] bodyArgs = new String[] { busLink, sender };
MailContext context = new MailContextImpl(map.getOlatResource(), null, getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setFrom(WebappHelper.getMailConfig("mailReplyTo"));
bundle.setContactList(contactList);
bundle.setContent(translate("map.share.invitation.mail.subject"), translate("map.share.invitation.mail.body", bodyArgs));
MailerResult result = mailManager.sendMessage(bundle);
success = result.isSuccessful();
} catch (Exception e) {
logError("Error on sending invitation mail to contactlist, invalid address.", e);
}
if (success) {
showInfo("map.share.invitation.mail.success");
} else {
showError("map.share.invitation.mail.failure");
}
}
use of org.olat.core.util.mail.ContactList in project OpenOLAT by OpenOLAT.
the class CatalogNodeManagerController method doContact.
private void doContact(UserRequest ureq) {
removeAsListenerAndDispose(cmc);
removeAsListenerAndDispose(contactCtrl);
ContactList caretaker = new ContactList(translate("contact.to.groupname.caretaker"));
List<Identity> owners = new ArrayList<Identity>();
CatalogEntry parent = catalogEntry;
while (parent != null && owners.isEmpty()) {
SecurityGroup parentOwner = parent.getOwnerGroup();
if (parentOwner != null) {
owners = securityManager.getIdentitiesOfSecurityGroup(parentOwner);
}
parent = parent.getParent();
}
for (int i = owners.size(); i-- > 0; ) {
caretaker.add(owners.get(i));
}
// create e-mail Message
ContactMessage cmsg = new ContactMessage(ureq.getIdentity());
cmsg.addEmailTo(caretaker);
contactCtrl = new ContactFormController(ureq, getWindowControl(), true, false, false, cmsg);
listenTo(contactCtrl);
// open form in dialog
cmc = new CloseableModalController(getWindowControl(), "close", contactCtrl.getInitialComponent(), true, translate("contact.caretaker"));
listenTo(cmc);
cmc.activate();
}
use of org.olat.core.util.mail.ContactList in project OpenOLAT by OpenOLAT.
the class MailManagerTest method testDeleteUserData_groupedMail.
@Test
public void testDeleteUserData_groupedMail() {
// send a mail to three ids
String metaId = UUID.randomUUID().toString();
Identity fromId = JunitTestHelper.createAndPersistIdentityAsUser("mail-7-" + UUID.randomUUID().toString());
Identity toId_1 = JunitTestHelper.createAndPersistIdentityAsUser("mail-8-" + UUID.randomUUID().toString());
Identity toId_2 = JunitTestHelper.createAndPersistIdentityAsUser("mail-9-" + UUID.randomUUID().toString());
Identity toId_3 = JunitTestHelper.createAndPersistIdentityAsUser("mail-10-" + UUID.randomUUID().toString());
ContactList ccs = new ContactList("unit-test-cc");
ccs.add(toId_1);
ccs.add(toId_2);
ccs.add(toId_3);
ccs.add(fromId);
MailBundle bundle = new MailBundle();
bundle.setFromId(fromId);
bundle.setContactList(ccs);
bundle.setMetaId(metaId);
bundle.setContent("Hello delList", "Content of delList");
MailerResult result = mailManager.sendMessage(bundle);
Assert.assertNotNull(result);
Assert.assertEquals(MailerResult.OK, result.getReturnCode());
dbInstance.commitAndCloseSession();
// delete the 4 users datas
mailBoxExtension.deleteUserData(toId_1, "lalala", null);
mailBoxExtension.deleteUserData(toId_2, "lalala", null);
mailBoxExtension.deleteUserData(toId_3, "lalala", null);
mailBoxExtension.deleteUserData(fromId, "lalala", null);
dbInstance.commitAndCloseSession();
// check inbox / outbox
List<DBMailLight> deletedMails_1 = mailManager.getInbox(toId_1, null, null, null, 0, -1);
Assert.assertNotNull(deletedMails_1);
Assert.assertTrue(deletedMails_1.isEmpty());
List<DBMailLight> deletedMails_2 = mailManager.getInbox(toId_2, null, null, null, 0, -1);
Assert.assertNotNull(deletedMails_2);
Assert.assertTrue(deletedMails_2.isEmpty());
List<DBMailLight> deletedMails_3 = mailManager.getInbox(toId_3, null, null, null, 0, -1);
Assert.assertNotNull(deletedMails_3);
Assert.assertTrue(deletedMails_3.isEmpty());
List<DBMailLight> deletedMails_4 = mailManager.getOutbox(fromId, 0, -1, true);
Assert.assertNotNull(deletedMails_4);
Assert.assertTrue(deletedMails_4.isEmpty());
// check mail by meta id
List<DBMailLight> deletedMails = mailManager.getEmailsByMetaId(metaId);
Assert.assertNotNull(deletedMails);
Assert.assertTrue(deletedMails.isEmpty());
}
use of org.olat.core.util.mail.ContactList in project OpenOLAT by OpenOLAT.
the class BusinessGroupServiceTest method allowToLeavingBusinessGroup_withCourse.
@Test
public void allowToLeavingBusinessGroup_withCourse() {
// authors group
RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("leave-bg-5-");
BusinessGroup group = businessGroupService.createBusinessGroup(null, "Leaving group", "But you cannot leave :-(", new Integer(0), new Integer(2), false, false, resource);
businessGroupRelationDao.addRole(participant, group, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
// set to not allowed to leave
group = businessGroupService.updateAllowToLeaveBusinessGroup(group, false);
dbInstance.commitAndCloseSession();
// check the authors group leaving option
LeaveOption optionToLeave = businessGroupService.isAllowToLeaveBusinessGroup(participant, group);
Assert.assertNotNull(optionToLeave);
Assert.assertFalse(optionToLeave.isAllowToLeave());
ContactList contacts = optionToLeave.getContacts();
Collection<Identity> contactList = contacts.getIdentiEmails().values();
Assert.assertNotNull(contactList);
Assert.assertFalse(contactList.isEmpty());
for (Identity contact : contactList) {
Roles roles = securityManager.getRoles(contact);
Assert.assertNotNull(roles);
Assert.assertTrue(roles.isOLATAdmin());
}
}
Aggregations