Search in sources :

Example 1 with MailingList

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

the class M2MRecipientListEntryBean method createEmailRecipient.

public EmailRecipient createEmailRecipient() {
    switch(recipientType) {
        case EmailRecipient.TYPE_MAILING_LIST:
            MailingList ml = new MailingList();
            ml.setId(referenceId);
            return ml;
        case EmailRecipient.TYPE_USER:
            UserEntry u = new UserEntry();
            u.setUserId(referenceId);
            return u;
        case EmailRecipient.TYPE_ADDRESS:
            AddressEntry a = new AddressEntry();
            a.setAddress(referenceAddress);
            return a;
    }
    throw new ShouldNeverHappenException("Unknown email recipient type: " + recipientType);
}
Also used : AddressEntry(com.serotonin.m2m2.vo.mailingList.AddressEntry) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) UserEntry(com.serotonin.m2m2.vo.mailingList.UserEntry)

Example 2 with MailingList

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

the class MailingListRestController method get.

@ApiOperation(value = "Get Mailing List by XID", notes = "Returns a Mailing List")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/{xid}")
public ResponseEntity<MailingListModel> get(@ApiParam(value = "Valid mailing list xid", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
    RestProcessResult<MailingListModel> result = new RestProcessResult<MailingListModel>(HttpStatus.OK);
    this.checkUser(request, result);
    if (result.isOk()) {
        MailingList list = this.dao.getMailingList(xid);
        if (list != null) {
            MailingListModel model = new MailingListModel(list);
            return result.createResponseEntity(model);
        } else {
            result.addRestMessage(getDoesNotExistMessage());
        }
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) MailingListModel(com.serotonin.m2m2.web.mvc.rest.v1.model.email.MailingListModel) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with MailingList

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

the class MailingListRestController method getAll.

@ApiOperation(value = "Get Mailing List", notes = "Returns all Mailing Lists, eventually will be RQL endpoint")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" })
public ResponseEntity<List<MailingListModel>> getAll(HttpServletRequest request) {
    RestProcessResult<List<MailingListModel>> result = new RestProcessResult<List<MailingListModel>>(HttpStatus.OK);
    this.checkUser(request, result);
    if (result.isOk()) {
        List<MailingList> lists = this.dao.getMailingLists();
        if (lists != null) {
            List<MailingListModel> models = new ArrayList<MailingListModel>();
            for (MailingList list : lists) {
                models.add(new MailingListModel(list));
            }
            return result.createResponseEntity(models);
        } else {
            result.addRestMessage(getDoesNotExistMessage());
        }
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) List(java.util.List) MailingListModel(com.serotonin.m2m2.web.mvc.rest.v1.model.email.MailingListModel) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with MailingList

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

the class EventManagerImpl method raiseEvent.

// 
// 
// Basic event management.
// 
/**
 * Raise Event
 * @param type
 * @param time
 * @param rtnApplicable - does this event return to normal?
 * @param alarmLevel
 * @param message
 * @param context
 */
public void raiseEvent(EventType type, long time, boolean rtnApplicable, int alarmLevel, TranslatableMessage message, Map<String, Object> context) {
    if (state != RUNNING)
        return;
    if (alarmLevel == AlarmLevels.IGNORE)
        return;
    // Check if there is an event for this type already active.
    EventInstance dup = get(type);
    if (dup != null) {
        // Check the duplicate handling.
        boolean discard = canDiscard(type, message);
        if (discard)
            return;
    // Otherwise we just continue...
    } else if (!rtnApplicable) {
        // Check if we've already seen this type recently.
        boolean recent = isRecent(type, message);
        if (recent)
            return;
    }
    // Determine if the event should be suppressed.
    TranslatableMessage autoAckMessage = null;
    for (EventManagerListenerDefinition l : listeners) {
        autoAckMessage = l.autoAckEventWithMessage(type);
        if (autoAckMessage != null)
            break;
    }
    EventInstance evt = new EventInstance(type, time, rtnApplicable, alarmLevel, message, context);
    if (autoAckMessage == null)
        setHandlers(evt);
    // Check to see if we are Not Logging these
    if (alarmLevel != AlarmLevels.DO_NOT_LOG) {
        eventDao.saveEvent(evt);
    }
    // Create user alarm records for all applicable users
    List<Integer> eventUserIds = new ArrayList<Integer>();
    Set<String> emailUsers = new HashSet<String>();
    for (User user : userDao.getActiveUsers()) {
        // user should be skipped.
        if (type.excludeUser(user))
            continue;
        if (Permissions.hasEventTypePermission(user, type)) {
            eventUserIds.add(user.getId());
            if (user.getReceiveAlarmEmails() > AlarmLevels.IGNORE && alarmLevel >= user.getReceiveAlarmEmails() && !StringUtils.isEmpty(user.getEmail()))
                emailUsers.add(user.getEmail());
            // Notify All User Event Listeners of the new event
            if ((alarmLevel != AlarmLevels.DO_NOT_LOG) && (!evt.getEventType().getEventType().equals(EventType.EventTypeNames.AUDIT))) {
                for (UserEventListener l : this.userEventListeners) {
                    if (l.getUserId() == user.getId()) {
                        Common.backgroundProcessing.addWorkItem(new EventNotifyWorkItem(user, l, evt, true, false, false, false));
                    }
                }
                // Add to the UserEventCache if the user has recently accessed their events
                this.userEventCache.addEvent(user.getId(), evt);
            }
        }
    }
    DateTime now = new DateTime(Common.timer.currentTimeMillis());
    for (MailingList ml : MailingListDao.instance.getAlarmMailingLists(alarmLevel)) {
        ml.appendAddresses(emailUsers, now);
    }
    // No Audit or Do Not Log events are User Events
    if ((eventUserIds.size() > 0) && (alarmLevel != AlarmLevels.DO_NOT_LOG) && (!evt.getEventType().getEventType().equals(EventType.EventTypeNames.AUDIT))) {
        eventDao.insertUserEvents(evt.getId(), eventUserIds, true);
        if (autoAckMessage == null)
            lastAlarmTimestamp = Common.timer.currentTimeMillis();
    }
    if (evt.isRtnApplicable()) {
        activeEventsLock.writeLock().lock();
        try {
            activeEvents.add(evt);
        } finally {
            activeEventsLock.writeLock().unlock();
        }
    } else if (evt.getEventType().isRateLimited()) {
        recentEventsLock.writeLock().lock();
        try {
            recentEvents.add(evt);
        } finally {
            recentEventsLock.writeLock().unlock();
        }
    }
    if ((autoAckMessage != null) && (alarmLevel != AlarmLevels.DO_NOT_LOG) && (!evt.getEventType().getEventType().equals(EventType.EventTypeNames.AUDIT)))
        this.acknowledgeEvent(evt, time, null, autoAckMessage);
    else {
        if (evt.isRtnApplicable()) {
            if (alarmLevel > highestActiveAlarmLevel) {
                int oldValue = highestActiveAlarmLevel;
                highestActiveAlarmLevel = alarmLevel;
                SystemEventType.raiseEvent(new SystemEventType(SystemEventType.TYPE_MAX_ALARM_LEVEL_CHANGED), time, false, getAlarmLevelChangeMessage("event.alarmMaxIncreased", oldValue));
            }
        }
        // Call raiseEvent handlers.
        handleRaiseEvent(evt, emailUsers);
        if (log.isDebugEnabled())
            log.trace("Event raised: type=" + type + ", message=" + message.translate(Common.getTranslations()));
    }
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType) User(com.serotonin.m2m2.vo.User) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) DateTime(org.joda.time.DateTime) UserEventListener(com.serotonin.m2m2.rt.event.UserEventListener) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) EventManagerListenerDefinition(com.serotonin.m2m2.module.EventManagerListenerDefinition) HashSet(java.util.HashSet)

Example 5 with MailingList

use of com.serotonin.m2m2.vo.mailingList.MailingList 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;
}
Also used : EmailRecipient(com.serotonin.m2m2.vo.mailingList.EmailRecipient) User(com.serotonin.m2m2.vo.User) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) RecipientListEntryBean(com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)

Aggregations

MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)14 User (com.serotonin.m2m2.vo.User)5 EmailRecipient (com.serotonin.m2m2.vo.mailingList.EmailRecipient)4 ArrayList (java.util.ArrayList)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)3 RecipientListEntryBean (com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)3 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)3 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)2 AddressEntry (com.serotonin.m2m2.vo.mailingList.AddressEntry)2 UserEntry (com.serotonin.m2m2.vo.mailingList.UserEntry)2 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)2 MailingListModel (com.serotonin.m2m2.web.mvc.rest.v1.model.email.MailingListModel)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 HashSet (java.util.HashSet)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JsonException (com.serotonin.json.JsonException)1 MailingListDao (com.serotonin.m2m2.db.dao.MailingListDao)1 MangoEmailContent (com.serotonin.m2m2.email.MangoEmailContent)1