Search in sources :

Example 6 with MailingListRecipient

use of com.serotonin.m2m2.vo.mailingList.MailingListRecipient in project ma-core-public by MangoAutomation.

the class RecipientListEntryBean method createEmailRecipient.

/**
 * Convert to mailing list recipient
 */
public MailingListRecipient createEmailRecipient() {
    RecipientListEntryType type = RecipientListEntryType.fromValue(recipientType);
    switch(type) {
        case ADDRESS:
            AddressEntry a = new AddressEntry();
            a.setAddress(referenceAddress);
            return a;
        case MAILING_LIST:
            MailingListEntry ml = new MailingListEntry();
            ml.setMailingListId(referenceId);
            return ml;
        case PHONE_NUMBER:
            PhoneEntry pe = new PhoneEntry();
            pe.setPhone(referenceAddress);
            return pe;
        case USER:
            UserEntry u = new UserEntry();
            u.setUserId(referenceId);
            return u;
        case USER_PHONE_NUMBER:
            PhoneEntry p = new PhoneEntry();
            p.setPhone(referenceAddress);
            return p;
        default:
            throw new ShouldNeverHappenException("Unknown recipient type: " + recipientType);
    }
}
Also used : MailingListEntry(com.serotonin.m2m2.vo.mailingList.MailingListEntry) AddressEntry(com.serotonin.m2m2.vo.mailingList.AddressEntry) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) RecipientListEntryType(com.serotonin.m2m2.vo.mailingList.RecipientListEntryType) UserEntry(com.serotonin.m2m2.vo.mailingList.UserEntry) PhoneEntry(com.serotonin.m2m2.vo.mailingList.PhoneEntry)

Example 7 with MailingListRecipient

use of com.serotonin.m2m2.vo.mailingList.MailingListRecipient in project ma-core-public by MangoAutomation.

the class EmailHandlerRTTest method testSendActiveInactive.

@Test
public void testSendActiveInactive() {
    EmailEventHandlerVO vo = createVO();
    vo.setSendInactive(true);
    List<MailingListRecipient> activeRecipients = createRecipients();
    vo.setActiveRecipients(activeRecipients);
    EmailHandlerRT rt = new EmailHandlerRT(vo);
    EventInstance evt = createDataPointEventInstance();
    rt.eventRaised(evt);
    // Ensure there is one scheduled
    assertEquals(1, scheduledItems.size());
    scheduledItems.clear();
    // Make Inactive
    evt.returnToNormal(this.timer.currentTimeMillis(), ReturnCause.RETURN_TO_NORMAL);
    rt.eventInactive(evt);
    assertEquals(1, scheduledItems.size());
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) EmailEventHandlerVO(com.serotonin.m2m2.vo.event.EmailEventHandlerVO) MailingListRecipient(com.serotonin.m2m2.vo.mailingList.MailingListRecipient) Test(org.junit.Test)

Example 8 with MailingListRecipient

use of com.serotonin.m2m2.vo.mailingList.MailingListRecipient in project ma-core-public by MangoAutomation.

the class EmailHandlerRTTest method createRecipients.

protected List<MailingListRecipient> createRecipients() {
    List<MailingListRecipient> recipients = new ArrayList<>();
    AddressEntry address = new AddressEntry();
    address.setAddress("test@test.com");
    recipients.add(address);
    return recipients;
}
Also used : AddressEntry(com.serotonin.m2m2.vo.mailingList.AddressEntry) ArrayList(java.util.ArrayList) MailingListRecipient(com.serotonin.m2m2.vo.mailingList.MailingListRecipient)

Example 9 with MailingListRecipient

use of com.serotonin.m2m2.vo.mailingList.MailingListRecipient in project ma-core-public by MangoAutomation.

the class MailingListService method recursivelyCheckMailingListEntries.

/**
 */
private void recursivelyCheckMailingListEntries(Set<Integer> listIds, MailingList list, String prefix, ProcessResult result) {
    for (MailingListRecipient recipient : list.getEntries()) {
        switch(recipient.getRecipientType()) {
            case MAILING_LIST:
                if (!listIds.add(recipient.getReferenceId())) {
                    // Failed, we already have this list as reference
                    result.addContextualMessage(prefix, "mailingLists.validate.listCannotContainItself");
                    return;
                } else {
                    MailingList sublist = dao.get(recipient.getReferenceId());
                    recursivelyCheckMailingListEntries(listIds, sublist, prefix, result);
                }
                break;
            default:
                break;
        }
    }
}
Also used : MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) MailingListRecipient(com.serotonin.m2m2.vo.mailingList.MailingListRecipient)

Example 10 with MailingListRecipient

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

the class MailingListDao method getRecipientType.

private MailingListRecipient getRecipientType(Record record) {
    int intType = record.get(mailingListMembersTable.typeId);
    RecipientListEntryType type = RecipientListEntryType.fromValue(intType);
    Integer userId = record.get(mailingListMembersTable.userId);
    switch(type) {
        case ADDRESS:
            AddressEntry ae = new AddressEntry();
            ae.setAddress(record.get(mailingListMembersTable.address));
            return ae;
        case MAILING_LIST:
            MailingListEntry ml = new MailingListEntry();
            ml.setMailingListId(userId != null ? userId : 0);
            return ml;
        case PHONE_NUMBER:
            PhoneEntry pe = new PhoneEntry();
            pe.setPhone(record.get(mailingListMembersTable.address));
            return pe;
        case USER:
        case USER_PHONE_NUMBER:
            UserEntry ue = new UserEntry();
            ue.setUserId(userId != null ? userId : 0);
            return ue;
        default:
            throw new ShouldNeverHappenException("Unknown mailing list entry type: " + intType);
    }
}
Also used : MailingListEntry(com.serotonin.m2m2.vo.mailingList.MailingListEntry) AddressEntry(com.serotonin.m2m2.vo.mailingList.AddressEntry) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) RecipientListEntryType(com.serotonin.m2m2.vo.mailingList.RecipientListEntryType) UserEntry(com.serotonin.m2m2.vo.mailingList.UserEntry) PhoneEntry(com.serotonin.m2m2.vo.mailingList.PhoneEntry)

Aggregations

MailingListRecipient (com.serotonin.m2m2.vo.mailingList.MailingListRecipient)31 ArrayList (java.util.ArrayList)17 AddressEntry (com.serotonin.m2m2.vo.mailingList.AddressEntry)13 MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)13 Test (org.junit.Test)10 MailingListEntry (com.serotonin.m2m2.vo.mailingList.MailingListEntry)9 EmailEventHandlerVO (com.serotonin.m2m2.vo.event.EmailEventHandlerVO)8 UserEntry (com.serotonin.m2m2.vo.mailingList.UserEntry)8 PhoneEntry (com.serotonin.m2m2.vo.mailingList.PhoneEntry)7 EventInstance (com.serotonin.m2m2.rt.event.EventInstance)6 IntStringPair (com.serotonin.db.pair.IntStringPair)5 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)4 User (com.serotonin.m2m2.vo.User)4 RecipientListEntryType (com.serotonin.m2m2.vo.mailingList.RecipientListEntryType)4 RecipientListEntryBean (com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)4 HashSet (java.util.HashSet)4 List (java.util.List)4 ScriptPermissions (com.infiniteautomation.mango.util.script.ScriptPermissions)3 EmailRecipientModel (com.infiniteautomation.mango.rest.latest.model.mailingList.EmailRecipientModel)2 ExpectValidationException (com.infiniteautomation.mango.rules.ExpectValidationException)2