Search in sources :

Example 1 with EmailRecipient

use of com.serotonin.m2m2.vo.mailingList.EmailRecipient in project ma-modules-public by infiniteautomation.

the class M2MRecipientListEntryBean 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 2 with EmailRecipient

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

the class EmailRecipientModel method createBean.

/**
 * Create a bean from a model
 * @param model
 * @return
 */
public static RecipientListEntryBean createBean(EmailRecipientModel<?> model) {
    EmailRecipient r = model.getData();
    RecipientListEntryBean bean = new RecipientListEntryBean();
    bean.setRecipientType(r.getRecipientType());
    switch(r.getRecipientType()) {
        case EmailRecipient.TYPE_ADDRESS:
            bean.setReferenceAddress(r.getReferenceAddress());
            break;
        case EmailRecipient.TYPE_MAILING_LIST:
            // This only comes back with an XID from the page
            MailingList list = MailingListDao.instance.getMailingList(((MailingList) r).getXid());
            if (list != null)
                bean.setReferenceId(list.getId());
            break;
        case EmailRecipient.TYPE_USER:
            User u = UserDao.instance.getUser(((UserEntry) r).getUserId());
            if (u != null)
                bean.setReferenceId(u.getId());
            break;
    }
    return bean;
}
Also used : EmailRecipient(com.serotonin.m2m2.vo.mailingList.EmailRecipient) User(com.serotonin.m2m2.vo.User) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) RecipientListEntryBean(com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)

Example 3 with EmailRecipient

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

the class MailingListsDwr method createMailingList.

// 
// /
// / Private helper methods
// /
// 
private MailingList createMailingList(int id, String xid, String name, int receiveAlarmEmails, List<RecipientListEntryBean> entryBeans) {
    // Convert the incoming information into more useful types.
    MailingList ml = new MailingList();
    ml.setId(id);
    ml.setXid(xid);
    ml.setName(name);
    ml.setReceiveAlarmEmails(receiveAlarmEmails);
    List<EmailRecipient> entries = new ArrayList<EmailRecipient>(entryBeans.size());
    for (RecipientListEntryBean bean : entryBeans) entries.add(bean.createEmailRecipient());
    ml.setEntries(entries);
    return ml;
}
Also used : EmailRecipient(com.serotonin.m2m2.vo.mailingList.EmailRecipient) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) ArrayList(java.util.ArrayList) RecipientListEntryBean(com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)

Example 4 with EmailRecipient

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

the class MailingListDao method getRecipientAddresses.

public Set<String> getRecipientAddresses(List<RecipientListEntryBean> beans, DateTime sendTime) {
    List<EmailRecipient> entries = new ArrayList<EmailRecipient>(beans.size());
    for (RecipientListEntryBean bean : beans) entries.add(bean.createEmailRecipient());
    populateEntrySubclasses(entries);
    Set<String> addresses = new HashSet<String>();
    for (EmailRecipient entry : entries) entry.appendAddresses(addresses, sendTime);
    return addresses;
}
Also used : EmailRecipient(com.serotonin.m2m2.vo.mailingList.EmailRecipient) ArrayList(java.util.ArrayList) RecipientListEntryBean(com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean) HashSet(java.util.HashSet)

Example 5 with EmailRecipient

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

the class MailingListDao method generateRecipientAddresses.

/**
 * Generate the recipient addresses
 * @param entries
 * @param sendTime
 * @return
 */
public Set<String> generateRecipientAddresses(List<EmailRecipient> entries, DateTime sendTime) {
    populateEntrySubclasses(entries);
    Set<String> addresses = new HashSet<String>();
    for (EmailRecipient entry : entries) entry.appendAddresses(addresses, sendTime);
    return addresses;
}
Also used : EmailRecipient(com.serotonin.m2m2.vo.mailingList.EmailRecipient) HashSet(java.util.HashSet)

Aggregations

EmailRecipient (com.serotonin.m2m2.vo.mailingList.EmailRecipient)6 MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)5 RecipientListEntryBean (com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)3 ArrayList (java.util.ArrayList)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 AddressEntry (com.serotonin.m2m2.vo.mailingList.AddressEntry)2 UserEntry (com.serotonin.m2m2.vo.mailingList.UserEntry)2 HashSet (java.util.HashSet)2 User (com.serotonin.m2m2.vo.User)1 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 BatchPreparedStatementSetter (org.springframework.jdbc.core.BatchPreparedStatementSetter)1