use of com.serotonin.m2m2.vo.mailingList.MailingListRecipient in project ma-core-public by infiniteautomation.
the class EmailHandlerRTTest method testSendActive.
@Test
public void testSendActive() {
EmailEventHandlerVO vo = createVO();
List<MailingListRecipient> activeRecipients = createRecipients();
vo.setActiveRecipients(activeRecipients);
EmailHandlerRT rt = new EmailHandlerRT(vo);
EventInstance evt = createDataPointEventInstance();
rt.eventRaised(evt);
// Ensure there is one scheduled
assertEquals(1, scheduledItems.size());
scheduledItems.clear();
// Make Inactive
evt.returnToNormal(this.timer.currentTimeMillis(), ReturnCause.RETURN_TO_NORMAL);
rt.eventInactive(evt);
assertEquals(0, scheduledItems.size());
}
use of com.serotonin.m2m2.vo.mailingList.MailingListRecipient in project ma-core-public by infiniteautomation.
the class EmailEventHandlerVO method readObject.
@SuppressWarnings({ "unchecked", "deprecation" })
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
// NOTE: after deserialization the recipient lists need to be cleaned of deleted references,
// See MailingListDao.cleanRecipientsList. This happens in the DAO
int ver = in.readInt();
subject = SUBJECT_INCLUDE_EVENT_MESSAGE;
if (ver == 1) {
List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
activeRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
activeRecipients.add(b.createEmailRecipient());
}
}
sendEscalation = in.readBoolean();
repeatEscalations = false;
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
escalationRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
escalationRecipients.add(b.createEmailRecipient());
}
}
sendInactive = in.readBoolean();
inactiveOverride = in.readBoolean();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
inactiveRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
inactiveRecipients.add(b.createEmailRecipient());
}
}
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = null;
additionalContext = new ArrayList<IntStringPair>();
scriptRoles = new ScriptPermissions();
script = null;
} else if (ver == 2) {
List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
activeRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
activeRecipients.add(b.createEmailRecipient());
}
}
sendEscalation = in.readBoolean();
repeatEscalations = false;
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
escalationRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
escalationRecipients.add(b.createEmailRecipient());
}
}
sendInactive = in.readBoolean();
inactiveOverride = in.readBoolean();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
inactiveRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
inactiveRecipients.add(b.createEmailRecipient());
}
}
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = SerializationHelper.readSafeUTF(in);
additionalContext = new ArrayList<IntStringPair>();
scriptRoles = new ScriptPermissions();
script = null;
} else if (ver == 3) {
List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
activeRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
activeRecipients.add(b.createEmailRecipient());
}
}
sendEscalation = in.readBoolean();
repeatEscalations = false;
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
escalationRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
escalationRecipients.add(b.createEmailRecipient());
}
}
sendInactive = in.readBoolean();
inactiveOverride = in.readBoolean();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
inactiveRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
inactiveRecipients.add(b.createEmailRecipient());
}
}
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = SerializationHelper.readSafeUTF(in);
additionalContext = (List<IntStringPair>) in.readObject();
scriptRoles = new ScriptPermissions();
script = null;
} else if (ver == 4) {
List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
activeRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
activeRecipients.add(b.createEmailRecipient());
}
}
sendEscalation = in.readBoolean();
repeatEscalations = false;
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
escalationRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
escalationRecipients.add(b.createEmailRecipient());
}
}
sendInactive = in.readBoolean();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
inactiveRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
inactiveRecipients.add(b.createEmailRecipient());
}
}
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = SerializationHelper.readSafeUTF(in);
additionalContext = (List<IntStringPair>) in.readObject();
com.serotonin.m2m2.rt.script.ScriptPermissions oldPermissions = (com.serotonin.m2m2.rt.script.ScriptPermissions) in.readObject();
if (oldPermissions != null) {
// We will be using this in the upgrade so this is temporary and will be used to set
// the scriptRoles
legacyScriptRoles = oldPermissions.getAllLegacyPermissions();
legacyPermissionHolderName = oldPermissions.getPermissionHolderName();
} else {
scriptRoles = new ScriptPermissions();
}
script = SerializationHelper.readSafeUTF(in);
} else if (ver == 5) {
List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
activeRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
activeRecipients.add(b.createEmailRecipient());
}
}
sendEscalation = in.readBoolean();
repeatEscalations = in.readBoolean();
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
escalationRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
escalationRecipients.add(b.createEmailRecipient());
}
}
sendInactive = in.readBoolean();
inactiveOverride = in.readBoolean();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
inactiveRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
inactiveRecipients.add(b.createEmailRecipient());
}
}
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = SerializationHelper.readSafeUTF(in);
additionalContext = (List<IntStringPair>) in.readObject();
com.serotonin.m2m2.rt.script.ScriptPermissions oldPermissions = (com.serotonin.m2m2.rt.script.ScriptPermissions) in.readObject();
if (oldPermissions != null) {
// We will be using this in the upgrade so this is temporary and will be used to set
// the scriptRoles
legacyScriptRoles = oldPermissions.getAllLegacyPermissions();
legacyPermissionHolderName = oldPermissions.getPermissionHolderName();
} else {
scriptRoles = new ScriptPermissions();
}
script = SerializationHelper.readSafeUTF(in);
} else if (ver == 6) {
List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
activeRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
activeRecipients.add(b.createEmailRecipient());
}
}
sendEscalation = in.readBoolean();
repeatEscalations = in.readBoolean();
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
escalationRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
escalationRecipients.add(b.createEmailRecipient());
}
}
sendInactive = in.readBoolean();
inactiveOverride = in.readBoolean();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
inactiveRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
inactiveRecipients.add(b.createEmailRecipient());
}
}
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = SerializationHelper.readSafeUTF(in);
additionalContext = (List<IntStringPair>) in.readObject();
scriptRoles = (ScriptPermissions) in.readObject();
script = SerializationHelper.readSafeUTF(in);
} else if (ver == 7) {
List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
activeRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
activeRecipients.add(b.createEmailRecipient());
}
}
sendEscalation = in.readBoolean();
repeatEscalations = in.readBoolean();
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
escalationRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
escalationRecipients.add(b.createEmailRecipient());
}
}
sendInactive = in.readBoolean();
inactiveOverride = in.readBoolean();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
inactiveRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
inactiveRecipients.add(b.createEmailRecipient());
}
}
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = SerializationHelper.readSafeUTF(in);
additionalContext = (List<IntStringPair>) in.readObject();
scriptRoles = (ScriptPermissions) in.readObject();
script = SerializationHelper.readSafeUTF(in);
subject = in.readInt();
} else if (ver == 8) {
activeRecipients = (List<MailingListRecipient>) in.readObject();
sendEscalation = in.readBoolean();
repeatEscalations = in.readBoolean();
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
escalationRecipients = (List<MailingListRecipient>) in.readObject();
sendInactive = in.readBoolean();
inactiveOverride = in.readBoolean();
inactiveRecipients = (List<MailingListRecipient>) in.readObject();
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = SerializationHelper.readSafeUTF(in);
additionalContext = (List<IntStringPair>) in.readObject();
scriptRoles = (ScriptPermissions) in.readObject();
script = SerializationHelper.readSafeUTF(in);
subject = in.readInt();
}
}
use of com.serotonin.m2m2.vo.mailingList.MailingListRecipient in project ma-core-public by infiniteautomation.
the class RecipientListEntryBean method createEmailRecipient.
/**
* Convert to mailing list recipient
*/
public MailingListRecipient createEmailRecipient() {
RecipientListEntryType type = RecipientListEntryType.fromValue(recipientType);
switch(type) {
case ADDRESS:
AddressEntry a = new AddressEntry();
a.setAddress(referenceAddress);
return a;
case MAILING_LIST:
MailingListEntry ml = new MailingListEntry();
ml.setMailingListId(referenceId);
return ml;
case PHONE_NUMBER:
PhoneEntry pe = new PhoneEntry();
pe.setPhone(referenceAddress);
return pe;
case USER:
UserEntry u = new UserEntry();
u.setUserId(referenceId);
return u;
case USER_PHONE_NUMBER:
PhoneEntry p = new PhoneEntry();
p.setPhone(referenceAddress);
return p;
default:
throw new ShouldNeverHappenException("Unknown recipient type: " + recipientType);
}
}
use of com.serotonin.m2m2.vo.mailingList.MailingListRecipient in project ma-core-public by infiniteautomation.
the class MailingListService method getActiveRecipients.
/**
* Get a list of all active recipients for the desired types of entries while also
* populating the entries of the list.
*/
public Set<String> getActiveRecipients(List<MailingListRecipient> recipients, long sendTime, RecipientListEntryType... types) {
PermissionHolder user = Common.getUser();
this.permissionService.ensureAdminRole(user);
Set<String> addresses = new HashSet<String>();
for (MailingListRecipient r : recipients) {
if (ArrayUtils.contains(types, r.getRecipientType())) {
switch(r.getRecipientType()) {
case ADDRESS:
addresses.add(r.getReferenceAddress());
break;
case MAILING_LIST:
// Reload this whole guy as he may have been serialized or changed
MailingList list = dao.get(r.getReferenceId());
if (list != null) {
if (!list.getInactiveIntervals().contains(MailingListUtility.getIntervalIdAt(sendTime))) {
Set<String> activeFromList = getActiveRecipients(list.getEntries(), sendTime, types);
addresses.addAll(activeFromList);
}
}
break;
case PHONE_NUMBER:
addresses.add(r.getReferenceAddress());
break;
case USER:
User u = userDao.get(r.getReferenceId());
if (u == null || u.isDisabled()) {
break;
} else {
addresses.add(u.getEmail());
}
break;
case USER_PHONE_NUMBER:
User up = userDao.get(r.getReferenceId());
if (up == null || up.isDisabled()) {
break;
} else {
addresses.add(up.getPhone());
}
break;
default:
break;
}
}
}
return addresses;
}
use of com.serotonin.m2m2.vo.mailingList.MailingListRecipient in project ma-core-public by infiniteautomation.
the class MailingListDao method saveRelationalData.
@Override
public void saveRelationalData(MailingList existing, MailingList ml) {
// Delete existing entries
if (existing != null) {
create.deleteFrom(mailingListInactiveTable).where(mailingListInactiveTable.mailingListId.eq(ml.getId())).execute();
create.deleteFrom(mailingListMembersTable).where(mailingListMembersTable.mailingListId.eq(ml.getId())).execute();
}
// Save relational data
Set<Integer> inactiveIntervals = ml.getInactiveIntervals();
if (inactiveIntervals.size() > 0) {
BatchBindStep batchInactive = create.batch(create.insertInto(mailingListInactiveTable).columns(mailingListInactiveTable.mailingListId, mailingListInactiveTable.inactiveInterval).values((Integer) null, null));
for (Integer interval : inactiveIntervals) batchInactive.bind(ml.getId(), interval);
batchInactive.execute();
}
List<MailingListRecipient> entries = ml.getEntries();
if (entries.size() > 0) {
BatchBindStep batchMembers = create.batch(create.insertInto(mailingListMembersTable).columns(mailingListMembersTable.mailingListId, mailingListMembersTable.typeId, mailingListMembersTable.userId, mailingListMembersTable.address).values((Integer) null, null, null, null));
for (MailingListRecipient r : entries) batchMembers.bind(ml.getId(), r.getRecipientType().value(), r.getReferenceId(), r.getReferenceAddress());
batchMembers.execute();
}
if (existing != null) {
if (!existing.getReadPermission().equals(ml.getReadPermission())) {
permissionService.deletePermissions(existing.getReadPermission());
}
if (!existing.getEditPermission().equals(ml.getEditPermission())) {
permissionService.deletePermissions(existing.getEditPermission());
}
}
}
Aggregations