use of org.olat.core.util.mail.MailContext 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;
}
use of org.olat.core.util.mail.MailContext in project openolat by klemens.
the class ReminderServiceImpl method sendReminder.
@Override
public MailerResult sendReminder(Reminder reminder, List<Identity> identitiesToRemind) {
RepositoryEntry entry = reminder.getEntry();
ContactList contactList = new ContactList("Infos");
contactList.addAllIdentites(identitiesToRemind);
MailContext context = new MailContextImpl("[RepositoryEntry:" + entry.getKey() + "]");
Locale locale = I18nModule.getDefaultLocale();
Translator trans = Util.createPackageTranslator(ReminderAdminController.class, locale);
String subject = reminder.getEmailSubject();
String body = reminder.getEmailBody();
if (body.contains("$courseurl")) {
body = body.replace("$courseurl", "<a href=\"$courseurl\">$courseurl</a>");
} else {
body = body + "<p>---<br />" + trans.translate("reminder.from.course", new String[] { "<a href=\"$courseurl\">$coursename</a>" }) + "</p>";
}
String metaId = UUID.randomUUID().toString();
String url = Settings.getServerContextPathURI() + "/url/RepositoryEntry/" + entry.getKey();
MailerResult overviewResult = new MailerResult();
ReminderTemplate template = new ReminderTemplate(subject, body, url, entry, locale);
for (Identity identityToRemind : identitiesToRemind) {
String status;
MailBundle bundle = mailManager.makeMailBundle(context, identityToRemind, template, null, metaId, overviewResult);
MailerResult result = mailManager.sendMessage(bundle);
overviewResult.append(result);
List<Identity> failedIdentities = result.getFailedIdentites();
if (failedIdentities != null && failedIdentities.contains(identityToRemind)) {
status = "error";
} else {
status = "ok";
}
reminderDao.markAsSend(reminder, identityToRemind, status);
}
return overviewResult;
}
use of org.olat.core.util.mail.MailContext in project openolat by klemens.
the class EnrollmentManager method doCancelEnrollment.
public void doCancelEnrollment(final Identity identity, final BusinessGroup enrolledGroup, final ENCourseNode enNode, final CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans) {
if (isLogDebugEnabled())
logDebug("doCancelEnrollment");
// 1. Remove group membership, fire events, do loggin etc.
// Remove participant. This will also check if a waiting-list with auto-close-ranks is configurated
// and move the users accordingly
MailPackage doNotSendmailPackage = new MailPackage(false);
businessGroupService.removeParticipants(identity, Collections.singletonList(identity), enrolledGroup, doNotSendmailPackage);
logInfo(" doCancelEnrollment in group " + enrolledGroup, identity.getName());
logInfo(" doCancelEnrollment in group " + enrolledGroup, identity.getName());
// 2. Remove enrollmentdate property
// only remove last time date, not firsttime
Property lastTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_ENROLLMENT_DATE);
if (lastTime != null) {
coursePropertyManager.deleteProperty(lastTime);
}
// 3. Send notification mail
MailTemplate mailTemplate = BGMailHelper.createRemoveMyselfMailTemplate(enrolledGroup, 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());
}
use of org.olat.core.util.mail.MailContext in project openolat by klemens.
the class EnrollmentManager method doCancelEnrollmentInWaitingList.
public void doCancelEnrollmentInWaitingList(final Identity identity, final BusinessGroup enrolledWaitingListGroup, final ENCourseNode enNode, final CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans) {
// 1. Remove group membership, fire events, do loggin etc.
businessGroupService.removeFromWaitingList(identity, Collections.singletonList(identity), enrolledWaitingListGroup, null);
// 2. Remove enrollmentdate property
// only remove last time date, not firsttime
Property lastTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_WAITINGLIST_DATE);
if (lastTime != null) {
coursePropertyManager.deleteProperty(lastTime);
}
// 3. Send notification mail
MailTemplate mailTemplate = BGMailHelper.createRemoveWaitinglistMailTemplate(enrolledWaitingListGroup, 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());
}
use of org.olat.core.util.mail.MailContext in project openolat by klemens.
the class EnrollmentManager method addUserToParticipantList.
// /////////////////
// Private Methods
// /////////////////
private boolean addUserToParticipantList(Identity identity, BusinessGroup group, ENCourseNode enNode, CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans) {
// 2. Set first enrollment date
String nowString = Long.toString(System.currentTimeMillis());
Property firstTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_INITIAL_ENROLLMENT_DATE);
if (firstTime == null) {
// create firsttime
firstTime = coursePropertyManager.createCourseNodePropertyInstance(enNode, identity, null, ENCourseNode.PROPERTY_INITIAL_ENROLLMENT_DATE, null, null, nowString, null);
coursePropertyManager.saveProperty(firstTime);
}
// 3. Set enrollmentdate property
Property thisTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_ENROLLMENT_DATE);
if (thisTime == null) {
// create firsttime
thisTime = coursePropertyManager.createCourseNodePropertyInstance(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_ENROLLMENT_DATE, null, null, nowString, null);
coursePropertyManager.saveProperty(thisTime);
} else {
thisTime.setStringValue(nowString);
coursePropertyManager.updateProperty(thisTime);
}
// 4. Send notification mail
MailTemplate mailTemplate = BGMailHelper.createAddMyselfMailTemplate(group, identity);
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;
}
Aggregations