Search in sources :

Example 1 with RecipientListEntryBean

use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean 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 2 with RecipientListEntryBean

use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean in project ma-core-public by infiniteautomation.

the class EmailEventHandlerVO method jsonRead.

@SuppressWarnings("unchecked")
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    String text = null;
    TypeDefinition recipType = new TypeDefinition(List.class, RecipientListEntryBean.class);
    JsonArray jsonActiveRecipients = jsonObject.getJsonArray("activeRecipients");
    if (jsonActiveRecipients != null)
        activeRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonActiveRecipients);
    JsonBoolean b = jsonObject.getJsonBoolean("sendEscalation");
    if (b != null)
        sendEscalation = b.booleanValue();
    if (sendEscalation) {
        text = jsonObject.getString("escalationDelayType");
        if (text != null) {
            escalationDelayType = Common.TIME_PERIOD_CODES.getId(text);
            if (escalationDelayType == -1)
                throw new TranslatableJsonException("emport.error.invalid", "escalationDelayType", text, Common.TIME_PERIOD_CODES.getCodeList());
        }
        Integer i = jsonObject.getInt("escalationDelay", 1);
        if (i != null)
            escalationDelay = i;
        JsonArray jsonEscalationRecipients = jsonObject.getJsonArray("escalationRecipients");
        if (jsonEscalationRecipients != null)
            escalationRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonEscalationRecipients);
        b = jsonObject.getJsonBoolean("keepSendingEscalations");
        if (b != null)
            repeatEscalations = b.booleanValue();
    }
    b = jsonObject.getJsonBoolean("sendInactive");
    if (b != null)
        sendInactive = b.booleanValue();
    if (sendInactive) {
        b = jsonObject.getJsonBoolean("inactiveOverride");
        if (b != null)
            inactiveOverride = b.booleanValue();
        if (inactiveOverride) {
            JsonArray jsonInactiveRecipients = jsonObject.getJsonArray("inactiveRecipients");
            if (jsonInactiveRecipients != null)
                inactiveRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonInactiveRecipients);
        }
    }
    b = jsonObject.getJsonBoolean("includeSystemInformation");
    if (b != null)
        includeSystemInfo = b.booleanValue();
    includePointValueCount = jsonObject.getInt("includePointValueCount", 0);
    b = jsonObject.getJsonBoolean("includeLogfile");
    if (b != null)
        includeSystemInfo = b.booleanValue();
    customTemplate = jsonObject.getString("customTemplate");
    JsonArray context = jsonObject.getJsonArray("additionalContext");
    if (context != null) {
        List<IntStringPair> additionalContext = new ArrayList<>();
        for (JsonValue jv : context) {
            JsonObject jo = jv.toJsonObject();
            String dataPointXid = jo.getString("dataPointXid");
            if (dataPointXid == null)
                throw new TranslatableJsonException("emport.error.context.missing", "dataPointXid");
            DataPointVO dpvo = DataPointDao.instance.getByXid(dataPointXid);
            if (dpvo == null)
                throw new TranslatableJsonException("emport.error.missingPoint", dataPointXid);
            String contextKey = jo.getString("contextKey");
            if (contextKey == null)
                throw new TranslatableJsonException("emport.error.context.missing", "contextKey");
            additionalContext.add(new IntStringPair(dpvo.getId(), contextKey));
        }
        this.additionalContext = additionalContext;
    } else
        this.additionalContext = new ArrayList<>();
    script = jsonObject.getString("script");
    JsonObject permissions = jsonObject.getJsonObject("scriptPermissions");
    ScriptPermissions scriptPermissions = new ScriptPermissions();
    if (permissions != null) {
        String perm = permissions.getString(ScriptPermissions.DATA_SOURCE);
        if (perm != null)
            scriptPermissions.setDataSourcePermissions(perm);
        perm = permissions.getString(ScriptPermissions.DATA_POINT_READ);
        if (perm != null)
            scriptPermissions.setDataPointReadPermissions(perm);
        perm = permissions.getString(ScriptPermissions.DATA_POINT_SET);
        if (perm != null)
            scriptPermissions.setDataPointSetPermissions(perm);
    }
    this.scriptPermissions = scriptPermissions;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) IntStringPair(com.serotonin.db.pair.IntStringPair) ArrayList(java.util.ArrayList) JsonValue(com.serotonin.json.type.JsonValue) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonObject(com.serotonin.json.type.JsonObject) ScriptPermissions(com.serotonin.m2m2.rt.script.ScriptPermissions) TypeDefinition(com.serotonin.json.util.TypeDefinition) JsonArray(com.serotonin.json.type.JsonArray) ArrayList(java.util.ArrayList) List(java.util.List) JsonBoolean(com.serotonin.json.type.JsonBoolean)

Example 3 with RecipientListEntryBean

use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean 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 RecipientListEntryBean

use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean in project ma-core-public by infiniteautomation.

the class MailingListsDwr method saveMailingList.

@DwrPermission(admin = true)
public ProcessResult saveMailingList(int id, String xid, String name, int receiveAlarmEmails, List<RecipientListEntryBean> entryBeans, List<Integer> inactiveIntervals) {
    ProcessResult response = new ProcessResult();
    MailingListDao mailingListDao = MailingListDao.instance;
    // Validate the given information. If there is a problem, return an appropriate error message.
    MailingList ml = createMailingList(id, xid, name, receiveAlarmEmails, entryBeans);
    ml.getInactiveIntervals().addAll(inactiveIntervals);
    if (StringUtils.isBlank(xid))
        response.addContextualMessage("xid", "validate.required");
    else if (!mailingListDao.isXidUnique(xid, id))
        response.addContextualMessage("xid", "validate.xidUsed");
    ml.validate(response);
    if (!response.getHasMessages()) {
        // Save the mailing list
        mailingListDao.saveMailingList(ml);
        response.addData("mlId", ml.getId());
    }
    if (!AlarmLevels.CODES.isValidId(receiveAlarmEmails))
        response.addContextualMessage("receiveAlarmEmails", "validate.invalidValue");
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) MailingListDao(com.serotonin.m2m2.db.dao.MailingListDao) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 5 with RecipientListEntryBean

use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean in project ma-core-public by infiniteautomation.

the class RecipientListEntryBean method cleanRecipientList.

/**
 * Clean a list of beans by removing any entries with dead references.
 * @param list
 */
public static void cleanRecipientList(List<RecipientListEntryBean> list) {
    if (list == null)
        return;
    ListIterator<RecipientListEntryBean> it = list.listIterator();
    MailingListDao mlDao = MailingListDao.instance;
    while (it.hasNext()) {
        RecipientListEntryBean bean = it.next();
        switch(bean.recipientType) {
            case EmailRecipient.TYPE_ADDRESS:
                if (StringUtils.isEmpty(bean.referenceAddress))
                    it.remove();
                break;
            case EmailRecipient.TYPE_MAILING_LIST:
                if (mlDao.getMailingList(bean.referenceId) == null)
                    it.remove();
                break;
            case EmailRecipient.TYPE_USER:
                if (!UserDao.instance.userExists(bean.referenceId))
                    it.remove();
                break;
        }
    }
}
Also used : MailingListDao(com.serotonin.m2m2.db.dao.MailingListDao)

Aggregations

RecipientListEntryBean (com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)8 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)6 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)5 User (com.serotonin.m2m2.vo.User)5 MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)5 ArrayList (java.util.ArrayList)5 JsonArray (com.serotonin.json.type.JsonArray)3 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)3 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)3 ReportVO (com.serotonin.m2m2.reports.vo.ReportVO)3 EmailRecipient (com.serotonin.m2m2.vo.mailingList.EmailRecipient)3 List (java.util.List)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 IntStringPair (com.serotonin.db.pair.IntStringPair)2 JsonBoolean (com.serotonin.json.type.JsonBoolean)2 JsonValue (com.serotonin.json.type.JsonValue)2 TypeDefinition (com.serotonin.json.util.TypeDefinition)2 MailingListDao (com.serotonin.m2m2.db.dao.MailingListDao)2 MangoEmailContent (com.serotonin.m2m2.email.MangoEmailContent)2 Translations (com.serotonin.m2m2.i18n.Translations)2