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);
}
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;
}
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;
}
}
}
}
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));
}
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);
}
}
}
Aggregations