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;
}
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;
}
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");
}
}
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");
}
}
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;
}
Aggregations