Search in sources :

Example 16 with EventInstance

use of com.serotonin.m2m2.rt.event.EventInstance in project ma-core-public by infiniteautomation.

the class EmailHandlerRT method eventRaised.

@Override
public void eventRaised(EventInstance evt) {
    // Get the email addresses to send to
    activeRecipients = MailingListDao.instance.getRecipientAddresses(vo.getActiveRecipients(), new DateTime(evt.getActiveTimestamp()));
    // Send an email to the active recipients.
    sendEmail(evt, NotificationType.ACTIVE, activeRecipients);
    // If an inactive notification is to be sent, save the active recipients.
    if (vo.isSendInactive()) {
        if (vo.isInactiveOverride())
            inactiveRecipients = MailingListDao.instance.getRecipientAddresses(vo.getInactiveRecipients(), new DateTime(evt.getActiveTimestamp()));
        else
            inactiveRecipients = activeRecipients;
    }
    // If an escalation is to be sent, set up timeout to trigger it.
    if (vo.isSendEscalation()) {
        long delayMS = Common.getMillis(vo.getEscalationDelayType(), vo.getEscalationDelay());
        escalationTask = new ModelTimeoutTask<EventInstance>(delayMS, this, evt);
    }
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) DateTime(org.joda.time.DateTime)

Example 17 with EventInstance

use of com.serotonin.m2m2.rt.event.EventInstance in project ma-modules-public by infiniteautomation.

the class UserEventsV2Controller method query.

@ApiOperation(value = "Query User Events", notes = "Query via rql in url against events for the current user", response = EventInstanceModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.GET, value = "")
public ResponseEntity<PageQueryResultModel<EventInstanceModel>> query(@AuthenticationPrincipal User user, HttpServletRequest request) {
    // Parse the RQL Query
    ASTNode query = parseRQLtoAST(request.getQueryString());
    List<EventInstance> results;
    List<EventInstance> events = Common.eventManager.getAllActiveUserEvents(user.getId());
    if (query != null)
        results = query.accept(new RQLToObjectListQuery<EventInstance>(), events);
    else
        results = events;
    List<EventInstanceModel> models = new ArrayList<>();
    // Convert to models
    for (EventInstance event : results) {
        models.add(new EventInstanceModel(event));
    }
    // Query the models
    return new ResponseEntity<>(new PageQueryResultModel<>(models, events.size()), HttpStatus.OK);
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) EventInstanceModel(com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventInstanceModel) ResponseEntity(org.springframework.http.ResponseEntity) ASTNode(net.jazdw.rql.parser.ASTNode) ArrayList(java.util.ArrayList) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with EventInstance

use of com.serotonin.m2m2.rt.event.EventInstance in project ma-modules-public by infiniteautomation.

the class ReportDao method getReportInstanceEvents.

public List<EventInstance> getReportInstanceEvents(int instanceId) {
    // Get the events.
    final List<EventInstance> events = query(EVENT_SELECT, new Object[] { instanceId }, new EventDao.EventInstanceRowMapper());
    // Add in the comments.
    ejt.query(EVENT_COMMENT_SELECT, new Object[] { instanceId, UserCommentVO.TYPE_EVENT }, new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            // Create the comment
            UserCommentVO c = new UserCommentVO();
            c.setUsername(rs.getString(1));
            c.setTs(rs.getLong(3));
            c.setComment(rs.getString(4));
            // Find the event and add the comment
            int eventId = rs.getInt(2);
            for (EventInstance event : events) {
                if (event.getId() == eventId) {
                    if (event.getEventComments() == null)
                        event.setEventComments(new ArrayList<UserCommentVO>());
                    event.addEventComment(c);
                }
            }
        }
    });
    // Done
    return events;
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) EventDao(com.serotonin.m2m2.db.dao.EventDao) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) UserCommentVO(com.serotonin.m2m2.vo.comment.UserCommentVO)

Example 19 with EventInstance

use of com.serotonin.m2m2.rt.event.EventInstance in project ma-modules-public by infiniteautomation.

the class ReportEventHandlerRT method eventRaised.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.rt.event.handlers.EventHandlerRT#eventRaised(com.serotonin.m2m2.rt.event.EventInstance)
	 */
@Override
public void eventRaised(EventInstance evt) {
    try {
        if (vo.getActiveReportId() != Common.NEW_ID) {
            // Schedule the Active Report To Run
            ReportVO report = ReportDao.instance.get(vo.getActiveReportId());
            if (report != null) {
                String host = InetAddress.getLocalHost().getHostName();
                int port = Common.envProps.getInt("web.port", 8080);
                ReportWorkItem.queueReport(host, port, report);
            }
        }
    } catch (UnknownHostException e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO)

Example 20 with EventInstance

use of com.serotonin.m2m2.rt.event.EventInstance in project ma-modules-public by infiniteautomation.

the class ReportEventHandlerRT method eventInactive.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.rt.event.handlers.EventHandlerRT#eventInactive(com.serotonin.m2m2.rt.event.EventInstance)
	 */
@Override
public void eventInactive(EventInstance evt) {
    try {
        if (vo.getInactiveReportId() != Common.NEW_ID) {
            // Schedule the Inactive Report to run
            ReportVO report = ReportDao.instance.get(vo.getInactiveReportId());
            if (report != null) {
                String host = InetAddress.getLocalHost().getHostName();
                int port = Common.envProps.getInt("web.port", 8080);
                ReportWorkItem.queueReport(host, port, report);
            }
        }
    } catch (UnknownHostException e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO)

Aggregations

EventInstance (com.serotonin.m2m2.rt.event.EventInstance)30 ArrayList (java.util.ArrayList)14 User (com.serotonin.m2m2.vo.User)12 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)7 HashMap (java.util.HashMap)7 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)6 EventDao (com.serotonin.m2m2.db.dao.EventDao)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 UserEventListener (com.serotonin.m2m2.rt.event.UserEventListener)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 Translations (com.serotonin.m2m2.i18n.Translations)3 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)3 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)3 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)3 ResultTypeException (com.serotonin.m2m2.rt.script.ResultTypeException)3 ScriptLog (com.serotonin.m2m2.rt.script.ScriptLog)3 ScriptPermissionsException (com.serotonin.m2m2.rt.script.ScriptPermissionsException)3 EventInstanceBean (com.serotonin.m2m2.web.dwr.beans.EventInstanceBean)3 ScriptException (javax.script.ScriptException)3