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;
}
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;
}
}
}
use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean in project ma-core-public by infiniteautomation.
the class MailingListDao method getRecipientAddresses.
public Set<String> getRecipientAddresses(List<RecipientListEntryBean> beans, DateTime sendTime) {
List<EmailRecipient> entries = new ArrayList<EmailRecipient>(beans.size());
for (RecipientListEntryBean bean : beans) entries.add(bean.createEmailRecipient());
populateEntrySubclasses(entries);
Set<String> addresses = new HashSet<String>();
for (EmailRecipient entry : entries) entry.appendAddresses(addresses, sendTime);
return addresses;
}
use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean 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;
}
use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean in project ma-modules-public by infiniteautomation.
the class ReportVO method jsonRead.
/* (non-Javadoc)
* @see com.serotonin.json.spi.JsonSerializable#jsonRead(com.serotonin.json.JsonReader, com.serotonin.json.type.JsonObject)
*/
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
if (jsonObject.containsKey("userId")) {
userId = jsonObject.getInt("userId");
} else if (jsonObject.containsKey("user")) {
String username = jsonObject.getString("user");
if (org.apache.commons.lang3.StringUtils.isBlank(username))
throw new TranslatableJsonException("emport.error.missingValue", "user");
User user = UserDao.instance.getUser(username);
if (user == null)
throw new TranslatableJsonException("emport.error.missingUser", username);
userId = user.getId();
}
String text = jsonObject.getString("includeEvents");
if (text != null) {
includeEvents = EVENT_CODES.getId(text);
if (includeEvents == -1)
throw new TranslatableJsonException("emport.error.invalid", "includeEvents", text, EVENT_CODES.getCodeList());
}
text = jsonObject.getString("dateRangeType");
if (text != null) {
dateRangeType = DATE_RANGE_TYPES.getId(text);
if (dateRangeType == -1)
throw new TranslatableJsonException("emport.error.invalid", "dateRangeType", text, DATE_RANGE_TYPES.getCodeList());
}
if (dateRangeType == DATE_RANGE_TYPE_RELATIVE) {
text = jsonObject.getString("relativeDateType");
if (text != null) {
relativeDateType = DATE_RELATIVE_TYPES.getId(text);
if (relativeDateType == -1)
throw new TranslatableJsonException("emport.error.invalid", "relativeDateType", text, DATE_RELATIVE_TYPES.getCodeList());
}
if (relativeDateType == RELATIVE_DATE_TYPE_PREVIOUS) {
text = jsonObject.getString("previousPeriodType");
if (text != null) {
previousPeriodType = Common.TIME_PERIOD_CODES.getId(text);
if (previousPeriodType == -1)
throw new TranslatableJsonException("emport.error.invalid", "previousPeriodType", text, Common.TIME_PERIOD_CODES.getCodeList());
previousPeriodCount = jsonObject.getInt("previousPeriods");
} else {
// FOR legacy bug where previousPeriodType was misspelled
text = jsonObject.getString("perviousPeriodType");
if (text != null) {
previousPeriodType = Common.TIME_PERIOD_CODES.getId(text);
if (previousPeriodType == -1)
throw new TranslatableJsonException("emport.error.invalid", "previousPeriodType", text, Common.TIME_PERIOD_CODES.getCodeList());
previousPeriodCount = jsonObject.getInt("previousPeriods");
}
}
} else if (relativeDateType == RELATIVE_DATE_TYPE_PREVIOUS) {
text = jsonObject.getString("pastPeriodType");
if (text != null) {
pastPeriodType = Common.TIME_PERIOD_CODES.getId(text);
if (pastPeriodType == -1)
throw new TranslatableJsonException("emport.error.invalid", "pastPeriodType", text, Common.TIME_PERIOD_CODES.getCodeList());
pastPeriodCount = jsonObject.getInt("pastPeriods");
}
}
} else if (dateRangeType == DATE_RANGE_TYPE_SPECIFIC) {
fromNone = jsonObject.getBoolean("fromInception");
if (!fromNone) {
fromYear = jsonObject.getInt("fromYear");
fromMonth = jsonObject.getInt("fromMonth");
fromDay = jsonObject.getInt("fromDay");
fromHour = jsonObject.getInt("fromHour");
fromMinute = jsonObject.getInt("fromMinute");
}
toNone = jsonObject.getBoolean("toLatest");
if (!toNone) {
toYear = jsonObject.getInt("toYear");
toMonth = jsonObject.getInt("toMonth");
toDay = jsonObject.getInt("toDay");
toHour = jsonObject.getInt("toHour");
toMinute = jsonObject.getInt("toMinute");
}
}
schedule = jsonObject.getBoolean("schedule");
if (schedule) {
text = jsonObject.getString("schedulePeriod");
if (text != null) {
schedulePeriod = SCHEDULE_CODES.getId(text);
if (schedulePeriod == -1)
throw new TranslatableJsonException("emport.error.invalid", "schedulePeriod", text, SCHEDULE_CODES.getCodeList());
if (schedulePeriod == SCHEDULE_CRON) {
scheduleCron = jsonObject.getString("scheduleCron");
try {
new CronTimerTrigger(scheduleCron);
} catch (ParseException e) {
throw new TranslatableJsonException("emport.error.invalid", "scheduleCron", scheduleCron, "cron expressions");
}
}
} else {
throw new TranslatableJsonException("emport.error.invalid", "schedulePeriod", "null", SCHEDULE_CODES.getCodeList());
}
}
email = jsonObject.getBoolean("email");
if (email) {
JsonArray recipientsArray = jsonObject.getJsonArray("recipients");
boolean add = true;
if (recipientsArray != null) {
for (JsonValue jv : recipientsArray) {
RecipientListEntryBean recipient = new RecipientListEntryBean();
reader.readInto(recipient, jv);
for (RecipientListEntryBean existing : recipients) {
if (existing.equals(recipient)) {
reader.readInto(existing, jv);
add = false;
break;
}
}
if (add) {
recipients.add(recipient);
} else {
add = true;
}
}
} else {
throw new TranslatableJsonException("emport.error.invalid", "recipients", "null", "valid users, email addresses or mailing lists");
}
includeData = jsonObject.getBoolean("includeData");
if (includeData)
zipData = jsonObject.getBoolean("zipData");
}
JsonArray pointsArray = jsonObject.getJsonArray("points");
if (pointsArray != null) {
points = new ArrayList<ReportPointVO>();
for (JsonValue jv : pointsArray) {
ReportPointVO reportPoint = new ReportPointVO();
reader.readInto(reportPoint, jv);
// TODO prevent adding the same point twice?
points.add(reportPoint);
}
}
}
Aggregations