use of com.serotonin.m2m2.vo.mailingList.MailingList in project ma-core-public by infiniteautomation.
the class MailingListsDwr method getMailingList.
@DwrPermission(admin = true)
public MailingList getMailingList(int id) {
if (id == Common.NEW_ID) {
MailingList ml = new MailingList();
ml.setId(Common.NEW_ID);
ml.setXid(MailingListDao.instance.generateUniqueXid());
ml.setEntries(new LinkedList<EmailRecipient>());
return ml;
}
return MailingListDao.instance.getMailingList(id);
}
use of com.serotonin.m2m2.vo.mailingList.MailingList in project ma-core-public by infiniteautomation.
the class MailingListsDwr method sendTestEmail.
@DwrPermission(admin = true)
public ProcessResult sendTestEmail(int id, String name, List<RecipientListEntryBean> entryBeans) {
ProcessResult response = new ProcessResult();
MailingList ml = createMailingList(id, null, name, AlarmLevels.IGNORE, entryBeans);
MailingListDao.instance.populateEntrySubclasses(ml.getEntries());
Set<String> addresses = new HashSet<String>();
ml.appendAddresses(addresses, null);
String[] toAddrs = addresses.toArray(new String[0]);
try {
Translations translations = Common.getTranslations();
Map<String, Object> model = new HashMap<String, Object>();
model.put("message", new TranslatableMessage("ftl.userTestEmail", ml.getName()));
MangoEmailContent cnt = new MangoEmailContent("testEmail", model, translations, translations.translate("ftl.testEmail"), Common.UTF8);
EmailWorkItem.queueEmail(toAddrs, cnt);
} catch (Exception e) {
response.addGenericMessage("mailingLists.testerror", e.getMessage());
log.warn("", e);
}
return response;
}
use of com.serotonin.m2m2.vo.mailingList.MailingList in project ma-core-public by infiniteautomation.
the class MailingListImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
if (StringUtils.isBlank(xid))
xid = ctx.getMailingListDao().generateUniqueXid();
MailingList vo = ctx.getMailingListDao().getMailingList(xid);
if (vo == null) {
vo = new MailingList();
vo.setXid(xid);
}
try {
ctx.getReader().readInto(vo, json);
// Now validate it. Use a new response object so we can distinguish errors in this vo from other errors.
ProcessResult voResponse = new ProcessResult();
vo.validate(voResponse);
if (voResponse.getHasMessages())
setValidationMessages(voResponse, "emport.mailingList.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = vo.getId() == Common.NEW_ID;
ctx.getMailingListDao().saveMailingList(vo);
addSuccessMessage(isnew, "emport.mailingList.prefix", xid);
}
} catch (TranslatableJsonException e) {
addFailureMessage("emport.mailingList.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.mailingList.prefix", xid, getJsonExceptionMessage(e));
}
}
use of com.serotonin.m2m2.vo.mailingList.MailingList in project ma-core-public by infiniteautomation.
the class RecipientListEntryBean method createEmailRecipient.
public EmailRecipient createEmailRecipient() {
switch(recipientType) {
case EmailRecipient.TYPE_MAILING_LIST:
MailingList ml = new MailingList();
ml.setId(referenceId);
return ml;
case EmailRecipient.TYPE_USER:
UserEntry u = new UserEntry();
u.setUserId(referenceId);
return u;
case EmailRecipient.TYPE_ADDRESS:
AddressEntry a = new AddressEntry();
a.setAddress(referenceAddress);
return a;
}
throw new ShouldNeverHappenException("Unknown email recipient type: " + recipientType);
}
use of com.serotonin.m2m2.vo.mailingList.MailingList in project ma-core-public by infiniteautomation.
the class MailingListDao method saveRelationalData.
void saveRelationalData(final MailingList ml) {
// Save the inactive intervals.
ejt.update("delete from mailingListInactive where mailingListId=?", new Object[] { ml.getId() });
// Save what is in the mailing list object.
final List<Integer> intervalIds = new ArrayList<Integer>(ml.getInactiveIntervals());
ejt.batchUpdate(MAILING_LIST_INACTIVE_INSERT, new BatchPreparedStatementSetter() {
public int getBatchSize() {
return intervalIds.size();
}
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setInt(1, ml.getId());
ps.setInt(2, intervalIds.get(i));
}
});
// Delete existing entries
ejt.update("delete from mailingListMembers where mailingListId=?", new Object[] { ml.getId() });
// Save what is in the mailing list object.
final List<EmailRecipient> entries = ml.getEntries();
ejt.batchUpdate(MAILING_LIST_ENTRY_INSERT, new BatchPreparedStatementSetter() {
public int getBatchSize() {
return entries.size();
}
public void setValues(PreparedStatement ps, int i) throws SQLException {
EmailRecipient e = entries.get(i);
ps.setInt(1, ml.getId());
ps.setInt(2, e.getRecipientType());
ps.setInt(3, e.getReferenceId());
ps.setString(4, e.getReferenceAddress());
}
});
}
Aggregations