Search in sources :

Example 26 with MailingListRecipient

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

the class EmailEventHandlerModel method readInto.

@Override
public void readInto(EmailEventHandlerVO vo) {
    super.readInto(vo);
    if (activeRecipients != null) {
        List<MailingListRecipient> beans = new ArrayList<>();
        for (EmailRecipientModel model : activeRecipients) beans.add(model.fromModel());
        vo.setActiveRecipients(beans);
    }
    vo.setSendEscalation(sendEscalation);
    vo.setRepeatEscalations(repeatEscalations);
    vo.setEscalationDelayType(Common.TIME_PERIOD_CODES.getId(escalationDelayType));
    vo.setEscalationDelay(escalationDelay);
    if (escalationRecipients != null) {
        List<MailingListRecipient> beans = new ArrayList<>();
        for (EmailRecipientModel model : escalationRecipients) beans.add(model.fromModel());
        vo.setEscalationRecipients(beans);
    }
    vo.setSendInactive(sendInactive);
    vo.setInactiveOverride(inactiveOverride);
    if (inactiveRecipients != null) {
        List<MailingListRecipient> beans = new ArrayList<>();
        for (EmailRecipientModel model : inactiveRecipients) beans.add(model.fromModel());
        vo.setInactiveRecipients(beans);
    }
    vo.setIncludeSystemInfo(includeSystemInfo);
    if (includePointValueCount != null)
        vo.setIncludePointValueCount(includePointValueCount);
    vo.setIncludeLogfile(includeLogfile);
    vo.setCustomTemplate(customTemplate);
    vo.setScript(script);
    PermissionService service = Common.getBean(PermissionService.class);
    vo.setScriptRoles(new ScriptPermissions(service.explodeLegacyPermissionGroupsToRoles(scriptPermissions)));
    if (scriptContext != null) {
        List<IntStringPair> additionalContext = new ArrayList<>();
        for (ScriptContextVariableModel var : scriptContext) {
            Integer id = DataPointDao.getInstance().getIdByXid(var.getXid());
            if (id != null) {
                additionalContext.add(new IntStringPair(id, var.getVariableName()));
            } else {
                additionalContext.add(new IntStringPair(Common.NEW_ID, var.getVariableName()));
            }
        }
        vo.setAdditionalContext(additionalContext);
    }
    vo.setSubject(EmailEventHandlerVO.SUBJECT_INCLUDE_CODES.getId(subject));
}
Also used : PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) IntStringPair(com.serotonin.db.pair.IntStringPair) ScriptContextVariableModel(com.infiniteautomation.mango.rest.latest.model.javascript.MangoJavaScriptModel.ScriptContextVariableModel) ArrayList(java.util.ArrayList) MailingListRecipient(com.serotonin.m2m2.vo.mailingList.MailingListRecipient) EmailRecipientModel(com.infiniteautomation.mango.rest.latest.model.mailingList.EmailRecipientModel) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions)

Example 27 with MailingListRecipient

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

the class EmailEventHandlerModelMapping method mapHandler.

@Override
public EmailEventHandlerModel mapHandler(EmailEventHandlerVO vo, PermissionHolder user, RestModelMapper mapper) {
    EmailEventHandlerModel model = new EmailEventHandlerModel(vo);
    if (vo.getActiveRecipients() != null) {
        List<EmailRecipientModel> activeRecipients = new ArrayList<>();
        model.setActiveRecipients(activeRecipients);
        for (MailingListRecipient bean : vo.getActiveRecipients()) {
            activeRecipients.add(mapper.map(bean, EmailRecipientModel.class, user));
        }
    }
    if (vo.getEscalationRecipients() != null) {
        List<EmailRecipientModel> escalationRecipients = new ArrayList<>();
        model.setEscalationRecipients(escalationRecipients);
        for (MailingListRecipient bean : vo.getEscalationRecipients()) {
            escalationRecipients.add(mapper.map(bean, EmailRecipientModel.class, user));
        }
    }
    if (vo.getInactiveRecipients() != null) {
        List<EmailRecipientModel> inactiveRecipients = new ArrayList<>();
        model.setInactiveRecipients(inactiveRecipients);
        for (MailingListRecipient bean : vo.getInactiveRecipients()) {
            inactiveRecipients.add(mapper.map(bean, EmailRecipientModel.class, user));
        }
    }
    return model;
}
Also used : ArrayList(java.util.ArrayList) MailingListRecipient(com.serotonin.m2m2.vo.mailingList.MailingListRecipient) EmailRecipientModel(com.infiniteautomation.mango.rest.latest.model.mailingList.EmailRecipientModel)

Example 28 with MailingListRecipient

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

the class MailingListServiceTest method assertVoEqual.

@Override
void assertVoEqual(MailingList expected, MailingList actual) {
    assertEquals(expected.getId(), actual.getId());
    assertEquals(expected.getReceiveAlarmEmails(), actual.getReceiveAlarmEmails());
    assertEquals(expected.getEntries().size(), actual.getEntries().size());
    for (int i = 0; i < expected.getEntries().size(); i++) {
        MailingListRecipient expectedRecipient = expected.getEntries().get(i);
        MailingListRecipient actualRecipient = actual.getEntries().get(i);
        switch(expectedRecipient.getRecipientType()) {
            case ADDRESS:
            case PHONE_NUMBER:
                assertEquals(expectedRecipient.getReferenceAddress(), actualRecipient.getReferenceAddress());
                break;
            case USER:
            case USER_PHONE_NUMBER:
            case MAILING_LIST:
                assertEquals(expectedRecipient.getReferenceId(), actualRecipient.getReferenceId());
                break;
            default:
                fail("unknown recipient type");
        }
    }
    assertPermission(expected.getReadPermission(), actual.getReadPermission());
    assertPermission(expected.getEditPermission(), actual.getEditPermission());
}
Also used : MailingListRecipient(com.serotonin.m2m2.vo.mailingList.MailingListRecipient)

Example 29 with MailingListRecipient

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

the class MailingListServiceTest method newVO.

@Override
MailingList newVO(User owner) {
    MailingList vo = new MailingList();
    vo.setXid(MailingListDao.getInstance().generateUniqueXid());
    vo.setName("MailingList");
    vo.setReceiveAlarmEmails(AlarmLevels.NONE);
    List<MailingListRecipient> entries = new ArrayList<>();
    AddressEntry entry = new AddressEntry();
    entry.setAddress("entry1@example.com");
    entries.add(entry);
    vo.setEntries(entries);
    return vo;
}
Also used : AddressEntry(com.serotonin.m2m2.vo.mailingList.AddressEntry) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) ArrayList(java.util.ArrayList) MailingListRecipient(com.serotonin.m2m2.vo.mailingList.MailingListRecipient)

Example 30 with MailingListRecipient

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

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)

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