Search in sources :

Example 1 with PhoneEntry

use of com.serotonin.m2m2.vo.mailingList.PhoneEntry 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;
        }
    }
}
Also used : User(com.serotonin.m2m2.vo.User) AddressEntry(com.serotonin.m2m2.vo.mailingList.AddressEntry) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) UserPhoneEntry(com.serotonin.m2m2.vo.mailingList.UserPhoneEntry) UserEntry(com.serotonin.m2m2.vo.mailingList.UserEntry) UserPhoneEntry(com.serotonin.m2m2.vo.mailingList.UserPhoneEntry) PhoneEntry(com.serotonin.m2m2.vo.mailingList.PhoneEntry) HashSet(java.util.HashSet)

Example 2 with PhoneEntry

use of com.serotonin.m2m2.vo.mailingList.PhoneEntry in project ma-core-public by infiniteautomation.

the class MailingListDao method getRecipientType.

private MailingListRecipient getRecipientType(Record record) {
    int intType = record.get(mailingListMembersTable.typeId);
    RecipientListEntryType type = RecipientListEntryType.fromValue(intType);
    Integer userId = record.get(mailingListMembersTable.userId);
    switch(type) {
        case ADDRESS:
            AddressEntry ae = new AddressEntry();
            ae.setAddress(record.get(mailingListMembersTable.address));
            return ae;
        case MAILING_LIST:
            MailingListEntry ml = new MailingListEntry();
            ml.setMailingListId(userId != null ? userId : 0);
            return ml;
        case PHONE_NUMBER:
            PhoneEntry pe = new PhoneEntry();
            pe.setPhone(record.get(mailingListMembersTable.address));
            return pe;
        case USER:
        case USER_PHONE_NUMBER:
            UserEntry ue = new UserEntry();
            ue.setUserId(userId != null ? userId : 0);
            return ue;
        default:
            throw new ShouldNeverHappenException("Unknown mailing list entry type: " + intType);
    }
}
Also used : MailingListEntry(com.serotonin.m2m2.vo.mailingList.MailingListEntry) AddressEntry(com.serotonin.m2m2.vo.mailingList.AddressEntry) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) RecipientListEntryType(com.serotonin.m2m2.vo.mailingList.RecipientListEntryType) UserEntry(com.serotonin.m2m2.vo.mailingList.UserEntry) PhoneEntry(com.serotonin.m2m2.vo.mailingList.PhoneEntry)

Example 3 with PhoneEntry

use of com.serotonin.m2m2.vo.mailingList.PhoneEntry in project ma-modules-public by infiniteautomation.

the class PhoneEntryModel method fromModel.

@Override
public MailingListRecipient fromModel() {
    PhoneEntry entry = new PhoneEntry();
    entry.setPhone(phone);
    return entry;
}
Also used : PhoneEntry(com.serotonin.m2m2.vo.mailingList.PhoneEntry)

Example 4 with PhoneEntry

use of com.serotonin.m2m2.vo.mailingList.PhoneEntry 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);
    }
}
Also used : MailingListEntry(com.serotonin.m2m2.vo.mailingList.MailingListEntry) AddressEntry(com.serotonin.m2m2.vo.mailingList.AddressEntry) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) RecipientListEntryType(com.serotonin.m2m2.vo.mailingList.RecipientListEntryType) UserEntry(com.serotonin.m2m2.vo.mailingList.UserEntry) PhoneEntry(com.serotonin.m2m2.vo.mailingList.PhoneEntry)

Aggregations

PhoneEntry (com.serotonin.m2m2.vo.mailingList.PhoneEntry)4 AddressEntry (com.serotonin.m2m2.vo.mailingList.AddressEntry)3 UserEntry (com.serotonin.m2m2.vo.mailingList.UserEntry)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 MailingListEntry (com.serotonin.m2m2.vo.mailingList.MailingListEntry)2 RecipientListEntryType (com.serotonin.m2m2.vo.mailingList.RecipientListEntryType)2 User (com.serotonin.m2m2.vo.User)1 MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)1 UserPhoneEntry (com.serotonin.m2m2.vo.mailingList.UserPhoneEntry)1 HashSet (java.util.HashSet)1