Search in sources :

Example 6 with MailingList

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

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

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

the class RecipientListEntryBean method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    String text = jsonObject.getString("recipientType");
    if (text == null)
        throw new TranslatableJsonException("emport.error.recipient.missing", "recipientType", EmailRecipient.TYPE_CODES.getCodeList());
    recipientType = EmailRecipient.TYPE_CODES.getId(text);
    if (recipientType == -1)
        throw new TranslatableJsonException("emport.error.recipient.invalid", "recipientType", text, EmailRecipient.TYPE_CODES.getCodeList());
    if (recipientType == EmailRecipient.TYPE_MAILING_LIST) {
        text = jsonObject.getString("mailingList");
        if (text == null)
            throw new TranslatableJsonException("emport.error.recipient.missing.reference", "mailingList");
        MailingList ml = MailingListDao.instance.getMailingList(text);
        if (ml == null)
            throw new TranslatableJsonException("emport.error.recipient.invalid.reference", "mailingList", text);
        referenceId = ml.getId();
    } else if (recipientType == EmailRecipient.TYPE_USER) {
        text = jsonObject.getString("username");
        if (text == null)
            throw new TranslatableJsonException("emport.error.recipient.missing.reference", "username");
        User user = UserDao.instance.getUser(text);
        if (user == null)
            throw new TranslatableJsonException("emport.error.recipient.invalid.reference", "user", text);
        referenceId = user.getId();
    } else if (recipientType == EmailRecipient.TYPE_ADDRESS) {
        referenceAddress = jsonObject.getString("address");
        if (referenceAddress == null)
            throw new TranslatableJsonException("emport.error.recipient.missing.reference", "address");
    }
}
Also used : User(com.serotonin.m2m2.vo.User) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 9 with MailingList

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

the class M2MRecipientListEntryBean method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    String text = jsonObject.getString("recipientType");
    if (text == null)
        throw new TranslatableJsonException("emport.error.recipient.missing", "recipientType", EmailRecipient.TYPE_CODES.getCodeList());
    recipientType = EmailRecipient.TYPE_CODES.getId(text);
    if (recipientType == -1)
        throw new TranslatableJsonException("emport.error.recipient.invalid", "recipientType", text, EmailRecipient.TYPE_CODES.getCodeList());
    if (recipientType == EmailRecipient.TYPE_MAILING_LIST) {
        text = jsonObject.getString("mailingList");
        if (text == null)
            throw new TranslatableJsonException("emport.error.recipient.missing.reference", "mailingList");
        MailingList ml = MailingListDao.instance.getMailingList(text);
        if (ml == null)
            throw new TranslatableJsonException("emport.error.recipient.invalid.reference", "mailingList", text);
        referenceId = ml.getId();
    } else if (recipientType == EmailRecipient.TYPE_USER) {
        text = jsonObject.getString("username");
        if (text == null)
            throw new TranslatableJsonException("emport.error.recipient.missing.reference", "username");
        User user = UserDao.instance.getUser(text);
        if (user == null)
            throw new TranslatableJsonException("emport.error.recipient.invalid.reference", "user", text);
        referenceId = user.getId();
    } else if (recipientType == EmailRecipient.TYPE_ADDRESS) {
        referenceAddress = jsonObject.getString("address");
        if (referenceAddress == null)
            throw new TranslatableJsonException("emport.error.recipient.missing.reference", "address");
    }
}
Also used : User(com.serotonin.m2m2.vo.User) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 10 with MailingList

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

the class M2MRecipientListEntryBean method convert.

/**
 * @param legacyDao
 * @return
 */
public RecipientListEntryBean convert(M2MReportDao legacyDao) {
    RecipientListEntryBean bean = new RecipientListEntryBean();
    bean.setRecipientType(recipientType);
    switch(recipientType) {
        case EmailRecipient.TYPE_USER:
            String username = legacyDao.getUsername(referenceId);
            User user = UserDao.instance.getUser(username);
            if (user != null)
                bean.setReferenceId(user.getId());
            else
                throw new ShouldNeverHappenException("User " + username + " not found in Mango.");
            break;
        case EmailRecipient.TYPE_ADDRESS:
            bean.setReferenceAddress(referenceAddress);
            break;
        case EmailRecipient.TYPE_MAILING_LIST:
            String listXid = legacyDao.getMailingListXid(referenceId);
            MailingList list = MailingListDao.instance.getMailingList(listXid);
            if (list != null)
                bean.setReferenceId(list.getId());
            else
                throw new ShouldNeverHappenException("Mailing list with XID: " + listXid + " not found in Mango.");
            break;
    }
    return bean;
}
Also used : User(com.serotonin.m2m2.vo.User) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) RecipientListEntryBean(com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)

Aggregations

MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)14 User (com.serotonin.m2m2.vo.User)5 EmailRecipient (com.serotonin.m2m2.vo.mailingList.EmailRecipient)4 ArrayList (java.util.ArrayList)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)3 RecipientListEntryBean (com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)3 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)3 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)2 AddressEntry (com.serotonin.m2m2.vo.mailingList.AddressEntry)2 UserEntry (com.serotonin.m2m2.vo.mailingList.UserEntry)2 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)2 MailingListModel (com.serotonin.m2m2.web.mvc.rest.v1.model.email.MailingListModel)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 HashSet (java.util.HashSet)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JsonException (com.serotonin.json.JsonException)1 MailingListDao (com.serotonin.m2m2.db.dao.MailingListDao)1 MangoEmailContent (com.serotonin.m2m2.email.MangoEmailContent)1