diff --git a/src/br/org/scadabr/rt/scripting/context/DPCommandsScriptContextObject.java b/src/br/org/scadabr/rt/scripting/context/DPCommandsScriptContextObject.java index 9f6a809746..57c1059d95 100644 --- a/src/br/org/scadabr/rt/scripting/context/DPCommandsScriptContextObject.java +++ b/src/br/org/scadabr/rt/scripting/context/DPCommandsScriptContextObject.java @@ -9,15 +9,15 @@ import org.apache.commons.logging.LogFactory; import com.serotonin.mango.Common; -import com.serotonin.mango.db.dao.DataPointDao; import com.serotonin.mango.rt.RuntimeManager; import com.serotonin.mango.rt.dataImage.types.MangoValue; import com.serotonin.mango.vo.permission.Permissions; import org.mozilla.javascript.NativeObject; +import org.scada_lts.mango.service.DataPointService; public class DPCommandsScriptContextObject extends ScriptContextObject { public static final Type TYPE = Type.DATAPOINT_COMMANDS; - private Log LOG = LogFactory.getLog(DPCommandsScriptContextObject.class); + private static final Log LOG = LogFactory.getLog(DPCommandsScriptContextObject.class); @Override public Type getType() { @@ -25,7 +25,7 @@ public Type getType() { } public void writeDataPoint(String xid, String stringValue) { - DataPointVO dataPoint = new DataPointDao().getDataPoint(xid); + DataPointVO dataPoint = new DataPointService().getDataPoint(xid); if (dataPoint != null) { Permissions.ensureDataPointSetPermission(user, dataPoint); RuntimeManager runtimeManager = Common.ctx.getRuntimeManager(); @@ -39,27 +39,33 @@ public void writeDataPoint(String xid, String stringValue) { } catch (Exception e) { LOG.debug("Error while setting point - " + e.getMessage()); } + } else { + logWarn(xid); } } public void enableDataPoint(String xid) { - DataPointVO dataPoint = new DataPointDao().getDataPoint(xid); + DataPointVO dataPoint = new DataPointService().getDataPoint(xid); if (dataPoint != null) { Permissions.ensureDataPointReadPermission(user, dataPoint); RuntimeManager runtimeManager = Common.ctx.getRuntimeManager(); dataPoint.setEnabled(true); runtimeManager.saveDataPoint(dataPoint); + } else { + logWarn(xid); } } public void disableDataPoint(String xid) { - DataPointVO dataPoint = new DataPointDao().getDataPoint(xid); + DataPointVO dataPoint = new DataPointService().getDataPoint(xid); if (dataPoint != null) { Permissions.ensureDataPointReadPermission(user, dataPoint); RuntimeManager runtimeManager = Common.ctx.getRuntimeManager(); dataPoint.setEnabled(false); runtimeManager.saveDataPoint(dataPoint); + } else { + logWarn(xid); } } @@ -137,12 +143,18 @@ public void setDefaultCacheSize(String xid, int defaultCacheSize) { } private void updateDataPoint(String xid, DataPointUpdate dataPointUpdate) { - DataPointVO dataPoint = new DataPointDao().getDataPoint(xid); + DataPointVO dataPoint = new DataPointService().getDataPoint(xid); if (dataPoint != null) { Permissions.ensureDataPointUpdatePermission(user, dataPoint); RuntimeManager runtimeManager = Common.ctx.getRuntimeManager(); dataPointUpdate.updateDataPoint(dataPoint); runtimeManager.saveDataPoint(dataPoint); + } else { + logWarn(xid); } } + + private static void logWarn(String xid) { + LOG.warn("Not exist data point with xid: " + xid); + } } diff --git a/src/com/serotonin/mango/MangoContextListener.java b/src/com/serotonin/mango/MangoContextListener.java index 60dde9c580..c84b9d35cd 100644 --- a/src/com/serotonin/mango/MangoContextListener.java +++ b/src/com/serotonin/mango/MangoContextListener.java @@ -140,8 +140,8 @@ private void initialized(ServletContextEvent evt) { new SystemSettingsDAO().setValue( SystemSettingsDAO.SERVLET_CONTEXT_PATH, ctx.getContextPath()); - utilitiesInitialize(ctx); eventManagerInitialize(ctx); + utilitiesInitialize(ctx); try { ApplicationBeans.getPointEventDetectorDaoBean().init(); diff --git a/src/com/serotonin/mango/rt/EventManager.java b/src/com/serotonin/mango/rt/EventManager.java index a7afda10bd..3546a3fa73 100644 --- a/src/com/serotonin/mango/rt/EventManager.java +++ b/src/com/serotonin/mango/rt/EventManager.java @@ -187,7 +187,7 @@ public void raiseEvent(EventType type, long time, boolean rtnApplicable, time, false, getAlarmLevelChangeMessage( - "event.alarmMaxIncreased", oldValue)); + "event.alarmMaxIncreased", oldValue, alarmLevel)); } } @@ -234,11 +234,6 @@ private void deactivateEvent(EventInstance evt, long time, int inactiveCause) { // Call inactiveEvent handlers. handleInactiveEvent(evt); } - - @Deprecated - public long getLastAlarmTimestamp() { - return lastAlarmTimestamp; - } public void setLastAlarmTimestamp(long alarmTimestamp) { this.lastAlarmTimestamp = alarmTimestamp; @@ -273,6 +268,14 @@ public void cancelEventsForPublisher(int publisherId) { } } + public void cancelEventsForHandler(int handlerId) { + for (EventInstance e : activeEvents) { + if (e.getEventType().getEventHandlerId() == handlerId) + deactivateEvent(e, System.currentTimeMillis(), + EventInstance.RtnCauses.SOURCE_DISABLED); + } + } + private void resetHighestAlarmLevel(long time, boolean init) { int max = 0; for (EventInstance e : activeEvents) { @@ -290,7 +293,7 @@ private void resetHighestAlarmLevel(long time, boolean init) { time, false, getAlarmLevelChangeMessage("event.alarmMaxIncreased", - oldValue)); + oldValue, max)); } else if (max < highestActiveAlarmLevel) { int oldValue = highestActiveAlarmLevel; highestActiveAlarmLevel = max; @@ -300,16 +303,16 @@ private void resetHighestAlarmLevel(long time, boolean init) { time, false, getAlarmLevelChangeMessage("event.alarmMaxDecreased", - oldValue)); + oldValue, max)); } } } private LocalizableMessage getAlarmLevelChangeMessage(String key, - int oldValue) { + int oldValue, int newValue) { return new LocalizableMessage(key, AlarmLevels.getAlarmLevelMessage(oldValue), - AlarmLevels.getAlarmLevelMessage(highestActiveAlarmLevel)); + AlarmLevels.getAlarmLevelMessage(newValue)); } // @@ -398,11 +401,6 @@ private void setHandlers(EventInstance evt) { evt.setHandlers(rts); } - @Deprecated - public void handleRaiseEvent(EventInstance evt) { - handleRaiseEvent(evt, Collections.emptySet()); - } - private void handleRaiseEvent(EventInstance evt, Set defaultAddresses) { if (evt.getHandlers() != null) { @@ -500,14 +498,6 @@ public void notifyEventToggle(EventInstance evt, User user) { NotifyEventUtils.notifyEventToggle(highestAlarmLevelService, evt, user, userEventServiceWebSocket); } - @Deprecated - public void notifyEventToggle(int eventId, User user) { - if(eventId != Common.NEW_ID) { - EventInstance evt = eventService.getEvent(eventId); - notifyEventToggle(evt, user); - } - } - public void notifyEventToggle(int eventId, int userId) { if(eventId != Common.NEW_ID) { EventInstance evt = eventService.getEvent(eventId); @@ -520,11 +510,6 @@ public void notifyEventUpdate(User user, WsEventMessage message) { NotifyEventUtils.notifyEventUpdate(user, message, userEventServiceWebSocket); } - @Deprecated - public void notifyEventReset() { - NotifyEventUtils.notifyEventReset(userService, userEventServiceWebSocket); - } - @Override public void notifyWebSocketSubscribers(String message) { eventsServiceWebSocket.notifyEventsSubscribers(message); diff --git a/src/com/serotonin/mango/rt/event/handlers/EmailHandlerRT.java b/src/com/serotonin/mango/rt/event/handlers/EmailHandlerRT.java index f07aa662e4..558c3e66c4 100644 --- a/src/com/serotonin/mango/rt/event/handlers/EmailHandlerRT.java +++ b/src/com/serotonin/mango/rt/event/handlers/EmailHandlerRT.java @@ -21,6 +21,7 @@ import com.serotonin.mango.Common; import com.serotonin.mango.db.dao.MailingListDao; import com.serotonin.mango.rt.event.EventInstance; +import com.serotonin.mango.rt.event.type.SystemEventType; import com.serotonin.mango.rt.maint.work.AfterWork; import com.serotonin.mango.util.MsgContentUtils; import com.serotonin.mango.util.timeout.ModelTimeoutClient; @@ -28,6 +29,7 @@ import com.serotonin.mango.vo.event.EventHandlerVO; import com.serotonin.mango.web.email.IMsgSubjectContent; import com.serotonin.timer.TimerTask; +import com.serotonin.web.i18n.LocalizableMessage; import freemarker.template.TemplateException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -87,21 +89,20 @@ public IMsgSubjectContent createContent(EventInstance evt, String alias) throws private Set inactiveRecipients; public EmailHandlerRT(EventHandlerVO vo) { - this.vo = vo; - this.service = ScheduledExecuteInactiveEventService.getInstance(); - this.mailingListService = new MailingListService(); + this(vo, SystemEventType.duplicateIgnoreEventType(SystemEventType.TYPE_EMAIL_SEND_FAILURE, vo.getId())); } - public EmailHandlerRT(EventHandlerVO vo, MailingListService mailingListService) { - this.vo = vo; + protected EmailHandlerRT(EventHandlerVO vo, SystemEventType systemEventType) { + super(vo, systemEventType); this.service = ScheduledExecuteInactiveEventService.getInstance(); - this.mailingListService = mailingListService; + this.mailingListService = new MailingListService(); } - public EmailHandlerRT(EventHandlerVO vo, - ScheduledExecuteInactiveEventService service, - MailingListService mailingListService) { - this.vo = vo; + protected EmailHandlerRT(EventHandlerVO vo, + ScheduledExecuteInactiveEventService service, + MailingListService mailingListService, + SystemEventType systemEventType) { + super(vo, systemEventType); this.service = service; this.mailingListService = mailingListService; } @@ -200,8 +201,17 @@ private void sendEmail(EventInstance evt, NotificationType notificationType, Set sendMsg(evt, notificationType, addresses, vo.getAlias(), new AfterWork() { @Override public void workFail(Throwable exception) { - LOG.error("Failed sending email for " + eventHandlerInfo(getVo()) + ", " + eventInfo(evt) - + ", error: " + exception.getMessage()); + String msg = "Failed sending email for " + eventHandlerInfo(getVo()) + ", " + eventInfo(evt) + + ", error: " + exception.getMessage(); + LOG.error(msg); + LocalizableMessage message = new LocalizableMessage("event.email.failure", + vo.getAlias(), addresses, msg); + SystemEventType.raiseEvent(getEventType(), System.currentTimeMillis(), true, message); + } + + @Override + public void workSuccess() { + SystemEventType.returnToNormal(getEventType(), System.currentTimeMillis()); } }, () -> eventHandlerInfo(getVo()) + ", " + eventInfo(evt)); } diff --git a/src/com/serotonin/mango/rt/event/handlers/EmailToSmsHandlerRT.java b/src/com/serotonin/mango/rt/event/handlers/EmailToSmsHandlerRT.java index 97205c1732..a7c2729457 100644 --- a/src/com/serotonin/mango/rt/event/handlers/EmailToSmsHandlerRT.java +++ b/src/com/serotonin/mango/rt/event/handlers/EmailToSmsHandlerRT.java @@ -1,10 +1,12 @@ package com.serotonin.mango.rt.event.handlers; import com.serotonin.mango.rt.event.EventInstance; +import com.serotonin.mango.rt.event.type.SystemEventType; import com.serotonin.mango.rt.maint.work.AfterWork; import com.serotonin.mango.util.MsgContentUtils; import com.serotonin.mango.vo.event.EventHandlerVO; import com.serotonin.mango.web.email.IMsgSubjectContent; +import com.serotonin.web.i18n.LocalizableMessage; import freemarker.template.TemplateException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -57,16 +59,15 @@ public IMsgSubjectContent createContent(EventInstance evt, String alias) throws private final SystemSettingsService systemSettingsService; private final MailingListService mailingListService; - @Deprecated public EmailToSmsHandlerRT(EventHandlerVO vo) { - super(vo); + super(vo, SystemEventType.duplicateIgnoreEventType(SystemEventType.TYPE_SMS_SEND_FAILURE, vo.getId())); this.systemSettingsService = new SystemSettingsService(); this.mailingListService = new MailingListService(); } public EmailToSmsHandlerRT(EventHandlerVO vo, ScheduledExecuteInactiveEventService service, MailingListService mailingListService, SystemSettingsService systemSettingsService) { - super(vo, service, mailingListService); + super(vo, service, mailingListService, SystemEventType.duplicateIgnoreEventType(SystemEventType.TYPE_SMS_SEND_FAILURE, vo.getId())); this.systemSettingsService = systemSettingsService; this.mailingListService = mailingListService; } @@ -90,9 +91,19 @@ protected void sendEmail(EventInstance evt, Set addresses) { sendMsg(evt, SmsNotificationType.MSG_FROM_EVENT, addresses, vo.getAlias(), new AfterWork() { @Override public void workFail(Throwable exception) { - LOG.error("Failed sending sms for " + eventHandlerInfo(getVo()) + ", " + eventInfo(evt) - + ", error: " + exception.getMessage()); + String msg = "Failed sending sms for " + eventHandlerInfo(getVo()) + ", " + eventInfo(evt) + + ", error: " + exception.getMessage(); + LOG.error(msg); + LocalizableMessage message = new LocalizableMessage("event.sms.failure", + vo.getAlias(), addresses, msg); + SystemEventType.raiseEvent(getEventType(), System.currentTimeMillis(), true, message); } + + @Override + public void workSuccess() { + SystemEventType.returnToNormal(getEventType(), System.currentTimeMillis()); + } + }, () -> eventHandlerInfo(getVo()) + ", " + eventInfo(evt)); } diff --git a/src/com/serotonin/mango/rt/event/handlers/EventHandlerRT.java b/src/com/serotonin/mango/rt/event/handlers/EventHandlerRT.java index 5d483bd156..f94509e82b 100644 --- a/src/com/serotonin/mango/rt/event/handlers/EventHandlerRT.java +++ b/src/com/serotonin/mango/rt/event/handlers/EventHandlerRT.java @@ -18,20 +18,37 @@ */ package com.serotonin.mango.rt.event.handlers; +import com.serotonin.mango.Common; import com.serotonin.mango.rt.EventManager; import com.serotonin.mango.rt.event.EventInstance; +import com.serotonin.mango.rt.event.type.EventType; import com.serotonin.mango.vo.event.EventHandlerVO; -abstract public class EventHandlerRT { +public abstract class EventHandlerRT { protected EventHandlerVO vo; + private final EventType eventType; + + protected EventHandlerRT(EventHandlerVO vo, EventType eventType) { + this.vo = vo; + this.eventType = eventType; + } + + protected EventHandlerVO getVo() { + return vo; + } + + protected EventType getEventType() { + return eventType; + } + /** * Not all events that are raised are made active. It depends on the event's alarm level and duplicate handling. * * @see EventManager.raiseEvent for details. * @param evt */ - abstract public void eventRaised(EventInstance evt); + public abstract void eventRaised(EventInstance evt); /** * Called when the event is considered inactive. @@ -39,6 +56,9 @@ abstract public class EventHandlerRT { * @see EventManager.raiseEvent for details. * @param evt */ - abstract public void eventInactive(EventInstance evt); + public abstract void eventInactive(EventInstance evt); + public int getId() { + return getVo() == null ? Common.NEW_ID : getVo().getId(); + } } diff --git a/src/com/serotonin/mango/rt/event/handlers/ProcessHandlerRT.java b/src/com/serotonin/mango/rt/event/handlers/ProcessHandlerRT.java index 5b8a62a5b1..c356c5eaaf 100644 --- a/src/com/serotonin/mango/rt/event/handlers/ProcessHandlerRT.java +++ b/src/com/serotonin/mango/rt/event/handlers/ProcessHandlerRT.java @@ -19,6 +19,7 @@ package com.serotonin.mango.rt.event.handlers; import com.serotonin.mango.rt.event.EventInstance; +import com.serotonin.mango.rt.event.type.SystemEventType; import com.serotonin.mango.rt.maint.work.ProcessWorkItem; import com.serotonin.mango.vo.event.EventHandlerVO; import com.serotonin.util.StringUtils; @@ -28,22 +29,22 @@ */ public class ProcessHandlerRT extends EventHandlerRT { public ProcessHandlerRT(EventHandlerVO vo) { - this.vo = vo; + super(vo, SystemEventType.duplicateIgnoreEventType(SystemEventType.TYPE_PROCESS_FAILURE, vo.getId())); } @Override public void eventRaised(EventInstance evt) { - executeCommand(vo.getActiveProcessCommand()); + executeCommand(getVo().getActiveProcessCommand()); } @Override public void eventInactive(EventInstance evt) { - executeCommand(vo.getInactiveProcessCommand()); + executeCommand(getVo().getInactiveProcessCommand()); } private void executeCommand(String command) { if (StringUtils.isEmpty(command)) return; - ProcessWorkItem.queueProcess(command, vo); + ProcessWorkItem.queueProcess(command, getVo(), getEventType()); } } diff --git a/src/com/serotonin/mango/rt/event/handlers/ScriptHandlerRT.java b/src/com/serotonin/mango/rt/event/handlers/ScriptHandlerRT.java index a4422152f0..63eb2fa9cf 100644 --- a/src/com/serotonin/mango/rt/event/handlers/ScriptHandlerRT.java +++ b/src/com/serotonin/mango/rt/event/handlers/ScriptHandlerRT.java @@ -6,11 +6,15 @@ import com.serotonin.mango.Common; import com.serotonin.mango.rt.event.EventInstance; +import com.serotonin.mango.rt.event.type.SystemEventType; import com.serotonin.mango.vo.event.EventHandlerVO; +import com.serotonin.web.i18n.LocalizableMessage; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.scada_lts.mango.service.ScriptService; +import java.util.function.IntSupplier; + import static com.serotonin.mango.util.LoggingScriptUtils.*; public class ScriptHandlerRT extends EventHandlerRT { @@ -18,60 +22,52 @@ public class ScriptHandlerRT extends EventHandlerRT { private static final Log LOG = LogFactory.getLog(ScriptHandlerRT.class); public ScriptHandlerRT(EventHandlerVO vo) { - this.vo = vo; + super(vo, SystemEventType.duplicateIgnoreEventType(SystemEventType.TYPE_SCRIPT_HANDLER_FAILURE, vo.getId())); } @Override public void eventInactive(EventInstance evt) { - if(vo.getInactiveScriptCommand() == Common.NEW_ID) { - LOG.trace("Inactive script not set: " + generateContext(evt, vo)); - return; - } - ScriptVO script; - try { - script = new ScriptService().getScript(vo - .getInactiveScriptCommand()); - } catch (Exception ex) { - LOG.warn(infoErrorInitializationScript(ex, vo, evt)); - return; - } - if (script != null) { - try { - script.createScriptRT().execute(); - } catch (ScriptException e) { - LOG.warn(infoErrorExecutionScript(e, script), e); - } catch (Exception e) { - LOG.warn(infoErrorExecutionScript(e, script)); - } - } else { - LOG.warn(infoErrorInitializationScript(null, vo, evt)); - } + executeScript(evt, vo::getInactiveScriptCommand, getVo()); } @Override public void eventRaised(EventInstance evt) { - if(vo.getActiveScriptCommand() == Common.NEW_ID) { - LOG.trace("Active script not set: " + generateContext(evt, vo)); + executeScript(evt, vo::getActiveScriptCommand, getVo()); + } + + private void executeScript(EventInstance evt, IntSupplier scriptCommand, EventHandlerVO vo) { + if(scriptCommand.getAsInt() == Common.NEW_ID || scriptCommand.getAsInt() == 0) { + LOG.warn("Script not set: " + generateContext(evt, vo)); return; } ScriptVO script; try { - script = new ScriptService().getScript(vo - .getActiveScriptCommand()); + script = new ScriptService().getScript(scriptCommand.getAsInt()); } catch (Exception ex) { - LOG.warn(infoErrorInitializationScript(ex, vo, evt)); + String msg = infoErrorInitializationScript(ex, vo, evt); + LOG.warn(msg); + LocalizableMessage message = new LocalizableMessage("event.script.failure", infoErrorInitializationScript(null, vo, evt), ex.getMessage()); + SystemEventType.raiseEvent(getEventType(), System.currentTimeMillis(), true, message); return; } if (script != null) { try { script.createScriptRT().execute(); + SystemEventType.returnToNormal(getEventType(), System.currentTimeMillis()); } catch (ScriptException e) { LOG.warn(infoErrorExecutionScript(e, script), e); + LocalizableMessage message = new LocalizableMessage("event.script.failure", infoErrorExecutionScript(null, script), e.getMessage()); + SystemEventType.raiseEvent(getEventType(), System.currentTimeMillis(), true, message); } catch (Exception e) { LOG.warn(infoErrorExecutionScript(e, script)); + LocalizableMessage message = new LocalizableMessage("event.script.failure", infoErrorExecutionScript(null, script), e.getMessage()); + SystemEventType.raiseEvent(getEventType(), System.currentTimeMillis(), true, message); } } else { - LOG.warn(infoErrorInitializationScript(null, vo, evt)); + String msg = infoErrorInitializationScript(null, vo, evt); + LOG.warn(msg); + LocalizableMessage message = new LocalizableMessage("event.script.failure", msg, "-||-"); + SystemEventType.raiseEvent(getEventType(), System.currentTimeMillis(), true, message); } } diff --git a/src/com/serotonin/mango/rt/event/handlers/SetPointHandlerRT.java b/src/com/serotonin/mango/rt/event/handlers/SetPointHandlerRT.java index 2b5019eeb7..2b9892c7e9 100644 --- a/src/com/serotonin/mango/rt/event/handlers/SetPointHandlerRT.java +++ b/src/com/serotonin/mango/rt/event/handlers/SetPointHandlerRT.java @@ -41,11 +41,13 @@ public class SetPointHandlerRT extends EventHandlerRT implements SetPointSource private static final Log LOG = LogFactory.getLog(SetPointHandlerRT.class); public SetPointHandlerRT(EventHandlerVO vo) { - this.vo = vo; + super(vo, SystemEventType.duplicateIgnoreEventType(SystemEventType.TYPE_SET_POINT_HANDLER_FAILURE, vo.getId())); } @Override public void eventRaised(EventInstance evt) { + EventHandlerVO vo = getVo(); + EventType eventType = getEventType(); if (vo.getActiveAction() == EventHandlerVO.SET_ACTION_NONE) return; @@ -54,14 +56,18 @@ public void eventRaised(EventInstance evt) { vo.getTargetPointId()); if (targetPoint == null) { raiseFailureEvent(new LocalizableMessage( - "event.setPoint.targetPointMissing"), evt.getEventType()); + "event.setPoint.targetPointMissing"), evt.getEventType(), eventType, vo); return; + } else { + returnToNormal(eventType); } if (!targetPoint.getPointLocator().isSettable()) { raiseFailureEvent(new LocalizableMessage( - "event.setPoint.targetNotSettable"), evt.getEventType()); + "event.setPoint.targetNotSettable"), evt.getEventType(), eventType, vo); return; + } else { + returnToNormal(eventType); } int targetDataType = targetPoint.getVO().getPointLocator() @@ -75,22 +81,28 @@ public void eventRaised(EventInstance evt) { if (sourcePoint == null) { raiseFailureEvent(new LocalizableMessage( "event.setPoint.activePointMissing"), - evt.getEventType()); + evt.getEventType(), eventType, vo); return; + } else { + returnToNormal(eventType); } PointValueTime valueTime = sourcePoint.getPointValue(); if (valueTime == null) { raiseFailureEvent(new LocalizableMessage( - "event.setPoint.activePointValue"), evt.getEventType()); + "event.setPoint.activePointValue"), evt.getEventType(), eventType, vo); return; + } else { + returnToNormal(eventType); } if (DataTypes.getDataType(valueTime.getValue()) != targetDataType) { raiseFailureEvent(new LocalizableMessage( "event.setPoint.activePointDataType"), - evt.getEventType()); + evt.getEventType(), eventType, vo); return; + } else { + returnToNormal(eventType); } value = valueTime.getValue(); @@ -104,11 +116,13 @@ public void eventRaised(EventInstance evt) { // Queue a work item to perform the set point. Common.ctx.getBackgroundProcessing().addWorkItem( new SetPointWorkItem(vo.getTargetPointId(), new PointValueTime( - value, System.currentTimeMillis()), this)); + value, System.currentTimeMillis()), this, getEventType())); } @Override public void eventInactive(EventInstance evt) { + EventHandlerVO vo = getVo(); + EventType eventType = getEventType(); if (vo.getInactiveAction() == EventHandlerVO.SET_ACTION_NONE) return; @@ -117,14 +131,18 @@ public void eventInactive(EventInstance evt) { vo.getTargetPointId()); if (targetPoint == null) { raiseFailureEvent(new LocalizableMessage( - "event.setPoint.targetPointMissing"), evt.getEventType()); + "event.setPoint.targetPointMissing"), evt.getEventType(), eventType, vo); return; + } else { + returnToNormal(eventType); } if (!targetPoint.getPointLocator().isSettable()) { raiseFailureEvent(new LocalizableMessage( - "event.setPoint.targetNotSettable"), evt.getEventType()); + "event.setPoint.targetNotSettable"), evt.getEventType(), eventType, vo); return; + } else { + returnToNormal(eventType); } int targetDataType = targetPoint.getVO().getPointLocator() @@ -138,23 +156,29 @@ public void eventInactive(EventInstance evt) { if (sourcePoint == null) { raiseFailureEvent(new LocalizableMessage( "event.setPoint.inactivePointMissing"), - evt.getEventType()); + evt.getEventType(), eventType, vo); return; + } else { + returnToNormal(eventType); } PointValueTime valueTime = sourcePoint.getPointValue(); if (valueTime == null) { raiseFailureEvent(new LocalizableMessage( "event.setPoint.inactivePointValue"), - evt.getEventType()); + evt.getEventType(), eventType, vo); return; + } else { + returnToNormal(eventType); } if (DataTypes.getDataType(valueTime.getValue()) != targetDataType) { raiseFailureEvent(new LocalizableMessage( "event.setPoint.inactivePointDataType"), - evt.getEventType()); + evt.getEventType(), eventType, vo); return; + } else { + returnToNormal(eventType); } value = valueTime.getValue(); @@ -167,10 +191,11 @@ public void eventInactive(EventInstance evt) { Common.ctx.getBackgroundProcessing().addWorkItem( new SetPointWorkItem(vo.getTargetPointId(), new PointValueTime( - value, System.currentTimeMillis()), this)); + value, System.currentTimeMillis()), this, getEventType())); } - private void raiseFailureEvent(LocalizableMessage message, EventType et) { + private static void raiseFailureEvent(LocalizableMessage message, EventType et, + EventType handlerEventType, EventHandlerVO vo) { if (et != null && et.isSystemMessage()) { if (((SystemEventType) et).getSystemEventTypeId() == SystemEventType.TYPE_SET_POINT_HANDLER_FAILURE) { // The set point attempt failed for an event that is a set point @@ -183,28 +208,28 @@ private void raiseFailureEvent(LocalizableMessage message, EventType et) { return; } } - - SystemEventType eventType = new SystemEventType( - SystemEventType.TYPE_SET_POINT_HANDLER_FAILURE, vo.getId()); if (StringUtils.isEmpty(vo.getAlias())) message = new LocalizableMessage("event.setPointFailed", message); else message = new LocalizableMessage("event.setPointFailed.alias", vo.getAlias(), message); - SystemEventType.raiseEvent(eventType, System.currentTimeMillis(), - false, message); + SystemEventType.raiseEvent(handlerEventType, System.currentTimeMillis(), + true, message); + } + + private static void returnToNormal(EventType eventType) { + SystemEventType.returnToNormal(eventType, System.currentTimeMillis()); } public void raiseRecursionFailureEvent() { - raiseFailureEvent(new LocalizableMessage( - "event.setPoint.recursionFailure"), null); + raiseFailureEvent(new LocalizableMessage("event.setPoint.recursionFailure"), null, getEventType(), getVo()); } // // SetPointSource implementation // public int getSetPointSourceId() { - return vo.getId(); + return getVo().getId(); } public int getSetPointSourceType() { diff --git a/src/com/serotonin/mango/rt/event/type/EventType.java b/src/com/serotonin/mango/rt/event/type/EventType.java index ae460ab7bb..b1b627636a 100644 --- a/src/com/serotonin/mango/rt/event/type/EventType.java +++ b/src/com/serotonin/mango/rt/event/type/EventType.java @@ -204,6 +204,14 @@ public int getPublisherId() { return -1; } + public int getEventHandlerId() { + return -1; + } + + public int getSystemEventTypeId() { + return -1; + } + /** * Determines whether an event type that, once raised, will always first be deactivated or whether overriding events * can be raised. Overrides can occur in data sources and point locators where a retry of a failed action causes the diff --git a/src/com/serotonin/mango/rt/event/type/SystemEventType.java b/src/com/serotonin/mango/rt/event/type/SystemEventType.java index ca497541c3..39f4019a58 100644 --- a/src/com/serotonin/mango/rt/event/type/SystemEventType.java +++ b/src/com/serotonin/mango/rt/event/type/SystemEventType.java @@ -36,6 +36,8 @@ import com.serotonin.mango.vo.event.EventTypeVO; import com.serotonin.web.i18n.LocalizableMessage; +import static com.serotonin.mango.rt.event.type.EventType.DuplicateHandling.IGNORE; + @JsonRemoteEntity public class SystemEventType extends EventType { // @@ -56,6 +58,8 @@ public class SystemEventType extends EventType { public static final int TYPE_EMAIL_SEND_FAILURE = 8; public static final int TYPE_POINT_LINK_FAILURE = 9; public static final int TYPE_PROCESS_FAILURE = 10; + public static final int TYPE_SCRIPT_HANDLER_FAILURE = 11; + public static final int TYPE_SMS_SEND_FAILURE = 12; public static final ExportCodes TYPE_CODES = new ExportCodes(); static { @@ -72,6 +76,8 @@ public class SystemEventType extends EventType { TYPE_CODES.addElement(TYPE_EMAIL_SEND_FAILURE, "EMAIL_SEND_FAILURE"); TYPE_CODES.addElement(TYPE_POINT_LINK_FAILURE, "POINT_LINK_FAILURE"); TYPE_CODES.addElement(TYPE_PROCESS_FAILURE, "PROCESS_FAILURE"); + TYPE_CODES.addElement(TYPE_SCRIPT_HANDLER_FAILURE, "SCRIPT_HANDLER_FAILURE"); + TYPE_CODES.addElement(TYPE_SMS_SEND_FAILURE, "SMS_SEND_FAILURE"); } private static List systemEventTypes; @@ -100,6 +106,10 @@ public static List getSystemEventTypes() { AlarmLevels.URGENT); addEventTypeVO(TYPE_PROCESS_FAILURE, "event.system.process", AlarmLevels.URGENT); + addEventTypeVO(TYPE_SCRIPT_HANDLER_FAILURE, "event.system.script", + AlarmLevels.URGENT); + addEventTypeVO(TYPE_SMS_SEND_FAILURE, "event.system.sms", + AlarmLevels.URGENT); } return systemEventTypes; } @@ -132,19 +142,19 @@ public static void setEventTypeAlarmLevel(int type, int alarmLevel) { } } - public static void raiseEvent(SystemEventType type, long time, boolean rtn, + public static void raiseEvent(EventType type, long time, boolean rtn, LocalizableMessage message) { - EventTypeVO vo = getEventType(type.getSystemEventTypeId()); + EventTypeVO vo = getEventType(type.getReferenceId1()); if(vo != null) { int alarmLevel = vo.getAlarmLevel(); Common.ctx.getEventManager().raiseEvent(type, time, rtn, alarmLevel, message, null); } else { - LOG.warn(LoggingUtils.systemEventTypInfo(type)); + LOG.error(LoggingUtils.systemEventTypInfo(type)); } } - public static void returnToNormal(SystemEventType type, long time) { + public static void returnToNormal(EventType type, long time) { Common.ctx.getEventManager().returnToNormal(type, time); } @@ -177,6 +187,10 @@ public SystemEventType(int systemEventTypeId, int refId2, this.duplicateHandling = duplicateHandling; } + public static SystemEventType duplicateIgnoreEventType(int systemEventTypeId, int refId2) { + return new SystemEventType(systemEventTypeId, refId2, IGNORE); + } + @Override public int getEventSourceId() { return EventType.EventSources.SYSTEM; @@ -186,6 +200,15 @@ public int getSystemEventTypeId() { return systemEventTypeId; } + @Override + public int getEventHandlerId() { + return this.systemEventTypeId == TYPE_SET_POINT_HANDLER_FAILURE || + this.systemEventTypeId == TYPE_SCRIPT_HANDLER_FAILURE || + this.systemEventTypeId == TYPE_EMAIL_SEND_FAILURE || + this.systemEventTypeId == TYPE_SMS_SEND_FAILURE || + this.systemEventTypeId == TYPE_PROCESS_FAILURE ? getReferenceId2() : -1; + } + @Override public boolean isSystemMessage() { return true; @@ -193,7 +216,11 @@ public boolean isSystemMessage() { @Override public String toString() { - return "SystemEventType(eventTypeId=" + systemEventTypeId + ")"; + return "SystemEventType{" + + "systemEventTypeId=" + systemEventTypeId + + ", refId2=" + refId2 + + ", duplicateHandling=" + duplicateHandling + + '}'; } @Override diff --git a/src/com/serotonin/mango/rt/link/PointLinkRT.java b/src/com/serotonin/mango/rt/link/PointLinkRT.java index 1c656c92ae..82cf588112 100644 --- a/src/com/serotonin/mango/rt/link/PointLinkRT.java +++ b/src/com/serotonin/mango/rt/link/PointLinkRT.java @@ -63,7 +63,7 @@ public PointLinkRT(PointLinkVO vo) { this.vo = vo; eventType = new SystemEventType( SystemEventType.TYPE_POINT_LINK_FAILURE, vo.getId(), - EventType.DuplicateHandling.IGNORE_SAME_MESSAGE); + EventType.DuplicateHandling.IGNORE); ready = true; } @@ -178,11 +178,11 @@ private void execute(PointValueTime newValue) { "event.pointLink.convertError")); return; } + returnToNormal(); // Queue a work item to perform the update. Common.ctx.getBackgroundProcessing().addWorkItem( - new PointLinkSetPointWorkItem(vo.getTargetPointId(), newValue, this)); - returnToNormal(); + new PointLinkSetPointWorkItem(vo.getTargetPointId(), newValue, this, eventType)); } // diff --git a/src/com/serotonin/mango/rt/maint/work/PointLinkSetPointWorkItem.java b/src/com/serotonin/mango/rt/maint/work/PointLinkSetPointWorkItem.java index 1c8c7e3838..92dbed9688 100644 --- a/src/com/serotonin/mango/rt/maint/work/PointLinkSetPointWorkItem.java +++ b/src/com/serotonin/mango/rt/maint/work/PointLinkSetPointWorkItem.java @@ -3,6 +3,7 @@ import com.serotonin.mango.rt.dataImage.PointLinkSetPointSource; import com.serotonin.mango.rt.dataImage.PointValueTime; import com.serotonin.mango.rt.dataImage.SetPointSource; +import com.serotonin.mango.rt.event.type.EventType; public class PointLinkSetPointWorkItem extends SetPointWorkItem { @@ -14,8 +15,8 @@ public class PointLinkSetPointWorkItem extends SetPointWorkItem { * @param source */ public PointLinkSetPointWorkItem(int targetPointId, PointValueTime pvt, - PointLinkSetPointSource source) { - super(targetPointId, pvt, (SetPointSource) source); + PointLinkSetPointSource source, EventType eventType) { + super(targetPointId, pvt, (SetPointSource) source, eventType); this.plSource = source; } diff --git a/src/com/serotonin/mango/rt/maint/work/ProcessWorkItem.java b/src/com/serotonin/mango/rt/maint/work/ProcessWorkItem.java index a45e3d28fb..286a81d189 100644 --- a/src/com/serotonin/mango/rt/maint/work/ProcessWorkItem.java +++ b/src/com/serotonin/mango/rt/maint/work/ProcessWorkItem.java @@ -23,6 +23,7 @@ import java.io.InputStreamReader; import java.io.StringWriter; +import com.serotonin.mango.rt.event.type.EventType; import com.serotonin.mango.util.LoggingUtils; import com.serotonin.mango.vo.event.EventHandlerVO; import org.apache.commons.logging.Log; @@ -41,30 +42,20 @@ public class ProcessWorkItem extends AbstractBeforeAfterWorkItem { static final Log LOG = LogFactory.getLog(ProcessWorkItem.class); private static final int TIMEOUT = 15000; // 15 seconds + private final EventType eventType; - @Deprecated - public static void queueProcess(String command) { - ProcessWorkItem item = new ProcessWorkItem(command); - Common.ctx.getBackgroundProcessing().addWorkItem(item); - } - - public static void queueProcess(String command, EventHandlerVO handler) { - ProcessWorkItem item = new ProcessWorkItem(command, LoggingUtils.eventHandlerInfo(handler)); + public static void queueProcess(String command, EventHandlerVO handler, EventType eventType) { + ProcessWorkItem item = new ProcessWorkItem(command, LoggingUtils.eventHandlerInfo(handler), eventType); Common.ctx.getBackgroundProcessing().addWorkItem(item); } final String command; final String details; - @Deprecated - public ProcessWorkItem(String command) { - this.command = command; - this.details = null; - } - - public ProcessWorkItem(String command, String details) { + public ProcessWorkItem(String command, String details, EventType eventType) { this.command = command; this.details = details; + this.eventType = eventType; } @Override @@ -76,12 +67,17 @@ public void work() { } } + @Override + public void workSuccess() { + SystemEventType.returnToNormal(eventType, System.currentTimeMillis()); + } + @Override public void workFail(Throwable e) { Throwable throwable = e.getCause() != null ? e.getCause() : e; LOG.error(this + " - " + throwable.getMessage(), throwable); - SystemEventType.raiseEvent(new SystemEventType(SystemEventType.TYPE_PROCESS_FAILURE), - System.currentTimeMillis(), false, + SystemEventType.raiseEvent(eventType, + System.currentTimeMillis(), true, new LocalizableMessage("event.process.failure", command, throwable.getMessage())); } diff --git a/src/com/serotonin/mango/rt/maint/work/SetPointWorkItem.java b/src/com/serotonin/mango/rt/maint/work/SetPointWorkItem.java index bceb83c247..3d6bec9b44 100644 --- a/src/com/serotonin/mango/rt/maint/work/SetPointWorkItem.java +++ b/src/com/serotonin/mango/rt/maint/work/SetPointWorkItem.java @@ -24,6 +24,9 @@ import com.serotonin.mango.Common; import com.serotonin.mango.rt.dataImage.PointValueTime; import com.serotonin.mango.rt.dataImage.SetPointSource; +import com.serotonin.mango.rt.event.type.EventType; +import com.serotonin.mango.rt.event.type.SystemEventType; +import com.serotonin.web.i18n.LocalizableMessage; /** * @author Matthew Lohbihler @@ -37,7 +40,9 @@ public class SetPointWorkItem extends AbstractBeforeAfterWorkItem { private final SetPointSource source; private final List sourceIds; - public SetPointWorkItem(int targetPointId, PointValueTime pvt, SetPointSource source) { + private final EventType eventType; + + public SetPointWorkItem(int targetPointId, PointValueTime pvt, SetPointSource source, EventType eventType) { this.targetPointId = targetPointId; this.pvt = pvt; this.source = source; @@ -46,6 +51,8 @@ public SetPointWorkItem(int targetPointId, PointValueTime pvt, SetPointSource so sourceIds = new ArrayList(); else sourceIds = threadLocal.get(); + + this.eventType = eventType; } @Override @@ -75,6 +82,16 @@ public void work() { } } + @Override + public void workSuccess() { + SystemEventType.returnToNormal(eventType, System.currentTimeMillis()); + } + + @Override + public void workFail(Throwable exception) { + SystemEventType.raiseEvent(eventType, System.currentTimeMillis(), true, new LocalizableMessage("common.default", exception.getMessage())); + } + @Override public WorkItemPriority getPriorityType() { return WorkItemPriority.HIGH; diff --git a/src/com/serotonin/mango/util/LoggingUtils.java b/src/com/serotonin/mango/util/LoggingUtils.java index 570e440306..af21f4879b 100644 --- a/src/com/serotonin/mango/util/LoggingUtils.java +++ b/src/com/serotonin/mango/util/LoggingUtils.java @@ -6,7 +6,7 @@ import com.serotonin.mango.rt.dataImage.SetPointSource; import com.serotonin.mango.rt.dataSource.DataSourceRT; import com.serotonin.mango.rt.event.EventInstance; -import com.serotonin.mango.rt.event.type.SystemEventType; +import com.serotonin.mango.rt.event.type.EventType; import com.serotonin.mango.view.View; import com.serotonin.mango.view.component.ScriptComponent; import com.serotonin.mango.vo.DataPointVO; @@ -178,15 +178,16 @@ public static String eventTypeInfo(EventTypeVO event) { return MessageFormat.format(info, event.getDescription(), event.getTypeId(), event.getTypeRef1(), event.getTypeRef2(), event.getAlarmLevel(), event.getEventDetectorKey()); } - public static String systemEventTypInfo(SystemEventType event) { + public static String systemEventTypInfo(EventType event) { if(event == null) return ""; String info = "system event type (systemEventTypeId: {0}, dataSourceId: {1}, dataPointId: {2}, eventSourceId: {3}, " + "duplicateHandling: {4}, referenceId1: {5}, referenceId2: {6}, compoundEventDetectorId: {7}, scheduleId: {8}, " + - "publisherId: {9}, systemMessage: {10})"; + "publisherId: {9}, eventHandlerId: {10}, systemMessage: {11})"; return MessageFormat.format(info, event.getSystemEventTypeId(), event.getDataSourceId(), event.getDataPointId(), event.getEventSourceId(), event.getDuplicateHandling(), event.getReferenceId1(), event.getReferenceId2(), - event.getCompoundEventDetectorId(), event.getScheduleId(), event.getPublisherId(), event.isSystemMessage()); + event.getCompoundEventDetectorId(), event.getScheduleId(), event.getPublisherId(), event.getEventHandlerId(), + event.isSystemMessage()); } public static String eventTypeInfo(int type, int alarmLevel) { diff --git a/src/com/serotonin/mango/util/SendUtils.java b/src/com/serotonin/mango/util/SendUtils.java index 7c238bf7f7..4b19c7896f 100644 --- a/src/com/serotonin/mango/util/SendUtils.java +++ b/src/com/serotonin/mango/util/SendUtils.java @@ -150,11 +150,19 @@ private static void sendMsg(EventInstance evt, NotificationType notificationType validateEmail(evt, notificationType, addresses, alias); - if (evt.getEventType().isSystemMessage() - && ((SystemEventType) evt.getEventType()).getSystemEventTypeId() == SystemEventType.TYPE_EMAIL_SEND_FAILURE) { - // Don't send email notifications about email send failures. - notExecuted.workNotExecuted("Not sending email for event raised due to email failure"); - return; + if (evt.getEventType().isSystemMessage()) { + + int systemEventTypeId = evt.getEventType().getSystemEventTypeId(); + + if(systemEventTypeId == SystemEventType.TYPE_EMAIL_SEND_FAILURE) { + notExecuted.workNotExecuted("Not sending email for event raised due to email failure"); + return; + } + + if (systemEventTypeId == SystemEventType.TYPE_SMS_SEND_FAILURE) { + notExecuted.workNotExecuted("Not sending sms for event raised due to sms failure"); + return; + } } SendEmailConfig.validateSystemSettings(); @@ -272,17 +280,17 @@ private static String getInfoEmail(EventInstance evt, NotificationType notificat String messageExceptionWhenGetSubjectEmail = ""; try { LocalizableMessage subjectMsg; - LocalizableMessage notifTypeMsg = new LocalizableMessage(notificationType.getKey()); + LocalizableMessage notifyTypeMsg = new LocalizableMessage(notificationType.getKey()); if (StringUtils.isEmpty(alias)) { if (evt.getId() == Common.NEW_ID) - subjectMsg = new LocalizableMessage("ftl.subject.default.log", notifTypeMsg); + subjectMsg = new LocalizableMessage("ftl.subject.default.log", notifyTypeMsg); else - subjectMsg = new LocalizableMessage("ftl.subject.default.id", notifTypeMsg, evt.getId()); + subjectMsg = new LocalizableMessage("ftl.subject.default.id", notifyTypeMsg, evt.getId()); } else { if (evt.getId() == Common.NEW_ID) - subjectMsg = new LocalizableMessage("ftl.subject.alias", alias, notifTypeMsg); + subjectMsg = new LocalizableMessage("ftl.subject.alias", alias, notifyTypeMsg); else - subjectMsg = new LocalizableMessage("ftl.subject.alias.id", alias, notifTypeMsg, evt.getId()); + subjectMsg = new LocalizableMessage("ftl.subject.alias.id", alias, notifyTypeMsg, evt.getId()); } ResourceBundle bundle = Common.getBundle(); @@ -297,6 +305,43 @@ private static String getInfoEmail(EventInstance evt, NotificationType notificat messageExceptionWhenGetSubjectEmail; } + private static String getInfoEmail(NotificationType notificationType, String alias) { + + String messageInfoAlias = MessageFormat.format("Alias: {0} \n", alias); + String messageInfoNotification = MessageFormat.format("Notification: {0} \n", notificationType.getKey()); + String subject = ""; + String messageExceptionWhenGetSubjectEmail = ""; + try { + LocalizableMessage subjectMsg; + LocalizableMessage notifyTypeMsg = new LocalizableMessage(notificationType.getKey()); + if (StringUtils.isEmpty(alias)) { + subjectMsg = new LocalizableMessage("ftl.subject.default.log", notifyTypeMsg); + } else { + subjectMsg = new LocalizableMessage("ftl.subject.alias", alias, notifyTypeMsg); + } + ResourceBundle bundle = Common.getBundle(); + subject = subjectMsg.getLocalizedMessage(bundle); + } catch (Exception e) { + messageExceptionWhenGetSubjectEmail = MessageFormat.format("StackTrace for subjectMsg {0}",ExceptionUtils.getStackTrace(e)); + } + return messageInfoNotification + + messageInfoAlias + + subject + + messageExceptionWhenGetSubjectEmail; + } + + private static String getInfoEmail(EventInstance evt, String alias) { + + String messageInfoAlias = MessageFormat.format("Alias: {0} \n", alias); + String messageInfoEmail = MessageFormat.format("Event: {0} \n", evt.getId()); + return messageInfoEmail + + messageInfoAlias; + } + + private static String getInfoEmail(String alias) { + return MessageFormat.format("Alias: {0} \n", alias); + } + private static void validateEmail(EventInstance evt, NotificationType notificationType, Set addresses, String alias) throws IllegalArgumentException { @@ -309,23 +354,19 @@ private static void validateEmail(EventInstance evt, NotificationType notificati if (addresses == null || addresses.size() == 0) messages += messageErrorEmails; if (messages.length() > 0) { - throw new IllegalArgumentException(getInfoEmail(evt, notificationType, alias) + messages ); + if(evt == null && notificationType == null) { + throw new IllegalArgumentException(getInfoEmail(alias) + messages); + } else if(evt == null) { + throw new IllegalArgumentException(getInfoEmail(notificationType, alias) + messages); + } else if(notificationType == null) { + throw new IllegalArgumentException(getInfoEmail(evt, alias) + messages); + } else { + throw new IllegalArgumentException(getInfoEmail(evt, notificationType, alias) + messages); + } } } - private static void validateAddresses(EventInstance evt, NotificationType notificationType, - InternetAddress[] internetAddresses, String alias) throws IllegalArgumentException { - - String messageErrorEmails = " Don't have e-mail \n"; - String messages = ""; - if (internetAddresses == null || internetAddresses.length == 0) messages += messageErrorEmails; - - if (!messages.isEmpty()) { - throw new IllegalArgumentException(getInfoEmail(evt, notificationType, alias) + messages ); - } - } - private static InternetAddress[] convertToInternetAddresses(String[] toAddresses) { Set addresses = new HashSet<>(); for (int i = 0; i < toAddresses.length; i++) { diff --git a/src/org/scada_lts/mango/service/EventService.java b/src/org/scada_lts/mango/service/EventService.java index 0d1a54ad4d..25b53c9222 100644 --- a/src/org/scada_lts/mango/service/EventService.java +++ b/src/org/scada_lts/mango/service/EventService.java @@ -413,12 +413,14 @@ public void deleteEventHandler(final int handlerId) { eventDAO.delete(handlerId); AuditEventUtils.raiseDeletedEvent(AuditEventType.TYPE_EVENT_HANDLER, handler); + Common.ctx.getEventManager().cancelEventsForHandler(handlerId); } public void deleteEventHandler(final String handlerXid) { EventHandlerVO handler = getEventHandler(handlerXid); eventDAO.delete(handler.getId()); AuditEventUtils.raiseDeletedEvent(AuditEventType.TYPE_EVENT_HANDLER, handler); + Common.ctx.getEventManager().cancelEventsForHandler(handler.getId()); } @Override @@ -573,11 +575,5 @@ private void _ackEvent(int eventId, long time, int userId, int alternateAckSourc clearCache(); notifyEventAck(eventId); - - //TODO check - /*if( signalAlarmLevelChange ) { - Common.ctx.getEventManager().setLastAlarmTimestamp(System.currentTimeMillis()); - Common.ctx.getEventManager().notifyEventAck(eventId, userId); - }*/ } } diff --git a/test/com/serotonin/mango/rt/maint/work/CreateWorkItemToStringTest.java b/test/com/serotonin/mango/rt/maint/work/CreateWorkItemToStringTest.java index 563039be13..e0112f9a33 100644 --- a/test/com/serotonin/mango/rt/maint/work/CreateWorkItemToStringTest.java +++ b/test/com/serotonin/mango/rt/maint/work/CreateWorkItemToStringTest.java @@ -53,7 +53,7 @@ public void when_new_ReportWorkItem() { @Test public void when_new_ProcessWorkItem() { //when: - WorkItem workItem = new ProcessWorkItem(null, null); + WorkItem workItem = new ProcessWorkItem(null, null, null); //then: System.out.println(workItem); } @@ -61,7 +61,7 @@ public void when_new_ProcessWorkItem() { @Test public void when_new_SetPointWorkItem() { //when: - WorkItem workItem = new SetPointWorkItem(-1, null, null); + WorkItem workItem = new SetPointWorkItem(-1, null, null, null); //then: System.out.println(workItem); } @@ -69,7 +69,7 @@ public void when_new_SetPointWorkItem() { @Test public void when_new_PointLinkSetPointWorkItem() { //when: - WorkItem workItem = new PointLinkSetPointWorkItem(-1, null, null); + WorkItem workItem = new PointLinkSetPointWorkItem(-1, null, null, null); //then: System.out.println(workItem); } diff --git a/webapp-resources/messages_de.properties b/webapp-resources/messages_de.properties index c4fd448c43..69655cf330 100644 --- a/webapp-resources/messages_de.properties +++ b/webapp-resources/messages_de.properties @@ -3337,4 +3337,8 @@ systemsettings.webresource.uploads.path.wrong=Uploaded images save path must end systemsettings.webresource.graphics.path.wrong=Graphics images path must end with "graphics" or "graphics{0}" annotation.api=REST API dsEdit.sql.statementLimit=Statement limit -dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? \ No newline at end of file +dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? +event.sms.failure=Failed to send sms titled "{0}" to "{1}". Message: "{2}" +event.script.failure=Failed execute script: "{0}", Message: "{1}" +event.system.sms=Sms send failure +event.system.script=Script event handler failure \ No newline at end of file diff --git a/webapp-resources/messages_en.properties b/webapp-resources/messages_en.properties index 2e7b7dd8ec..e26b8d6edd 100644 --- a/webapp-resources/messages_en.properties +++ b/webapp-resources/messages_en.properties @@ -3340,4 +3340,8 @@ systemsettings.webresource.uploads.path.wrong=Uploaded images save path must end systemsettings.webresource.graphics.path.wrong=Graphics images path must end with "graphics" or "graphics{0}" annotation.api=REST API dsEdit.sql.statementLimit=Statement limit -dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? \ No newline at end of file +dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? +event.sms.failure=Failed to send sms titled "{0}" to "{1}". Message: "{2}" +event.script.failure=Failed execute script: "{0}", Message: "{1}" +event.system.sms=Sms send failure +event.system.script=Script event handler failure \ No newline at end of file diff --git a/webapp-resources/messages_es.properties b/webapp-resources/messages_es.properties index 67950ec200..12d31628bd 100644 --- a/webapp-resources/messages_es.properties +++ b/webapp-resources/messages_es.properties @@ -3380,4 +3380,8 @@ systemsettings.webresource.uploads.path.wrong=Uploaded images save path must end systemsettings.webresource.graphics.path.wrong=Graphics images path must end with "graphics" or "graphics{0}" annotation.api=REST API dsEdit.sql.statementLimit=Statement limit -dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? \ No newline at end of file +dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? +event.sms.failure=Failed to send sms titled "{0}" to "{1}". Message: "{2}" +event.script.failure=Failed execute script: "{0}", Message: "{1}" +event.system.sms=Sms send failure +event.system.script=Script event handler failure \ No newline at end of file diff --git a/webapp-resources/messages_fi.properties b/webapp-resources/messages_fi.properties index 1744343e5c..c484b2341a 100644 --- a/webapp-resources/messages_fi.properties +++ b/webapp-resources/messages_fi.properties @@ -3466,4 +3466,8 @@ systemsettings.webresource.uploads.path.wrong=Uploaded images save path must end systemsettings.webresource.graphics.path.wrong=Graphics images path must end with "graphics" or "graphics{0}" annotation.api=REST API dsEdit.sql.statementLimit=Statement limit -dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? \ No newline at end of file +dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? +event.sms.failure=Failed to send sms titled "{0}" to "{1}". Message: "{2}" +event.script.failure=Failed execute script: "{0}", Message: "{1}" +event.system.sms=Sms send failure +event.system.script=Script event handler failure \ No newline at end of file diff --git a/webapp-resources/messages_fr.properties b/webapp-resources/messages_fr.properties index 6f84292d0c..f47047eb31 100644 --- a/webapp-resources/messages_fr.properties +++ b/webapp-resources/messages_fr.properties @@ -3334,4 +3334,8 @@ systemsettings.webresource.uploads.path.wrong=Uploaded images save path must end systemsettings.webresource.graphics.path.wrong=Graphics images path must end with "graphics" or "graphics{0}" annotation.api=REST API dsEdit.sql.statementLimit=Statement limit -dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? \ No newline at end of file +dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? +event.sms.failure=Failed to send sms titled "{0}" to "{1}". Message: "{2}" +event.script.failure=Failed execute script: "{0}", Message: "{1}" +event.system.sms=Sms send failure +event.system.script=Script event handler failure \ No newline at end of file diff --git a/webapp-resources/messages_lu.properties b/webapp-resources/messages_lu.properties index ff80d1b714..e4db6550cd 100644 --- a/webapp-resources/messages_lu.properties +++ b/webapp-resources/messages_lu.properties @@ -3353,4 +3353,8 @@ systemsettings.webresource.uploads.path.wrong=Uploaded images save path must end systemsettings.webresource.graphics.path.wrong=Graphics images path must end with "graphics" or "graphics{0}" annotation.api=REST API dsEdit.sql.statementLimit=Statement limit -dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? \ No newline at end of file +dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? +event.sms.failure=Failed to send sms titled "{0}" to "{1}". Message: "{2}" +event.script.failure=Failed execute script: "{0}", Message: "{1}" +event.system.sms=Sms send failure +event.system.script=Script event handler failure \ No newline at end of file diff --git a/webapp-resources/messages_nl.properties b/webapp-resources/messages_nl.properties index bb723bc425..b3d75e2951 100644 --- a/webapp-resources/messages_nl.properties +++ b/webapp-resources/messages_nl.properties @@ -3456,4 +3456,8 @@ systemsettings.webresource.uploads.path.wrong=Uploaded images save path must end systemsettings.webresource.graphics.path.wrong=Graphics images path must end with "graphics" or "graphics{0}" annotation.api=REST API dsEdit.sql.statementLimit=Statement limit -dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? \ No newline at end of file +dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? +event.sms.failure=Failed to send sms titled "{0}" to "{1}". Message: "{2}" +event.script.failure=Failed execute script: "{0}", Message: "{1}" +event.system.sms=Sms send failure +event.system.script=Script event handler failure \ No newline at end of file diff --git a/webapp-resources/messages_pl.properties b/webapp-resources/messages_pl.properties index 5b64b60dea..a699b8f785 100644 --- a/webapp-resources/messages_pl.properties +++ b/webapp-resources/messages_pl.properties @@ -3479,3 +3479,7 @@ systemsettings.webresource.graphics.path.wrong=Graphics images path must end wit annotation.api=REST API dsEdit.sql.statementLimit=Statement limit dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? +event.sms.failure=Failed to send sms titled "{0}" to "{1}". Message: "{2}" +event.script.failure=Failed execute script: "{0}", Message: "{1}" +event.system.sms=Sms send failure +event.system.script=Script event handler failure diff --git a/webapp-resources/messages_pt.properties b/webapp-resources/messages_pt.properties index 1d9d1f67f2..31c3f5cb20 100644 --- a/webapp-resources/messages_pt.properties +++ b/webapp-resources/messages_pt.properties @@ -3492,4 +3492,8 @@ systemsettings.webresource.uploads.path.wrong=Uploaded images save path must end systemsettings.webresource.graphics.path.wrong=Graphics images path must end with "graphics" or "graphics{0}" annotation.api=REST API dsEdit.sql.statementLimit=Statement limit -dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? \ No newline at end of file +dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? +event.sms.failure=Failed to send sms titled "{0}" to "{1}". Message: "{2}" +event.script.failure=Failed execute script: "{0}", Message: "{1}" +event.system.sms=Sms send failure +event.system.script=Script event handler failure \ No newline at end of file diff --git a/webapp-resources/messages_ru.properties b/webapp-resources/messages_ru.properties index 1059bc437c..d1676af0d6 100644 --- a/webapp-resources/messages_ru.properties +++ b/webapp-resources/messages_ru.properties @@ -3488,4 +3488,8 @@ systemsettings.webresource.uploads.path.wrong=Uploaded images save path must end systemsettings.webresource.graphics.path.wrong=Graphics images path must end with "graphics" or "graphics{0}" annotation.api=REST API dsEdit.sql.statementLimit=Statement limit -dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? \ No newline at end of file +dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? +event.sms.failure=Failed to send sms titled "{0}" to "{1}". Message: "{2}" +event.script.failure=Failed execute script: "{0}", Message: "{1}" +event.system.sms=Sms send failure +event.system.script=Script event handler failure \ No newline at end of file diff --git a/webapp-resources/messages_zh.properties b/webapp-resources/messages_zh.properties index e9abc498f6..0ca322fc93 100644 --- a/webapp-resources/messages_zh.properties +++ b/webapp-resources/messages_zh.properties @@ -3441,4 +3441,8 @@ systemsettings.webresource.uploads.path.wrong=Uploaded images save path must end systemsettings.webresource.graphics.path.wrong=Graphics images path must end with "graphics" or "graphics{0}" annotation.api=REST API dsEdit.sql.statementLimit=Statement limit -dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? \ No newline at end of file +dsEdit.sql.statementLimit.warning=Setting the value 0 in the Statement limit field means there is no limit for the select query, which may lead to a serious application failure due to filling up the memory needed for the application to run. Do you confirm setting Statement limit equals 0? +event.sms.failure=Failed to send sms titled "{0}" to "{1}". Message: "{2}" +event.script.failure=Failed execute script: "{0}", Message: "{1}" +event.system.sms=Sms send failure +event.system.script=Script event handler failure \ No newline at end of file