use of com.serotonin.m2m2.vo.mailingList.MailingListRecipient in project ma-core-public by infiniteautomation.
the class MailingListService method validateRecipient.
/**
* For internal use to validate a mailing list
*/
protected void validateRecipient(MailingList list, String prefix, MailingListRecipient recipient, ProcessResult result, RecipientListEntryType... acceptableTypes) {
if (!ArrayUtils.contains(acceptableTypes, recipient.getRecipientType())) {
result.addContextualMessage(prefix + ".recipientType", "mailingLists.validate.invalidEntryType", recipient.getRecipientType(), acceptableTypes);
} else {
switch(recipient.getRecipientType()) {
case ADDRESS:
AddressEntry ee = (AddressEntry) recipient;
if (StringUtils.isBlank(ee.getAddress())) {
result.addContextualMessage(prefix, "validate.required");
}
break;
case MAILING_LIST:
// If a mailing list then make sure it exists and there are no circular references
MailingList sublist = dao.get(recipient.getReferenceId());
if (sublist == null) {
result.addContextualMessage(prefix, "mailingLists.validate.listDoesNotExist");
} else {
Set<Integer> listIds = new HashSet<>();
if (list != null) {
listIds.add(list.getId());
}
// Check to see if the top level recipient is the same as me
if (!listIds.add(sublist.getId())) {
result.addContextualMessage(prefix, "mailingLists.validate.listCannotContainItself");
return;
}
recursivelyCheckMailingListEntries(listIds, sublist, prefix, result);
}
break;
case PHONE_NUMBER:
PhoneEntry pe = (PhoneEntry) recipient;
if (StringUtils.isBlank(pe.getPhone())) {
result.addContextualMessage(prefix, "validate.required");
}
break;
case USER:
UserEntry ue = (UserEntry) recipient;
if (userDao.getXidById(ue.getUserId()) == null) {
result.addContextualMessage(prefix, "mailingLists.validate.userDoesNotExist");
}
break;
case USER_PHONE_NUMBER:
UserPhoneEntry up = (UserPhoneEntry) recipient;
User userWithPhone = userDao.get(up.getUserId());
if (userWithPhone == null) {
result.addContextualMessage(prefix, "mailingLists.validate.userDoesNotExist");
} else if (StringUtils.isBlank(userWithPhone.getPhone())) {
result.addContextualMessage(prefix, "mailingLists.validate.userDoesNotHavePhoneNumber");
}
break;
default:
break;
}
}
}
use of com.serotonin.m2m2.vo.mailingList.MailingListRecipient in project ma-core-public by infiniteautomation.
the class MailingListService method commonValidation.
/**
* Common validation logic for insert/update of Mailing lists
*/
protected ProcessResult commonValidation(MailingList vo) {
ProcessResult result = super.validate(vo);
if (vo.getReceiveAlarmEmails() == null) {
result.addContextualMessage("receiveAlarmEmails", "validate.invalidValue");
}
if (vo.getEntries() == null || vo.getEntries().size() == 0) {
result.addContextualMessage("recipients", "mailingLists.validate.entries");
} else {
int index = 0;
for (MailingListRecipient recipient : vo.getEntries()) {
validateRecipient(vo, "recipients[" + index + "]", recipient, result, RecipientListEntryType.values());
index++;
}
}
if (vo.getInactiveIntervals() != null) {
if (vo.getInactiveIntervals().size() > 672)
result.addContextualMessage("inactiveSchedule", "validate.invalidValue");
}
return result;
}
use of com.serotonin.m2m2.vo.mailingList.MailingListRecipient in project ma-core-public by infiniteautomation.
the class MailingListService method recursivelyCheckMailingListEntries.
/**
*/
private void recursivelyCheckMailingListEntries(Set<Integer> listIds, MailingList list, String prefix, ProcessResult result) {
for (MailingListRecipient recipient : list.getEntries()) {
switch(recipient.getRecipientType()) {
case MAILING_LIST:
if (!listIds.add(recipient.getReferenceId())) {
// Failed, we already have this list as reference
result.addContextualMessage(prefix, "mailingLists.validate.listCannotContainItself");
return;
} else {
MailingList sublist = dao.get(recipient.getReferenceId());
recursivelyCheckMailingListEntries(listIds, sublist, prefix, result);
}
break;
default:
break;
}
}
}
use of com.serotonin.m2m2.vo.mailingList.MailingListRecipient in project ma-core-public by infiniteautomation.
the class EmailHandlerRTTest method testSendInactive.
@Test
public void testSendInactive() {
EmailEventHandlerVO vo = createVO();
List<MailingListRecipient> activeRecipients = createRecipients();
vo.setActiveRecipients(activeRecipients);
vo.setSendInactive(true);
List<MailingListRecipient> inactiveRecipients = createRecipients();
vo.setInactiveRecipients(inactiveRecipients);
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(1, scheduledItems.size());
}
use of com.serotonin.m2m2.vo.mailingList.MailingListRecipient in project ma-core-public by infiniteautomation.
the class EmailHandlerRTTest method testSendActiveInactive.
@Test
public void testSendActiveInactive() {
EmailEventHandlerVO vo = createVO();
vo.setSendInactive(true);
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(1, scheduledItems.size());
}
Aggregations