Search in sources :

Example 11 with EventInstance

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

the class EventExportServlet method exportCsv.

/**
 * @param response
 * @param def
 * @param user
 * @throws IOException
 */
private void exportCsv(HttpServletResponse response, EventExportDefinition def, User user) throws IOException {
    final Translations translations = Common.getTranslations();
    List<EventInstance> events = EventDao.instance.search(def.getEventId(), def.getEventType(), def.getStatus(), def.getAlarmLevel(), def.getKeywords(), def.getDateFrom(), def.getDateTo(), user.getId(), translations, 0, Integer.MAX_VALUE, null);
    // Stream the content.
    response.setContentType("text/csv");
    new EventCsvStreamer(response.getWriter(), events, translations);
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) EventCsvStreamer(com.serotonin.m2m2.vo.export.EventCsvStreamer) Translations(com.serotonin.m2m2.i18n.Translations)

Example 12 with EventInstance

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

the class EventInstanceDwr method acknowledgeEvents.

/**
 * Acknowledge all events from the current User Event Query
 * @return
 */
@DwrPermission(user = true)
public ProcessResult acknowledgeEvents() {
    ProcessResult response = new ProcessResult();
    final User user = Common.getHttpUser();
    if (user != null) {
        final long now = Common.timer.currentTimeMillis();
        final ResultSetCounter counter = new ResultSetCounter();
        QueryDefinition queryData = (QueryDefinition) user.getAttribute("eventInstanceExportDefinition");
        DojoQueryCallback<EventInstanceVO> callback = new DojoQueryCallback<EventInstanceVO>(false) {

            @Override
            public void row(EventInstanceVO vo, int rowIndex) {
                if (!vo.isAcknowledged()) {
                    EventInstance event = Common.eventManager.acknowledgeEventById(vo.getId(), now, user, null);
                    if (event != null && event.isAcknowledged()) {
                        counter.increment();
                    }
                }
            }
        };
        EventInstanceDao.instance.exportQuery(queryData.getQuery(), queryData.getSort(), null, null, queryData.isOr(), callback);
        resetLastAlarmLevelChange();
        response.addGenericMessage("events.acknowledgedEvents", counter.getCount());
    } else {
        response.addGenericMessage("events.acknowledgedEvents", 0);
    }
    return response;
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) User(com.serotonin.m2m2.vo.User) EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DojoQueryCallback(com.serotonin.m2m2.db.dao.DojoQueryCallback) ResultSetCounter(com.serotonin.m2m2.db.dao.ResultSetCounter) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 13 with EventInstance

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

the class BaseDwr method setEvents.

protected static void setEvents(DataPointVO pointVO, User user, Map<String, Object> model, int limit) {
    int userId = 0;
    if (user != null)
        userId = user.getId();
    List<EventInstance> userEvents = Common.eventManager.getAllActiveUserEvents(userId);
    // EVENT_DAO.getPendingEventsForDataPoint(pointVO.getId(), userId);
    // Fill the list in reverse order so the latest is first
    List<EventInstance> list = null;
    if (userEvents.size() > 0) {
        for (int i = userEvents.size() - 1; i >= 0; i--) {
            EventInstance e = userEvents.get(i);
            if (e.getEventType().getDataPointId() == pointVO.getId()) {
                if (list == null)
                    list = new ArrayList<EventInstance>();
                list.add(e);
                if (list.size() == limit)
                    break;
            }
        }
    }
    if (list != null) {
        model.put(MODEL_ATTR_EVENTS, list);
        for (EventInstance event : list) {
            if (!event.isAcknowledged()) {
                model.put(MODEL_ATTR_HAS_UNACKED_EVENT, true);
                break;
            }
        }
    }
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) ArrayList(java.util.ArrayList)

Example 14 with EventInstance

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

the class SetPointHandlerRT method eventInactive.

@Override
public void eventInactive(EventInstance evt) {
    if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_NONE)
        return;
    // Validate that the target point is available.
    DataPointRT targetPoint = Common.runtimeManager.getDataPoint(vo.getTargetPointId());
    if (targetPoint == null) {
        raiseFailureEvent(new TranslatableMessage("event.setPoint.targetPointMissing"), evt.getEventType());
        return;
    }
    if (!targetPoint.getPointLocator().isSettable()) {
        raiseFailureEvent(new TranslatableMessage("event.setPoint.targetNotSettable"), evt.getEventType());
        return;
    }
    int targetDataType = targetPoint.getVO().getPointLocator().getDataTypeId();
    DataValue value;
    if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_POINT_VALUE) {
        // Get the source data point.
        DataPointRT sourcePoint = Common.runtimeManager.getDataPoint(vo.getInactivePointId());
        if (sourcePoint == null) {
            raiseFailureEvent(new TranslatableMessage("event.setPoint.inactivePointMissing"), evt.getEventType());
            return;
        }
        PointValueTime valueTime = sourcePoint.getPointValue();
        if (valueTime == null) {
            raiseFailureEvent(new TranslatableMessage("event.setPoint.inactivePointValue"), evt.getEventType());
            return;
        }
        if (DataTypes.getDataType(valueTime.getValue()) != targetDataType) {
            raiseFailureEvent(new TranslatableMessage("event.setPoint.inactivePointDataType"), evt.getEventType());
            return;
        }
        value = valueTime.getValue();
    } else if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_STATIC_VALUE)
        value = DataValue.stringToValue(vo.getInactiveValueToSet(), targetDataType);
    else if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_SCRIPT_VALUE) {
        if (inactiveScript == null) {
            raiseFailureEvent(new TranslatableMessage("eventHandlers.invalidInactiveScript"), evt.getEventType());
            return;
        }
        Map<String, IDataPointValueSource> context = new HashMap<String, IDataPointValueSource>();
        context.put("target", targetPoint);
        try {
            PointValueTime pvt = CompiledScriptExecutor.execute(inactiveScript, context, new HashMap<String, Object>(), evt.getRtnTimestamp(), targetPoint.getDataTypeId(), evt.getRtnTimestamp(), vo.getScriptPermissions(), NULL_WRITER, new ScriptLog(NULL_WRITER, LogLevel.FATAL), setCallback, importExclusions, false);
            value = pvt.getValue();
        } catch (ScriptPermissionsException e) {
            raiseFailureEvent(e.getTranslatableMessage(), evt.getEventType());
            return;
        } catch (ScriptException e) {
            raiseFailureEvent(new TranslatableMessage("eventHandlers.invalidInactiveScriptError", e.getCause().getMessage()), evt.getEventType());
            return;
        } catch (ResultTypeException e) {
            raiseFailureEvent(new TranslatableMessage("eventHandlers.invalidInactiveScriptError", e.getMessage()), evt.getEventType());
            return;
        }
    } else
        throw new ShouldNeverHappenException("Unknown active action: " + vo.getInactiveAction());
    Common.backgroundProcessing.addWorkItem(new SetPointWorkItem(vo.getTargetPointId(), new PointValueTime(value, evt.getRtnTimestamp()), this));
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) HashMap(java.util.HashMap) SetPointWorkItem(com.serotonin.m2m2.rt.maint.work.SetPointWorkItem) ScriptLog(com.serotonin.m2m2.rt.script.ScriptLog) ScriptException(javax.script.ScriptException) ResultTypeException(com.serotonin.m2m2.rt.script.ResultTypeException) ScriptPermissionsException(com.serotonin.m2m2.rt.script.ScriptPermissionsException) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) IDataPointValueSource(com.serotonin.m2m2.rt.dataImage.IDataPointValueSource) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 15 with EventInstance

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

the class EmailHandlerRT method scheduleTimeout.

// 
// TimeoutClient
// 
public synchronized void scheduleTimeout(EventInstance evt, long fireTime) {
    // Get the email addresses to send to
    Set<String> addresses = MailingListDao.instance.getRecipientAddresses(vo.getEscalationRecipients(), new DateTime(fireTime));
    // Send the escalation.
    sendEmail(evt, NotificationType.ESCALATION, addresses);
    // have not been overridden.
    if (vo.isSendInactive() && !vo.isInactiveOverride())
        inactiveRecipients.addAll(addresses);
    if (vo.isRepeatEscalations()) {
        // While evt will probably show ack'ed if ack'ed, the possibility exists for it to be deleted
        // and in which case we want to notice rather than send emails forever.
        EventInstance dbEvent = EventDao.instance.get(evt.getId());
        if (dbEvent != null && !dbEvent.isAcknowledged() && dbEvent.isActive()) {
            long delayMS = Common.getMillis(vo.getEscalationDelayType(), vo.getEscalationDelay());
            escalationTask = new ModelTimeoutTask<EventInstance>(delayMS, this, dbEvent);
        }
    }
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) DateTime(org.joda.time.DateTime)

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