use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean in project ma-core-public by infiniteautomation.
the class EmailRecipientModel method createBean.
/**
* Create a bean from a model
* @param model
* @return
*/
public static RecipientListEntryBean createBean(EmailRecipientModel<?> model) {
EmailRecipient r = model.getData();
RecipientListEntryBean bean = new RecipientListEntryBean();
bean.setRecipientType(r.getRecipientType());
switch(r.getRecipientType()) {
case EmailRecipient.TYPE_ADDRESS:
bean.setReferenceAddress(r.getReferenceAddress());
break;
case EmailRecipient.TYPE_MAILING_LIST:
// This only comes back with an XID from the page
MailingList list = MailingListDao.instance.getMailingList(((MailingList) r).getXid());
if (list != null)
bean.setReferenceId(list.getId());
break;
case EmailRecipient.TYPE_USER:
User u = UserDao.instance.getUser(((UserEntry) r).getUserId());
if (u != null)
bean.setReferenceId(u.getId());
break;
}
return bean;
}
use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean in project ma-core-public by infiniteautomation.
the class EmailEventHandlerVO method jsonRead.
@SuppressWarnings("unchecked")
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
String text = null;
TypeDefinition recipType = new TypeDefinition(List.class, RecipientListEntryBean.class);
JsonArray jsonActiveRecipients = jsonObject.getJsonArray("activeRecipients");
if (jsonActiveRecipients != null)
activeRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonActiveRecipients);
JsonBoolean b = jsonObject.getJsonBoolean("sendEscalation");
if (b != null)
sendEscalation = b.booleanValue();
if (sendEscalation) {
text = jsonObject.getString("escalationDelayType");
if (text != null) {
escalationDelayType = Common.TIME_PERIOD_CODES.getId(text);
if (escalationDelayType == -1)
throw new TranslatableJsonException("emport.error.invalid", "escalationDelayType", text, Common.TIME_PERIOD_CODES.getCodeList());
}
Integer i = jsonObject.getInt("escalationDelay", 1);
if (i != null)
escalationDelay = i;
JsonArray jsonEscalationRecipients = jsonObject.getJsonArray("escalationRecipients");
if (jsonEscalationRecipients != null)
escalationRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonEscalationRecipients);
b = jsonObject.getJsonBoolean("keepSendingEscalations");
if (b != null)
repeatEscalations = b.booleanValue();
}
b = jsonObject.getJsonBoolean("sendInactive");
if (b != null)
sendInactive = b.booleanValue();
if (sendInactive) {
b = jsonObject.getJsonBoolean("inactiveOverride");
if (b != null)
inactiveOverride = b.booleanValue();
if (inactiveOverride) {
JsonArray jsonInactiveRecipients = jsonObject.getJsonArray("inactiveRecipients");
if (jsonInactiveRecipients != null)
inactiveRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonInactiveRecipients);
}
}
b = jsonObject.getJsonBoolean("includeSystemInformation");
if (b != null)
includeSystemInfo = b.booleanValue();
includePointValueCount = jsonObject.getInt("includePointValueCount", 0);
b = jsonObject.getJsonBoolean("includeLogfile");
if (b != null)
includeSystemInfo = b.booleanValue();
customTemplate = jsonObject.getString("customTemplate");
JsonArray context = jsonObject.getJsonArray("additionalContext");
if (context != null) {
List<IntStringPair> additionalContext = new ArrayList<>();
for (JsonValue jv : context) {
JsonObject jo = jv.toJsonObject();
String dataPointXid = jo.getString("dataPointXid");
if (dataPointXid == null)
throw new TranslatableJsonException("emport.error.context.missing", "dataPointXid");
DataPointVO dpvo = DataPointDao.instance.getByXid(dataPointXid);
if (dpvo == null)
throw new TranslatableJsonException("emport.error.missingPoint", dataPointXid);
String contextKey = jo.getString("contextKey");
if (contextKey == null)
throw new TranslatableJsonException("emport.error.context.missing", "contextKey");
additionalContext.add(new IntStringPair(dpvo.getId(), contextKey));
}
this.additionalContext = additionalContext;
} else
this.additionalContext = new ArrayList<>();
script = jsonObject.getString("script");
JsonObject permissions = jsonObject.getJsonObject("scriptPermissions");
ScriptPermissions scriptPermissions = new ScriptPermissions();
if (permissions != null) {
String perm = permissions.getString(ScriptPermissions.DATA_SOURCE);
if (perm != null)
scriptPermissions.setDataSourcePermissions(perm);
perm = permissions.getString(ScriptPermissions.DATA_POINT_READ);
if (perm != null)
scriptPermissions.setDataPointReadPermissions(perm);
perm = permissions.getString(ScriptPermissions.DATA_POINT_SET);
if (perm != null)
scriptPermissions.setDataPointSetPermissions(perm);
}
this.scriptPermissions = scriptPermissions;
}
use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean 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.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;
}
}
}
Aggregations