use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.
the class GroupController method doAddIdentitiesToGroup.
/**
* Add users from the identites array to the group if they are not guest users
* and not already in the group
*
* @param ureq
* @param choosenIdentities
*/
private void doAddIdentitiesToGroup(UserRequest ureq, List<Identity> choosenIdentities, MailTemplate mailTemplate) {
// additional security check
if (!mayModifyMembers)
throw new AssertException("not allowed to add member!");
IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(choosenIdentities);
// process workflow to BusinessGroupManager via BusinessGroupEditController
fireEvent(ureq, identitiesAddedEvent);
if (!identitiesAddedEvent.getAddedIdentities().isEmpty()) {
// update table model
reloadData();
}
// build info message for identities which could be added.
StringBuilder infoMessage = new StringBuilder();
for (Identity identity : identitiesAddedEvent.getIdentitiesWithoutPermission()) {
infoMessage.append(translate("msg.isingroupanonymous", userManager.getUserDisplayName(identity))).append("<br />");
}
for (Identity identity : identitiesAddedEvent.getIdentitiesAlreadyInGroup()) {
infoMessage.append(translate("msg.subjectalreadyingroup", userManager.getUserDisplayName(identity))).append("<br />");
}
// send the notification mail fro added users
StringBuilder errorMessage = new StringBuilder();
if (mailTemplate != null) {
// means no sender in footer
Identity sender = null;
if (showSenderInAddMailFooter) {
sender = ureq.getIdentity();
}
String metaId = UUID.randomUUID().toString();
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailerResult result = new MailerResult();
MailBundle[] bundles = mailManager.makeMailBundles(context, identitiesAddedEvent.getAddedIdentities(), mailTemplate, sender, metaId, result);
result.append(mailManager.sendMessage(bundles));
if (mailTemplate.getCpfrom()) {
MailBundle ccBundle = mailManager.makeMailBundle(context, ureq.getIdentity(), mailTemplate, sender, metaId, result);
result.append(mailManager.sendMessage(ccBundle));
}
MailHelper.appendErrorsAndWarnings(result, errorMessage, infoMessage, ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
}
// report any errors on screen
if (infoMessage.length() > 0)
getWindowControl().setWarning(infoMessage.toString());
if (errorMessage.length() > 0)
getWindowControl().setError(errorMessage.toString());
}
use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.
the class ProjectBrokerMailerImpl method sendEmailProjectChanged.
private MailerResult sendEmailProjectChanged(List<Identity> group, Identity changer, Project project, String subject, String body, Locale locale) {
MailTemplate enrolledMailTemplate = this.createProjectChangeMailTemplate(project, changer, subject, body, locale);
// loop over all project manger
StringBuilder identityNames = new StringBuilder();
for (Identity identity : group) {
if (identityNames.length() > 0)
identityNames.append(",");
identityNames.append(identity.getName());
}
MailContext context = new MailContextImpl(project.getProjectBroker(), null, null);
MailerResult result = new MailerResult();
MailBundle[] bundles = mailManager.makeMailBundles(context, group, enrolledMailTemplate, null, null, result);
result.append(mailManager.sendMessage(bundles));
log.audit("ProjectBroker: sendEmailToGroup: identities=" + identityNames.toString() + " , mailerResult.returnCode=" + result.getReturnCode());
return result;
}
use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.
the class ProjectBrokerMailerImpl method sendEmailToGroup.
private MailerResult sendEmailToGroup(List<Identity> group, Identity enrolledIdentity, Project project, String subject, String body, Locale locale) {
MailTemplate enrolledMailTemplate = this.createMailTemplate(project, enrolledIdentity, subject, body, locale);
// loop over all project manger
StringBuilder identityNames = new StringBuilder();
for (Identity identity : group) {
if (identityNames.length() > 0)
identityNames.append(",");
identityNames.append(identity.getName());
}
MailContext context = new MailContextImpl(project.getProjectBroker(), null, null);
String metaId = UUID.randomUUID().toString().replace("-", "");
MailerResult result = new MailerResult();
MailBundle[] bundles = mailManager.makeMailBundles(context, group, enrolledMailTemplate, null, metaId, result);
result.append(mailManager.sendMessage(bundles));
log.audit("ProjectBroker: sendEmailToGroup: identities=" + identityNames.toString() + " , mailerResult.returnCode=" + result.getReturnCode());
return result;
}
use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.
the class InvitationEditRightsController method sendInvitation.
private void sendInvitation() {
String inviteeEmail = invitee.getUser().getProperty(UserConstants.EMAIL, getLocale());
ContactList contactList = new ContactList(inviteeEmail);
contactList.add(inviteeEmail);
boolean success = false;
try {
mailTemplate.setSubjectTemplate(subjectEl.getValue());
mailTemplate.setBodyTemplate(bodyEl.getValue());
MailContext context = new MailContextImpl(binder, null, getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setFromId(getIdentity());
bundle.setContactList(contactList);
bundle.setContent(subjectEl.getValue(), bodyEl.getValue());
MailerResult result = mailManager.sendExternMessage(bundle, null, true);
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.MailContextImpl in project openolat by klemens.
the class UnpublishResourceCallback method execute.
@Override
public Step execute(UserRequest ureq, WindowControl wControl, StepsRunContext runContext) {
MailTemplate mailTemplate = (MailTemplate) runContext.get("mailTemplate");
if (mailTemplate != null) {
List<Identity> ownerList = new ArrayList<Identity>();
// owners
if (repositoryService.hasRole(ureq.getIdentity(), repositoryEntry, GroupRoles.owner.name())) {
ownerList = repositoryService.getMembers(repositoryEntry, GroupRoles.owner.name());
}
String businessPath = wControl.getBusinessControl().getAsString();
MailContext context = new MailContextImpl(businessPath);
String metaId = UUID.randomUUID().toString().replace("-", "");
MailerResult result = new MailerResult();
MailBundle[] bundles = mailManager.makeMailBundles(context, ownerList, mailTemplate, ureq.getIdentity(), metaId, result);
result.append(mailManager.sendMessage(bundles));
if (mailTemplate.getCpfrom()) {
MailBundle ccBundle = mailManager.makeMailBundle(context, ureq.getIdentity(), mailTemplate, ureq.getIdentity(), metaId, result);
result.append(mailManager.sendMessage(ccBundle));
}
StringBuilder errorMessage = new StringBuilder();
StringBuilder warningMessage = new StringBuilder();
MailHelper.appendErrorsAndWarnings(result, errorMessage, warningMessage, ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
if (warningMessage.length() > 0) {
wControl.setWarning(warningMessage.toString());
}
if (errorMessage.length() > 0) {
wControl.setError(errorMessage.toString());
}
ownerList.clear();
}
// update status
repositoryEntry = repositoryService.loadByKey(repositoryEntry.getKey());
repositoryEntry.setStatusCode(RepositoryEntryStatus.REPOSITORY_STATUS_CLOSED);
repositoryEntry = DBFactory.getInstance().getCurrentEntityManager().merge(repositoryEntry);
// clean catalog
Object cleanCatalog = runContext.get("cleanCatalog");
if (cleanCatalog != null && Boolean.TRUE.equals(cleanCatalog)) {
CoreSpringFactory.getImpl(CatalogManager.class).resourceableDeleted(repositoryEntry);
}
// clean groups
Object cleanGroups = runContext.get("cleanGroups");
if (cleanGroups != null && Boolean.TRUE.equals(cleanGroups)) {
doCleanGroups(ureq.getIdentity());
}
ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_EDITOR_CLOSE, getClass());
log.audit("Repository entry " + repositoryEntry.getDisplayname() + " ( " + repositoryEntry.getOlatResource() + " ) closed");
return StepsMainRunController.DONE_MODIFIED;
}
Aggregations