Search in sources :

Example 11 with MailingList

use of com.serotonin.m2m2.vo.mailingList.MailingList in project ma-core-public by infiniteautomation.

the class MailingListsDwr method getMailingList.

@DwrPermission(admin = true)
public MailingList getMailingList(int id) {
    if (id == Common.NEW_ID) {
        MailingList ml = new MailingList();
        ml.setId(Common.NEW_ID);
        ml.setXid(MailingListDao.instance.generateUniqueXid());
        ml.setEntries(new LinkedList<EmailRecipient>());
        return ml;
    }
    return MailingListDao.instance.getMailingList(id);
}
Also used : EmailRecipient(com.serotonin.m2m2.vo.mailingList.EmailRecipient) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 12 with MailingList

use of com.serotonin.m2m2.vo.mailingList.MailingList in project ma-core-public by infiniteautomation.

the class MailingListsDwr method sendTestEmail.

@DwrPermission(admin = true)
public ProcessResult sendTestEmail(int id, String name, List<RecipientListEntryBean> entryBeans) {
    ProcessResult response = new ProcessResult();
    MailingList ml = createMailingList(id, null, name, AlarmLevels.IGNORE, entryBeans);
    MailingListDao.instance.populateEntrySubclasses(ml.getEntries());
    Set<String> addresses = new HashSet<String>();
    ml.appendAddresses(addresses, null);
    String[] toAddrs = addresses.toArray(new String[0]);
    try {
        Translations translations = Common.getTranslations();
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("message", new TranslatableMessage("ftl.userTestEmail", ml.getName()));
        MangoEmailContent cnt = new MangoEmailContent("testEmail", model, translations, translations.translate("ftl.testEmail"), Common.UTF8);
        EmailWorkItem.queueEmail(toAddrs, cnt);
    } catch (Exception e) {
        response.addGenericMessage("mailingLists.testerror", e.getMessage());
        log.warn("", e);
    }
    return response;
}
Also used : HashMap(java.util.HashMap) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) MangoEmailContent(com.serotonin.m2m2.email.MangoEmailContent) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) Translations(com.serotonin.m2m2.i18n.Translations) HashSet(java.util.HashSet) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 13 with MailingList

use of com.serotonin.m2m2.vo.mailingList.MailingList in project ma-core-public by infiniteautomation.

the class MailingListImporter method importImpl.

@Override
protected void importImpl() {
    String xid = json.getString("xid");
    if (StringUtils.isBlank(xid))
        xid = ctx.getMailingListDao().generateUniqueXid();
    MailingList vo = ctx.getMailingListDao().getMailingList(xid);
    if (vo == null) {
        vo = new MailingList();
        vo.setXid(xid);
    }
    try {
        ctx.getReader().readInto(vo, json);
        // Now validate it. Use a new response object so we can distinguish errors in this vo from other errors.
        ProcessResult voResponse = new ProcessResult();
        vo.validate(voResponse);
        if (voResponse.getHasMessages())
            setValidationMessages(voResponse, "emport.mailingList.prefix", xid);
        else {
            // Sweet. Save it.
            boolean isnew = vo.getId() == Common.NEW_ID;
            ctx.getMailingListDao().saveMailingList(vo);
            addSuccessMessage(isnew, "emport.mailingList.prefix", xid);
        }
    } catch (TranslatableJsonException e) {
        addFailureMessage("emport.mailingList.prefix", xid, e.getMsg());
    } catch (JsonException e) {
        addFailureMessage("emport.mailingList.prefix", xid, getJsonExceptionMessage(e));
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 14 with MailingList

use of com.serotonin.m2m2.vo.mailingList.MailingList in project ma-core-public by infiniteautomation.

the class RecipientListEntryBean method createEmailRecipient.

public EmailRecipient createEmailRecipient() {
    switch(recipientType) {
        case EmailRecipient.TYPE_MAILING_LIST:
            MailingList ml = new MailingList();
            ml.setId(referenceId);
            return ml;
        case EmailRecipient.TYPE_USER:
            UserEntry u = new UserEntry();
            u.setUserId(referenceId);
            return u;
        case EmailRecipient.TYPE_ADDRESS:
            AddressEntry a = new AddressEntry();
            a.setAddress(referenceAddress);
            return a;
    }
    throw new ShouldNeverHappenException("Unknown email recipient type: " + recipientType);
}
Also used : AddressEntry(com.serotonin.m2m2.vo.mailingList.AddressEntry) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) UserEntry(com.serotonin.m2m2.vo.mailingList.UserEntry)

Example 15 with MailingList

use of com.serotonin.m2m2.vo.mailingList.MailingList in project ma-core-public by infiniteautomation.

the class MailingListDao method saveRelationalData.

void saveRelationalData(final MailingList ml) {
    // Save the inactive intervals.
    ejt.update("delete from mailingListInactive where mailingListId=?", new Object[] { ml.getId() });
    // Save what is in the mailing list object.
    final List<Integer> intervalIds = new ArrayList<Integer>(ml.getInactiveIntervals());
    ejt.batchUpdate(MAILING_LIST_INACTIVE_INSERT, new BatchPreparedStatementSetter() {

        public int getBatchSize() {
            return intervalIds.size();
        }

        public void setValues(PreparedStatement ps, int i) throws SQLException {
            ps.setInt(1, ml.getId());
            ps.setInt(2, intervalIds.get(i));
        }
    });
    // Delete existing entries
    ejt.update("delete from mailingListMembers where mailingListId=?", new Object[] { ml.getId() });
    // Save what is in the mailing list object.
    final List<EmailRecipient> entries = ml.getEntries();
    ejt.batchUpdate(MAILING_LIST_ENTRY_INSERT, new BatchPreparedStatementSetter() {

        public int getBatchSize() {
            return entries.size();
        }

        public void setValues(PreparedStatement ps, int i) throws SQLException {
            EmailRecipient e = entries.get(i);
            ps.setInt(1, ml.getId());
            ps.setInt(2, e.getRecipientType());
            ps.setInt(3, e.getReferenceId());
            ps.setString(4, e.getReferenceAddress());
        }
    });
}
Also used : EmailRecipient(com.serotonin.m2m2.vo.mailingList.EmailRecipient) SQLException(java.sql.SQLException) BatchPreparedStatementSetter(org.springframework.jdbc.core.BatchPreparedStatementSetter) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement)

Aggregations

MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)14 User (com.serotonin.m2m2.vo.User)5 EmailRecipient (com.serotonin.m2m2.vo.mailingList.EmailRecipient)4 ArrayList (java.util.ArrayList)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)3 RecipientListEntryBean (com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)3 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)3 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)2 AddressEntry (com.serotonin.m2m2.vo.mailingList.AddressEntry)2 UserEntry (com.serotonin.m2m2.vo.mailingList.UserEntry)2 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)2 MailingListModel (com.serotonin.m2m2.web.mvc.rest.v1.model.email.MailingListModel)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 HashSet (java.util.HashSet)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JsonException (com.serotonin.json.JsonException)1 MailingListDao (com.serotonin.m2m2.db.dao.MailingListDao)1 MangoEmailContent (com.serotonin.m2m2.email.MangoEmailContent)1