use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.
the class InfoMessageFrontendManagerImpl method sendInfoMessage.
@Override
public boolean sendInfoMessage(InfoMessage infoMessage, MailFormatter mailFormatter, Locale locale, Identity from, List<Identity> tos) {
infoMessageManager.saveInfoMessage(infoMessage);
boolean send = false;
if (tos != null && !tos.isEmpty()) {
Set<Long> identityKeySet = new HashSet<Long>();
ContactList contactList = new ContactList("Infos");
for (Identity to : tos) {
if (identityKeySet.contains(to.getKey()))
continue;
contactList.add(to);
identityKeySet.add(to.getKey());
}
try {
String subject = null;
String body = null;
if (mailFormatter != null) {
subject = mailFormatter.getSubject(infoMessage);
body = mailFormatter.getBody(infoMessage);
}
if (!StringHelper.containsNonWhitespace(subject)) {
subject = infoMessage.getTitle();
}
if (!StringHelper.containsNonWhitespace(body)) {
body = infoMessage.getMessage();
}
File attachment = null;
if (StringHelper.containsNonWhitespace(infoMessage.getAttachmentPath())) {
File root = getStoragePath().getBasefile();
attachment = new File(root, infoMessage.getAttachmentPath());
}
MailContext context = new MailContextImpl(mailFormatter.getBusinessPath());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setFromId(from);
bundle.setContactList(contactList);
if (attachment != null) {
bundle.setContent(subject, body, attachment);
} else {
bundle.setContent(subject, body);
}
MailerResult result = mailManager.sendMessage(bundle);
send = result.isSuccessful();
} catch (Exception e) {
log.error("Cannot send info messages", e);
}
}
infoSubscriptionManager.markPublisherNews(infoMessage.getOLATResourceable(), infoMessage.getResSubPath());
MultiUserEvent mue = new MultiUserEvent("new_info_message");
coordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(mue, oresFrontend);
return send;
}
use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.
the class EnrollmentManager method addUserToWaitingList.
private boolean addUserToWaitingList(Identity identity, BusinessGroup group, ENCourseNode enNode, CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans) {
// <- moved to bgs 1. Add user to group, fire events, do loggin etc.
// 2. Set first waiting-list date
String nowString = Long.toString(System.currentTimeMillis());
Property firstTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_INITIAL_WAITINGLIST_DATE);
if (firstTime == null) {
// create firsttime
firstTime = coursePropertyManager.createCourseNodePropertyInstance(enNode, identity, null, ENCourseNode.PROPERTY_INITIAL_WAITINGLIST_DATE, null, null, nowString, null);
coursePropertyManager.saveProperty(firstTime);
}
// 3. Set waiting-list date property
Property thisTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_WAITINGLIST_DATE);
if (thisTime == null) {
// create firsttime
thisTime = coursePropertyManager.createCourseNodePropertyInstance(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_WAITINGLIST_DATE, null, null, nowString, null);
coursePropertyManager.saveProperty(thisTime);
} else {
thisTime.setStringValue(nowString);
coursePropertyManager.updateProperty(thisTime);
}
// 4. Send notification mail
MailTemplate mailTemplate = BGMailHelper.createAddWaitinglistMailTemplate(group, identity);
// fxdiff VCRP-16: intern mail system
MailContext context = new MailContextImpl(wControl.getBusinessControl().getAsString());
MailerResult result = new MailerResult();
MailBundle bundle = mailManager.makeMailBundle(context, identity, mailTemplate, null, null, result);
if (bundle != null) {
mailManager.sendMessage(bundle);
}
MailHelper.printErrorsAndWarnings(result, wControl, false, trans.getLocale());
return true;
}
use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.
the class GTAAvailableTaskController method doSendConfirmationEmail.
private void doSendConfirmationEmail(Task assignedTask) {
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
ContactList contacts = new ContactList("participants");
if (GTAType.group.name().equals(gtaNode.getModuleConfiguration().getStringValue(GTACourseNode.GTASK_TYPE))) {
List<Identity> participants = businessGroupService.getMembers(assessedGroup, GroupRoles.participant.name());
contacts.addAllIdentites(participants);
bundle.setMetaId(UUID.randomUUID().toString());
} else {
contacts.add(assessedIdentity);
}
bundle.setContactList(contacts);
String[] args = new String[] { // 0 first name
getIdentity().getUser().getFirstName(), // 1 last name
getIdentity().getUser().getLastName(), // 2 course name
courseEnv.getCourseTitle(), // 3 task
assignedTask.getTaskName() };
String subject = translate("mail.confirm.assignment.subject", args);
String body = translate("mail.confirm.assignment.body", args);
bundle.setContent(subject, body);
mailManager.sendMessage(bundle);
}
use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.
the class ProjectGroupController method handleCandidateGroupEvent.
private void handleCandidateGroupEvent(UserRequest urequest, Event event) {
if (event instanceof IdentitiesAddEvent) {
IdentitiesAddEvent identitiesAddEvent = (IdentitiesAddEvent) event;
List<Identity> addedIdentities = projectGroupManager.addCandidates(identitiesAddEvent.getAddIdentities(), project);
identitiesAddEvent.setIdentitiesAddedEvent(addedIdentities);
fireEvent(urequest, Event.CHANGED_EVENT);
} else if (event instanceof IdentitiesRemoveEvent) {
projectGroupManager.removeCandidates(((IdentitiesRemoveEvent) event).getRemovedIdentities(), project);
fireEvent(urequest, Event.CHANGED_EVENT);
} else if (event instanceof IdentitiesMoveEvent) {
final IdentitiesMoveEvent identitiesMoveEvent = (IdentitiesMoveEvent) event;
// OLAT-6342: check identity not in group first!
List<Identity> moveIdents = identitiesMoveEvent.getChosenIdentities();
BusinessGroupAddResponse response = projectGroupManager.acceptCandidates(moveIdents, project, urequest.getIdentity(), projectBrokerModuleConfiguration.isAutoSignOut(), projectBrokerModuleConfiguration.isAcceptSelectionManually());
identitiesMoveEvent.setMovedIdentities(response.getAddedIdentities());
identitiesMoveEvent.setNotMovedIdentities(response.getIdentitiesAlreadyInGroup());
// send mail for all of them
MailTemplate mailTemplate = identitiesMoveEvent.getMailTemplate();
if (mailTemplate != null) {
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
String metaId = UUID.randomUUID().toString().replace("-", "");
MailerResult result = new MailerResult();
MailBundle[] bundles = mailManager.makeMailBundles(context, identitiesMoveEvent.getMovedIdentities(), mailTemplate, null, metaId, result);
result.append(mailManager.sendMessage(bundles));
if (mailTemplate.getCpfrom()) {
MailBundle ccBundle = mailManager.makeMailBundle(context, urequest.getIdentity(), mailTemplate, null, metaId, result);
result.append(mailManager.sendMessage(ccBundle));
}
MailHelper.printErrorsAndWarnings(result, getWindowControl(), urequest.getUserSession().getRoles().isOLATAdmin(), urequest.getLocale());
}
fireEvent(urequest, Event.CHANGED_EVENT);
// Participant and waiting-list were changed => reload both
projectMemberController.reloadData();
// Do only reload data in case of IdentitiesMoveEvent (IdentitiesAddEvent and reload data resulting in doublicate values)
projectCandidatesController.reloadData();
}
}
use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.
the class ProjectBrokerMailerImpl method sendEmail.
// ////////////////
// Private Methods
// ////////////////
private MailerResult sendEmail(Identity enrolledIdentity, Project project, String subject, String body, Locale locale) {
MailTemplate enrolledMailTemplate = createMailTemplate(project, enrolledIdentity, subject, body, locale);
MailContext context = new MailContextImpl(project.getProjectBroker(), null, null);
MailerResult result = new MailerResult();
MailBundle bundle = mailManager.makeMailBundle(context, enrolledIdentity, enrolledMailTemplate, null, null, result);
if (bundle != null) {
mailManager.sendMessage(bundle);
}
log.audit("ProjectBroker: sendEmail to identity.name=" + enrolledIdentity.getName() + " , mailerResult.returnCode=" + result.getReturnCode());
return result;
}
Aggregations