use of com.serotonin.m2m2.db.dao.MailingListDao 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;
}
use of com.serotonin.m2m2.db.dao.MailingListDao 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;
}
}
}
Aggregations