Search in sources :

Example 6 with EmailRecipient

use of com.serotonin.m2m2.vo.mailingList.EmailRecipient 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 7 with EmailRecipient

use of com.serotonin.m2m2.vo.mailingList.EmailRecipient 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 8 with EmailRecipient

use of com.serotonin.m2m2.vo.mailingList.EmailRecipient 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

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