use of org.olat.core.util.mail.MailContextImpl 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.MailContextImpl in project openolat by klemens.
the class DENManageParticipantsController method event.
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == tableListParticipants) {
if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
TableEvent tableEvent = (TableEvent) event;
// open window for choosen date to manage the enrolled users or manually add
if (tableEvent.getActionId().equals(DENListTableDataModel.CHANGE_ACTION)) {
selectedEvent = listTableData.getObject(tableEvent.getRowId());
List<Identity> participants = denManager.getEventParticipants(selectedEvent);
participantsTableData = new DENParticipantsTableDataModel(participants);
removeAsListenerAndDispose(tableManageParticipants);
tableManageParticipants = denManager.createParticipantsTable(ureq, getWindowControl(), getTranslator(), participantsTableData);
listenTo(tableManageParticipants);
participantsVC = createVelocityContainer("participants");
DateFormat df = new SimpleDateFormat();
participantsVC.contextPut("dateTitle", selectedEvent.getSubject());
participantsVC.contextPut("dateTimeframe", df.format(selectedEvent.getBegin()) + " - " + df.format(selectedEvent.getEnd()));
participantsVC.put("participantsTable", tableManageParticipants.getInitialComponent());
addParticipantButton = LinkFactory.createButton("participants.add", participantsVC, this);
removeAsListenerAndDispose(manageParticipantsModalCntrl);
manageParticipantsModalCntrl = new CloseableModalController(getWindowControl(), "close", participantsVC, true, translate("dates.table.participant.manage"));
listenTo(manageParticipantsModalCntrl);
manageParticipantsModalCntrl.activate();
}
} else {
TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
BitSet selection = tmse.getSelection();
// delete all users from the selected dates
if (tmse.getAction().equals(DENListTableDataModel.DELETE_ACTION) && selection.cardinality() > 0) {
selectedIds = denManager.getSelectedEventParticipants(dateList, selection);
dateList = denManager.deleteParticipants(ores, courseNode, denManager.getSelectedEventIDs(dateList, selection));
listTableData.setObjects(dateList);
// send notification mail
createNotificationMail(ureq, courseNode.getShortTitle(), REMOVE_ACTION);
} else if (tmse.getAction().equals(DENListTableDataModel.MAIL_ACTION) && selection.cardinality() > 0) {
// send email to all users from the selected dates
List<Identity> participants = denManager.getSelectedEventParticipants(dateList, selection);
createParticipantsMail(ureq, participants);
} else if (selection.cardinality() == 0) {
showWarning("participants.message.empty");
}
}
} else if (source == userSearchCntrl) {
if (event == Event.CANCELLED_EVENT) {
userSearchCMC.deactivate();
} else {
List<Identity> toAdd = null;
selectedIds = new ArrayList<Identity>();
if (event instanceof SingleIdentityChosenEvent) {
SingleIdentityChosenEvent singleEvent = (SingleIdentityChosenEvent) event;
Identity choosenIdentity = singleEvent.getChosenIdentity();
toAdd = new ArrayList<Identity>();
toAdd.add(choosenIdentity);
} else if (event instanceof MultiIdentityChosenEvent) {
MultiIdentityChosenEvent multiEvent = (MultiIdentityChosenEvent) event;
toAdd = multiEvent.getChosenIdentities();
}
boolean showMessage = false;
if (toAdd != null && toAdd.size() > 0) {
for (Identity identity : toAdd) {
status = denManager.doEnroll(identity, selectedEvent, ores, courseNode, true);
if (!status.isEnrolled() && status.getErrorMessage().equals(DENStatus.ERROR_ALREADY_ENROLLED))
showMessage = true;
else
selectedIds.add(identity);
}
if (showMessage)
showWarning("enrollment.warning.manual");
refreshTables();
}
userSearchCMC.deactivate();
if (selectedIds.size() > 0) {
// write notification mail
createNotificationMail(ureq, selectedEvent.getSubject(), ADD_ACTION);
}
}
} else if (source == tableManageParticipants) {
if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
TableEvent tableEvent = (TableEvent) event;
// delete single user from event
if (tableEvent.getActionId().equals(DENParticipantsTableDataModel.REMOVE_ACTION)) {
Identity identity = participantsTableData.getEntryAt(tableEvent.getRowId());
status = denManager.cancelEnroll(identity, selectedEvent, ores);
if (!status.isCancelled())
showError();
else // send notification mail
{
selectedIds.clear();
selectedIds.add(identity);
createNotificationMail(ureq, selectedEvent.getSubject(), REMOVE_ACTION);
}
refreshTables();
// write email to single user
} else if (tableEvent.getActionId().equals(DENParticipantsTableDataModel.MAIL_ACTION)) {
List<Identity> participants = new ArrayList<Identity>();
participants.add(participantsTableData.getEntryAt(tableEvent.getRowId()));
createParticipantsMail(ureq, participants);
}
}
} else if (source == notificationCtr && event == Event.DONE_EVENT) {
if (notificationCtr.getMailTemplate() != null) {
Identity sender = ureq.getIdentity();
MailerResult result = new MailerResult();
String metaId = UUID.randomUUID().toString().replace("-", "");
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailBundle[] bundles = mailManager.makeMailBundles(context, selectedIds, notificationCtr.getMailTemplate(), sender, metaId, result);
result.append(mailManager.sendMessage(bundles));
if (notificationCtr.getMailTemplate().getCpfrom()) {
MailBundle ccBundles = mailManager.makeMailBundle(context, sender, notificationCtr.getMailTemplate(), sender, metaId, result);
result.append(mailManager.sendMessage(ccBundles));
}
MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
}
notificationCmc.deactivate();
selectedIds.clear();
} else if (source == contactCtr) {
notificationCmc.deactivate();
}
}
use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.
the class GroupController method doRemoveIdentitiesFromGroup.
private void doRemoveIdentitiesFromGroup(UserRequest ureq, List<Identity> toBeRemoved, MailTemplate mailTemplate) {
fireEvent(ureq, new IdentitiesRemoveEvent(toBeRemoved));
identitiesTableModel.remove(toBeRemoved);
if (tableCtr != null) {
// can be null in the follwoing case.
// the user which does the removal is also in the list of toBeRemoved
// hence the fireEvent does trigger a disposal of a GroupController, which
// in turn nullifies the tableCtr... see also OLAT-3331
tableCtr.modelChanged();
}
// send the notification mail
if (mailTemplate != null) {
// means no sender in footer
Identity sender = null;
if (showSenderInRemovMailFooter) {
sender = ureq.getIdentity();
}
String metaId = UUID.randomUUID().toString();
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailerResult result = new MailerResult();
MailBundle[] bundles = mailManager.makeMailBundles(context, toBeRemoved, 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.printErrorsAndWarnings(result, getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
}
}
use of org.olat.core.util.mail.MailContextImpl 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.MailContextImpl in project OpenOLAT by OpenOLAT.
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