Search in sources :

Example 16 with ContactList

use of org.olat.core.util.mail.ContactList in project OpenOLAT by OpenOLAT.

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;
}
Also used : Locale(java.util.Locale) MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) Translator(org.olat.core.gui.translator.Translator) MailerResult(org.olat.core.util.mail.MailerResult) RepositoryEntry(org.olat.repository.RepositoryEntry) ContactList(org.olat.core.util.mail.ContactList) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Example 17 with ContactList

use of org.olat.core.util.mail.ContactList in project OpenOLAT by OpenOLAT.

the class BusinessGroupServiceImpl method isAllowToLeaveBusinessGroup.

@Override
public LeaveOption isAllowToLeaveBusinessGroup(Identity identity, BusinessGroup group) {
    LeaveOption opt;
    if (groupModule.isAllowLeavingGroupOverride()) {
        if (group.isAllowToLeave()) {
            opt = new LeaveOption();
        } else {
            ContactList list = getAdminContactList(group);
            opt = new LeaveOption(false, list);
        }
    } else if (groupModule.isAllowLeavingGroupCreatedByAuthors() && groupModule.isAllowLeavingGroupCreatedByLearners()) {
        opt = new LeaveOption();
    } else if (!groupModule.isAllowLeavingGroupCreatedByAuthors() && !groupModule.isAllowLeavingGroupCreatedByLearners()) {
        ContactList list = getAdminContactList(group);
        opt = new LeaveOption(false, list);
    } else {
        int numOfCoaches = countMembers(group, GroupRoles.coach.name());
        if (numOfCoaches == 0) {
            int numOfResources = businessGroupRelationDAO.countResources(group);
            if (numOfResources > 0) {
                // author group
                if (groupModule.isAllowLeavingGroupCreatedByAuthors()) {
                    opt = new LeaveOption();
                } else {
                    ContactList list = getAdminContactList(group);
                    opt = new LeaveOption(false, list);
                }
            // learner group
            } else if (groupModule.isAllowLeavingGroupCreatedByLearners()) {
                opt = new LeaveOption();
            } else {
                ContactList list = getAdminContactList(group);
                opt = new LeaveOption(false, list);
            }
        } else {
            int numOfAuthors = businessGroupRelationDAO.countAuthors(group);
            if (numOfAuthors > 0) {
                if (groupModule.isAllowLeavingGroupCreatedByAuthors()) {
                    opt = new LeaveOption();
                } else {
                    ContactList list = getAdminContactList(group);
                    opt = new LeaveOption(false, list);
                }
            } else if (groupModule.isAllowLeavingGroupCreatedByLearners()) {
                opt = new LeaveOption();
            } else {
                ContactList list = getAdminContactList(group);
                opt = new LeaveOption(false, list);
            }
        }
    }
    return opt;
}
Also used : LeaveOption(org.olat.group.model.LeaveOption) ContactList(org.olat.core.util.mail.ContactList)

Example 18 with ContactList

use of org.olat.core.util.mail.ContactList in project OpenOLAT by OpenOLAT.

the class AbstractMemberListController method doSendMail.

protected void doSendMail(UserRequest ureq, List<MemberView> members) {
    List<Long> identityKeys = getMemberKeys(members);
    List<Identity> identities = securityManager.loadIdentityByKeys(identityKeys);
    if (identities.isEmpty()) {
        showWarning("error.msg.send.no.rcps");
        return;
    }
    ContactMessage contactMessage = new ContactMessage(getIdentity());
    String name = repoEntry != null ? repoEntry.getDisplayname() : businessGroup.getName();
    ContactList contactList = new ContactList(name);
    contactList.addAllIdentites(identities);
    contactMessage.addEmailTo(contactList);
    contactCtrl = new ContactFormController(ureq, getWindowControl(), true, false, false, contactMessage);
    listenTo(contactCtrl);
    cmc = new CloseableModalController(getWindowControl(), translate("close"), contactCtrl.getInitialComponent(), true, translate("mail.member"));
    cmc.activate();
    listenTo(cmc);
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) ContactFormController(org.olat.modules.co.ContactFormController) ContactList(org.olat.core.util.mail.ContactList) Identity(org.olat.core.id.Identity) ContactMessage(org.olat.core.util.mail.ContactMessage)

Example 19 with ContactList

use of org.olat.core.util.mail.ContactList in project OpenOLAT by OpenOLAT.

the class MailManagerTest method testSend_BCC.

@Test
public void testSend_BCC() {
    // send a mail to three ids
    Identity fromId = JunitTestHelper.createAndPersistIdentityAsUser("mail-7-" + UUID.randomUUID().toString());
    Identity toId_1 = JunitTestHelper.createAndPersistIdentityAsUser("mail-8-" + UUID.randomUUID().toString());
    Identity toId_2 = JunitTestHelper.createAndPersistIdentityAsUser("mail-9-" + UUID.randomUUID().toString());
    Identity toId_3 = JunitTestHelper.createAndPersistIdentityAsUser("mail-10-" + UUID.randomUUID().toString());
    ContactList ccs = new ContactList("unit-test-cc");
    ccs.add(toId_1);
    ccs.add(toId_2);
    ccs.add(toId_3);
    MailBundle bundle = new MailBundle();
    bundle.setFromId(fromId);
    bundle.setContactList(ccs);
    bundle.setContent("Hello ccList", "Content of ccList");
    MailerResult result = mailManager.sendMessage(bundle);
    Assert.assertNotNull(result);
    Assert.assertEquals(MailerResult.OK, result.getReturnCode());
    dbInstance.commitAndCloseSession();
    // retrieve the inbox of 1
    List<DBMailLight> incomingsMails = mailManager.getInbox(toId_1, Boolean.TRUE, Boolean.TRUE, null, 0, -1);
    Assert.assertNotNull(incomingsMails);
    Assert.assertEquals(1, incomingsMails.size());
    DBMailLight incomingMail = incomingsMails.get(0);
    Assert.assertNotNull(incomingMail);
    Assert.assertEquals("Hello ccList", incomingMail.getSubject());
    // retrieve the inbox of 2
    List<DBMailLight> incomingsMails_2 = mailManager.getInbox(toId_2, Boolean.TRUE, Boolean.TRUE, null, 0, -1);
    Assert.assertNotNull(incomingsMails_2);
    Assert.assertEquals(1, incomingsMails_2.size());
    Assert.assertEquals(incomingMail, incomingsMails_2.get(0));
    // retrieve the inbox of 3
    List<DBMailLight> incomingsMails_3 = mailManager.getInbox(toId_2, Boolean.TRUE, Boolean.TRUE, null, 0, -1);
    Assert.assertNotNull(incomingsMails_3);
    Assert.assertEquals(1, incomingsMails_3.size());
    Assert.assertEquals(incomingMail, incomingsMails_3.get(0));
}
Also used : MailerResult(org.olat.core.util.mail.MailerResult) ContactList(org.olat.core.util.mail.ContactList) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) DBMailLight(org.olat.core.util.mail.model.DBMailLight) Test(org.junit.Test)

Example 20 with ContactList

use of org.olat.core.util.mail.ContactList in project openolat by klemens.

the class UsermanagerUserSearchForm 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)
 */
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == searchform) {
        if (event == Event.DONE_EVENT) {
            // form validation was ok
            identitiesList = findIdentitiesFromSearchForm();
            initUserListCtr(ureq, identitiesList, null);
            userListVC.put("userlist", tableCtr.getInitialComponent());
            userListVC.contextPut("emptyList", (identitiesList.size() == 0 ? Boolean.TRUE : Boolean.FALSE));
            panel.setContent(userListVC);
            // fxdiff BAKS-7 Resume function
            ContextEntry currentEntry = getWindowControl().getBusinessControl().getCurrentContextEntry();
            if (currentEntry != null) {
                currentEntry.setTransientState(searchform.getStateEntry());
            }
            addToHistory(ureq, tableCtr);
        } else if (event == Event.CANCELLED_EVENT) {
            fireEvent(ureq, Event.CANCELLED_EVENT);
        }
    } else if (source == tableCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            String actionid = te.getActionId();
            if (actionid.equals(ExtendedIdentitiesTableDataModel.COMMAND_SELECTUSER)) {
                int rowid = te.getRowId();
                Identity foundIdentity = tdm.getObject(rowid);
                // Tell parentController that a subject has been found
                fireEvent(ureq, new SingleIdentityChosenEvent(foundIdentity));
            } else if (actionid.equals(ExtendedIdentitiesTableDataModel.COMMAND_VCARD)) {
                // get identity and open new visiting card controller in new window
                int rowid = te.getRowId();
                final Identity identity = tdm.getObject(rowid);
                ControllerCreator userInfoMainControllerCreator = new ControllerCreator() {

                    @Override
                    public Controller createController(UserRequest lureq, WindowControl lwControl) {
                        return new UserInfoMainController(lureq, lwControl, identity, true, false);
                    }
                };
                // wrap the content controller into a full header layout
                ControllerCreator layoutCtrlr = BaseFullWebappPopupLayoutFactory.createAuthMinimalPopupLayout(ureq, userInfoMainControllerCreator);
                // open in new browser window
                PopupBrowserWindow pbw = getWindowControl().getWindowBackOffice().getWindowManager().createNewPopupBrowserWindowFor(ureq, layoutCtrlr);
                pbw.open(ureq);
            }
        }
        if (event instanceof TableMultiSelectEvent) {
            // Multiselect events
            TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
            if (tmse.getAction().equals(CMD_BULKEDIT)) {
                if (tmse.getSelection().isEmpty()) {
                    // empty selection
                    showWarning("msg.selectionempty");
                    return;
                }
                selectedIdentities = tdm.getIdentities(tmse.getSelection());
                // valid selection: load in wizard
                Step start = new UserBulkChangeStep00(ureq, selectedIdentities);
                // callback executed in case wizard is finished.
                StepRunnerCallback finish = new StepRunnerCallback() {

                    public Step execute(UserRequest ureq1, WindowControl wControl1, StepsRunContext runContext) {
                        // all information to do now is within the runContext saved
                        boolean hasChanges = false;
                        try {
                            if (runContext.containsKey("validChange") && ((Boolean) runContext.get("validChange")).booleanValue()) {
                                HashMap<String, String> attributeChangeMap = (HashMap<String, String>) runContext.get("attributeChangeMap");
                                HashMap<String, String> roleChangeMap = (HashMap<String, String>) runContext.get("roleChangeMap");
                                List<Long> ownGroups = (List<Long>) runContext.get("ownerGroups");
                                List<Long> partGroups = (List<Long>) runContext.get("partGroups");
                                // List<Long> mailGroups = (List<Long>) runContext.get("mailGroups");
                                if (attributeChangeMap.size() != 0 || roleChangeMap.size() != 0 || ownGroups.size() != 0 || partGroups.size() != 0) {
                                    Identity addingIdentity = ureq1.getIdentity();
                                    ubcMan.changeSelectedIdentities(selectedIdentities, attributeChangeMap, roleChangeMap, notUpdatedIdentities, isAdministrativeUser, ownGroups, partGroups, getTranslator(), addingIdentity);
                                    hasChanges = true;
                                }
                            }
                        } catch (Exception any) {
                        // return new ErrorStep
                        }
                        // signal correct completion and tell if changes were made or not.
                        return hasChanges ? StepsMainRunController.DONE_MODIFIED : StepsMainRunController.DONE_UNCHANGED;
                    }
                };
                removeAsListenerAndDispose(userBulkChangeStepsController);
                userBulkChangeStepsController = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("bulkChange.title"), "o_sel_user_bulk_change_wizard");
                listenTo(userBulkChangeStepsController);
                getWindowControl().pushAsModalDialog(userBulkChangeStepsController.getInitialComponent());
            } else if (tmse.getAction().equals(CMD_MAIL)) {
                if (tmse.getSelection().isEmpty()) {
                    // empty selection
                    showWarning("msg.selectionempty");
                    return;
                }
                // create e-mail message
                ContactMessage cmsg = new ContactMessage(ureq.getIdentity());
                selectedIdentities = tdm.getIdentities(tmse.getSelection());
                ContactList contacts = new ContactList(translate("mailto.userlist"));
                contacts.addAllIdentites(selectedIdentities);
                cmsg.addEmailTo(contacts);
                // create contact form controller with ContactMessage
                removeAsListenerAndDispose(contactCtr);
                contactCtr = new ContactFormController(ureq, getWindowControl(), true, false, false, cmsg);
                listenTo(contactCtr);
                mailVC.put("mailform", contactCtr.getInitialComponent());
                panel.setContent(mailVC);
            }
        }
    } else if (source == contactCtr) {
        // in any case go back to list (events: done, failed or cancel)
        panel.setContent(userListVC);
    } else if (source == userBulkChangeStepsController) {
        if (event == Event.CANCELLED_EVENT) {
            getWindowControl().pop();
        } else if (event == Event.CHANGED_EVENT) {
            getWindowControl().pop();
            Integer selIdentCount = selectedIdentities.size();
            if (notUpdatedIdentities.size() > 0) {
                Integer notUpdatedIdentCount = notUpdatedIdentities.size();
                Integer sucChanges = selIdentCount - notUpdatedIdentCount;
                String changeErrors = "";
                for (String err : notUpdatedIdentities) {
                    changeErrors += err + "<br />";
                }
                getWindowControl().setError(translate("bulkChange.partialsuccess", new String[] { sucChanges.toString(), selIdentCount.toString(), changeErrors }));
            } else {
                showInfo("bulkChange.success");
            }
            // update table model - has changed
            reloadDataModel(ureq);
        } else if (event == Event.DONE_EVENT) {
            showError("bulkChange.failed");
        }
    }
}
Also used : HashMap(java.util.HashMap) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) Step(org.olat.core.gui.control.generic.wizard.Step) WindowControl(org.olat.core.gui.control.WindowControl) StepsRunContext(org.olat.core.gui.control.generic.wizard.StepsRunContext) ContextEntry(org.olat.core.id.context.ContextEntry) ControllerCreator(org.olat.core.gui.control.creator.ControllerCreator) PopupBrowserWindow(org.olat.core.gui.control.generic.popup.PopupBrowserWindow) ContactFormController(org.olat.modules.co.ContactFormController) ContactList(org.olat.core.util.mail.ContactList) List(java.util.List) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) UserRequest(org.olat.core.gui.UserRequest) ContactList(org.olat.core.util.mail.ContactList) UserBulkChangeStep00(org.olat.admin.user.bulkChange.UserBulkChangeStep00) ContactMessage(org.olat.core.util.mail.ContactMessage) TableEvent(org.olat.core.gui.components.table.TableEvent) UserInfoMainController(org.olat.user.UserInfoMainController) SingleIdentityChosenEvent(org.olat.basesecurity.events.SingleIdentityChosenEvent) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) StepRunnerCallback(org.olat.core.gui.control.generic.wizard.StepRunnerCallback)

Aggregations

ContactList (org.olat.core.util.mail.ContactList)92 Identity (org.olat.core.id.Identity)66 ContactMessage (org.olat.core.util.mail.ContactMessage)28 MailBundle (org.olat.core.util.mail.MailBundle)26 ContactFormController (org.olat.modules.co.ContactFormController)22 MailContextImpl (org.olat.core.util.mail.MailContextImpl)18 MailerResult (org.olat.core.util.mail.MailerResult)18 MailContext (org.olat.core.util.mail.MailContext)16 ArrayList (java.util.ArrayList)14 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)14 RepositoryEntry (org.olat.repository.RepositoryEntry)10 HashSet (java.util.HashSet)8 Test (org.junit.Test)8 BusinessGroup (org.olat.group.BusinessGroup)7 Locale (java.util.Locale)6 WindowControl (org.olat.core.gui.control.WindowControl)6 Translator (org.olat.core.gui.translator.Translator)6 File (java.io.File)4 Date (java.util.Date)4 Address (javax.mail.Address)4