Search in sources :

Example 1 with EmailRecipientModel

use of com.infiniteautomation.mango.rest.latest.model.mailingList.EmailRecipientModel 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 2 with EmailRecipientModel

use of com.infiniteautomation.mango.rest.latest.model.mailingList.EmailRecipientModel 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)

Aggregations

EmailRecipientModel (com.infiniteautomation.mango.rest.latest.model.mailingList.EmailRecipientModel)2 MailingListRecipient (com.serotonin.m2m2.vo.mailingList.MailingListRecipient)2 ArrayList (java.util.ArrayList)2 ScriptContextVariableModel (com.infiniteautomation.mango.rest.latest.model.javascript.MangoJavaScriptModel.ScriptContextVariableModel)1 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)1 ScriptPermissions (com.infiniteautomation.mango.util.script.ScriptPermissions)1 IntStringPair (com.serotonin.db.pair.IntStringPair)1