use of org.olat.core.util.mail.MailContext in project openolat by klemens.
the class IQEditReplaceWizard method event.
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
if (source == mailCtr && event == Event.DONE_EVENT) {
MailTemplate mailTemplate = mailCtr.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, learners, mailTemplate, getIdentity(), metaId, result);
result.append(mailManager.sendMessage(bundles));
if (mailTemplate.getCpfrom()) {
MailBundle ccBundle = mailManager.makeMailBundle(context, getIdentity(), mailTemplate, getIdentity(), metaId, result);
result.append(mailManager.sendMessage(ccBundle));
}
}
fireEvent(ureq, Event.DONE_EVENT);
} else if (source == searchCtr && event == ReferencableEntriesSearchController.EVENT_REPOSITORY_ENTRY_SELECTED) {
selectedRepositoryEntry = searchCtr.getSelectedEntry();
doStep2(ureq);
}
}
use of org.olat.core.util.mail.MailContext in project openolat by klemens.
the class BGEmailCompositionStepController method formOK.
@Override
protected void formOK(UserRequest ureq) {
boolean success = false;
try {
File[] attachments = contactForm.getAttachments();
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setFromId(getIdentity());
bundle.setContactLists(contactForm.getEmailToContactLists());
bundle.setContent(contactForm.getSubject(), contactForm.getBody(), attachments);
MailerResult result = mailService.sendMessage(bundle);
success = result.isSuccessful();
if (contactForm.isTcpFrom()) {
MailBundle ccBundle = new MailBundle();
ccBundle.setContext(context);
ccBundle.setFromId(getIdentity());
ccBundle.setCc(getIdentity());
ccBundle.setContent(contactForm.getSubject(), contactForm.getBody(), attachments);
MailerResult ccResult = mailService.sendMessage(ccBundle);
success = ccResult.isSuccessful();
}
} catch (Exception e) {
logError(null, e);
}
if (success) {
fireEvent(ureq, StepsEvent.ACTIVATE_NEXT);
}
}
use of org.olat.core.util.mail.MailContext in project openolat by klemens.
the class OLATAuthManager method sendConfirmationEmail.
private void sendConfirmationEmail(Identity doer, Identity identity) {
String prefsLanguage = identity.getUser().getPreferences().getLanguage();
Locale locale = I18nManager.getInstance().getLocaleOrDefault(prefsLanguage);
Translator translator = Util.createPackageTranslator(OLATAuthenticationController.class, locale);
ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(OresHelper.createOLATResourceableInstance("changepw", 0l));
String changePwUrl = BusinessControlFactory.getInstance().getAsURIString(Collections.singletonList(ce), false);
String[] args = new String[] { // 0: changed users username
identity.getName(), // 1: changed users email address
UserManager.getInstance().getUserDisplayEmail(identity, locale), // 2: Name (first and last name) of user who changed the password
userManager.getUserDisplayName(doer.getUser()), // 3: configured support email address
WebappHelper.getMailConfig("mailSupport"), // 4: direct link to change password workflow (e.g. https://xx.xx.xx/olat/url/changepw/0)
changePwUrl };
String subject = translator.translate("mail.pwd.subject", args);
String body = translator.translate("mail.pwd.body", args);
MailContext context = new MailContextImpl(null, null, "[Identity:" + identity.getKey() + "]");
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setToId(identity);
bundle.setContent(subject, body);
mailManager.sendMessage(bundle);
}
use of org.olat.core.util.mail.MailContext in project openolat by klemens.
the class DropboxController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == fileChooserController) {
cmc.deactivate();
if (event.equals(Event.DONE_EVENT)) {
boolean success = false;
File fIn = fileChooserController.getUploadFile();
VFSContainer fDropbox = getDropBox(ureq.getIdentity());
String filename = fileChooserController.getUploadFileName();
VFSLeaf fOut;
if (fDropbox.resolve(filename) != null) {
// FIXME ms: check if dropbox quota is exceeded -> clarify with customers
fOut = fDropbox.createChildLeaf(getNewUniqueName(filename));
} else {
fOut = fDropbox.createChildLeaf(filename);
}
try {
InputStream in = new FileInputStream(fIn);
OutputStream out = new BufferedOutputStream(fOut.getOutputStream(false));
success = FileUtils.copy(in, out);
FileUtils.closeSafely(in);
FileUtils.closeSafely(out);
} catch (FileNotFoundException e) {
logError("", e);
return;
}
if (fOut instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) fOut).getMetaInfo();
if (info != null) {
info.setAuthor(ureq.getIdentity());
info.write();
}
}
if (success) {
int numFiles = fDropbox.getItems().size();
myContent.contextPut("numfiles", new String[] { Integer.toString(numFiles) });
// assemble confirmation
String confirmation = getConfirmation(ureq, fOut.getName());
// send email if necessary
Boolean sendEmail = (Boolean) config.get(TACourseNode.CONF_DROPBOX_ENABLEMAIL);
if (sendEmail == null)
sendEmail = Boolean.FALSE;
boolean sendMailError = false;
if (sendEmail.booleanValue()) {
// send mail
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setToId(ureq.getIdentity());
bundle.setContent(translate("conf.mail.subject"), confirmation);
MailerResult result = CoreSpringFactory.getImpl(MailManager.class).sendMessage(bundle);
if (result.getFailedIdentites().size() > 0) {
List<Identity> disabledIdentities = new ArrayList<Identity>();
disabledIdentities = result.getFailedIdentites();
// show error that message can not be sent
ArrayList<String> myButtons = new ArrayList<String>();
myButtons.add(translate("back"));
String title = MailHelper.getTitleForFailedUsersError(ureq.getLocale());
String message = MailHelper.getMessageForFailedUsersError(ureq.getLocale(), disabledIdentities);
// add dropbox specific error message
message += "\n<br />" + translate("conf.mail.error");
// FIXME:FG:6.2: fix problem in info message, not here
message += "\n<br />\n<br />" + confirmation.replace("\n", " ").replace("\r", " ").replace("\u2028", " ");
DialogBoxController noUsersErrorCtr = null;
noUsersErrorCtr = activateGenericDialog(ureq, title, message, myButtons, noUsersErrorCtr);
sendMailError = true;
} else if (result.getReturnCode() > 0) {
// show error that message can not be sent
ArrayList<String> myButtons = new ArrayList<String>();
myButtons.add(translate("back"));
DialogBoxController noUsersErrorCtr = null;
String message = translate("conf.mail.error");
// FIXME:FG:6.2: fix problem in info message, not here
message += "\n<br />\n<br />" + confirmation.replace("\n", " ").replace("\r", " ").replace("\u2028", " ");
noUsersErrorCtr = activateGenericDialog(ureq, translate("error.header"), message, myButtons, noUsersErrorCtr);
sendMailError = true;
}
}
// inform subscription manager about new element
if (subsContext != null) {
NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
}
// FIXME:FG:6.2: fix problem in info message, not here
if (!sendMailError) {
getWindowControl().setInfo(confirmation.replace("\n", " ").replace("\r", " ").replace("\u2028", " "));
}
} else {
showInfo("dropbox.upload.failed");
}
}
}
}
use of org.olat.core.util.mail.MailContext in project openolat by klemens.
the class ReturnboxFullAccessCallback method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == dropboxFolderRunController) {
if (event instanceof FolderEvent) {
FolderEvent folderEvent = (FolderEvent) event;
if (folderEvent.getCommand().equals(FolderEvent.DELETE_EVENT)) {
UserNodeAuditManager am = userCourseEnv.getCourseEnvironment().getAuditManager();
// log entry for this file
Identity coach = ureq.getIdentity();
Identity student = userCourseEnv.getIdentityEnvironment().getIdentity();
am.appendToUserNodeLog(node, coach, student, "FILE DELETED: " + folderEvent.getFilename());
}
}
} else if (source == returnboxFolderRunController) {
if (event instanceof FolderEvent) {
FolderEvent folderEvent = (FolderEvent) event;
if (folderEvent.getCommand().equals(FolderEvent.UPLOAD_EVENT) || folderEvent.getCommand().equals(FolderEvent.NEW_FILE_EVENT)) {
UserNodeAuditManager am = userCourseEnv.getCourseEnvironment().getAuditManager();
// log entry for this file
Identity coach = ureq.getIdentity();
Identity student = userCourseEnv.getIdentityEnvironment().getIdentity();
if (node instanceof AssessableCourseNode) {
AssessableCourseNode acn = (AssessableCourseNode) node;
AssessmentEvaluation eval = acn.getUserScoreEvaluation(userCourseEnv);
if (eval.getAssessmentStatus() == null || eval.getAssessmentStatus() == AssessmentEntryStatus.notStarted) {
eval = new AssessmentEvaluation(eval, AssessmentEntryStatus.inProgress);
acn.updateUserScoreEvaluation(eval, userCourseEnv, coach, false, Role.coach);
}
}
am.appendToUserNodeLog(node, coach, student, "FILE UPLOADED: " + folderEvent.getFilename());
String toMail = UserManager.getInstance().getUserDisplayEmail(student, ureq.getLocale());
OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseNode.class, Long.valueOf(node.getIdent()));
ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(ores);
BusinessControl bc = BusinessControlFactory.getInstance().createBusinessControl(ce, getWindowControl().getBusinessControl());
String link = BusinessControlFactory.getInstance().getAsURIString(bc, true);
log.debug("DEBUG : Returnbox notification email with link=" + link);
String subject = translate("returnbox.email.subject");
String body = translate("returnbox.email.body", new String[] { userCourseEnv.getCourseEnvironment().getCourseTitle(), node.getShortTitle(), folderEvent.getFilename(), link });
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setToId(student);
bundle.setContent(subject, body);
MailerResult result = CoreSpringFactory.getImpl(MailManager.class).sendMessage(bundle);
if (result.getReturnCode() > 0) {
am.appendToUserNodeLog(node, coach, student, "MAIL SEND FAILED TO:" + toMail + "; MailReturnCode: " + result.getReturnCode());
log.warn("Could not send email 'returnbox notification' to " + student + "with email=" + toMail);
} else {
log.info("Send email 'returnbox notification' to " + student + "with email=" + toMail);
}
}
} else if (FolderCommand.FOLDERCOMMAND_FINISHED == event) {
if (node instanceof AssessableCourseNode) {
AssessableCourseNode acn = (AssessableCourseNode) node;
AssessmentEvaluation eval = acn.getUserScoreEvaluation(userCourseEnv);
if (eval == null) {
eval = AssessmentEvaluation.EMPTY_EVAL;
}
if (eval.getAssessmentStatus() == null || eval.getAssessmentStatus() == AssessmentEntryStatus.notStarted) {
eval = new AssessmentEvaluation(eval, AssessmentEntryStatus.inProgress);
acn.updateUserScoreEvaluation(eval, userCourseEnv, getIdentity(), false, Role.coach);
fireEvent(ureq, Event.CHANGED_EVENT);
}
}
}
} else if (source == statusForm) {
if (event == Event.DONE_EVENT) {
// get identity not from request (this would be an author)
StatusManager.getInstance().saveStatusFormData(statusForm, node, userCourseEnv);
}
} else if (source == dialogBoxController) {
if (DialogBoxUIFactory.isYesEvent(event) && assignedTask != null) {
// cancel task assignment, and show "no task assigned to user"
removeAssignedTask(userCourseEnv, userCourseEnv.getIdentityEnvironment().getIdentity());
// update UI
myContent.contextPut("assignedtask", null);
}
}
}
Aggregations