use of com.serotonin.m2m2.rt.event.type.EventType in project ma-core-public by infiniteautomation.
the class EventsDwr method exportEvents.
@DwrPermission(user = true)
public void exportEvents(int eventId, String eventType, String status, int alarmLevel, String keywordStr, int dateRangeType, int relativeDateType, int previousPeriodCount, int previousPeriodType, int pastPeriodCount, int pastPeriodType, boolean fromNone, int fromYear, int fromMonth, int fromDay, int fromHour, int fromMinute, int fromSecond, boolean toNone, int toYear, int toMonth, int toDay, int toHour, int toMinute, int toSecond) {
User user = Common.getUser();
LongPair dateRange = getDateRange(dateRangeType, relativeDateType, previousPeriodCount, previousPeriodType, pastPeriodCount, pastPeriodType, fromNone, fromYear, fromMonth, fromDay, fromHour, fromMinute, fromSecond, toNone, toYear, toMonth, toDay, toHour, toMinute, toSecond, user.getDateTimeZoneInstance());
EventExportDefinition def = new EventExportDefinition(eventId, eventType, status, alarmLevel, getKeywords(keywordStr), dateRange.getL1(), dateRange.getL2(), user.getId());
Common.getUser().setEventExportDefinition(def);
}
use of com.serotonin.m2m2.rt.event.type.EventType in project ma-core-public by infiniteautomation.
the class EventsDwr method search.
@DwrPermission(user = true)
public ProcessResult search(int eventId, String eventType, String status, int alarmLevel, String keywordStr, int dateRangeType, int relativeDateType, int previousPeriodCount, int previousPeriodType, int pastPeriodCount, int pastPeriodType, boolean fromNone, int fromYear, int fromMonth, int fromDay, int fromHour, int fromMinute, int fromSecond, boolean toNone, int toYear, int toMonth, int toDay, int toHour, int toMinute, int toSecond, int page, Date date) {
ProcessResult response = new ProcessResult();
HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
User user = Common.getUser(request);
int from = PAGE_SIZE * page;
int to = from + PAGE_SIZE;
// excluding all of the events for that day. So, // we need to add 1 day to it.
if (date != null)
date = DateUtils.minus(new DateTime(date.getTime()), Common.TimePeriods.DAYS, -1).toDate();
LongPair dateRange = getDateRange(dateRangeType, relativeDateType, previousPeriodCount, previousPeriodType, pastPeriodCount, pastPeriodType, fromNone, fromYear, fromMonth, fromDay, fromHour, fromMinute, fromSecond, toNone, toYear, toMonth, toDay, toHour, toMinute, toSecond, user.getDateTimeZoneInstance());
EventDao eventDao = EventDao.instance;
List<EventInstance> results = eventDao.search(eventId, eventType, status, alarmLevel, getKeywords(keywordStr), dateRange.getL1(), dateRange.getL2(), user.getId(), getTranslations(), from, to, date);
Map<String, Object> model = new HashMap<String, Object>();
int searchRowCount = eventDao.getSearchRowCount();
int pages = (int) Math.ceil(((double) searchRowCount) / PAGE_SIZE);
if (date != null) {
int startRow = eventDao.getStartRow();
if (startRow == -1)
page = pages - 1;
else
page = eventDao.getStartRow() / PAGE_SIZE;
}
if (pages > 1) {
model.put("displayPagination", true);
if (page - PAGINATION_RADIUS > 1)
model.put("leftEllipsis", true);
else
model.put("leftEllipsis", false);
int linkFrom = page + 1 - PAGINATION_RADIUS;
if (linkFrom < 2)
linkFrom = 2;
model.put("linkFrom", linkFrom);
int linkTo = page + 1 + PAGINATION_RADIUS;
if (linkTo >= pages)
linkTo = pages - 1;
model.put("linkTo", linkTo);
if (page + PAGINATION_RADIUS < pages - 2)
model.put("rightEllipsis", true);
else
model.put("rightEllipsis", false);
model.put("numberOfPages", pages);
} else
model.put("displayPagination", false);
model.put(MODEL_ATTR_EVENTS, results);
model.put("page", page);
model.put("pendingEvents", false);
response.addData("content", generateContent(request, "eventList.jsp", model));
response.addData("resultCount", new TranslatableMessage("events.search.resultCount", searchRowCount));
return response;
}
use of com.serotonin.m2m2.rt.event.type.EventType in project ma-core-public by infiniteautomation.
the class EventManagerImpl method returnToNormal.
public void returnToNormal(EventType type, long time, int alarmLevel, int cause) {
if (alarmLevel == AlarmLevels.IGNORE)
return;
EventInstance evt = remove(type);
if (evt == null)
return;
List<User> activeUsers = userDao.getActiveUsers();
// Loop in case of multiples
while (evt != null) {
evt.returnToNormal(time, cause);
for (User user : activeUsers) {
// user should be skipped.
if (type.excludeUser(user))
continue;
if (evt.getAlarmLevel() != AlarmLevels.DO_NOT_LOG) {
if (Permissions.hasEventTypePermission(user, type)) {
// Notify All User Event Listeners of the new event
for (UserEventListener l : this.userEventListeners) {
if ((l.getUserId() == user.getId())) {
Common.backgroundProcessing.addWorkItem(new EventNotifyWorkItem(user, l, evt, false, true, false, false));
}
}
// Only alarms make it into the cache
this.userEventCache.updateEvent(user.getId(), evt);
}
}
}
resetHighestAlarmLevel(time);
if (evt.getAlarmLevel() != AlarmLevels.DO_NOT_LOG)
eventDao.saveEvent(evt);
// Call inactiveEvent handlers.
handleInactiveEvent(evt);
// Check for another
evt = remove(type);
}
if (log.isTraceEnabled())
log.trace("Event returned to normal: type=" + type);
}
use of com.serotonin.m2m2.rt.event.type.EventType in project ma-core-public by infiniteautomation.
the class EventManagerImpl method isRecent.
private boolean isRecent(EventType type, TranslatableMessage message) {
long cutoff = Common.timer.currentTimeMillis() - RECENT_EVENT_PERIOD;
recentEventsLock.writeLock().lock();
try {
for (int i = recentEvents.size() - 1; i >= 0; i--) {
EventInstance evt = recentEvents.get(i);
// event instance has expired or not.
if (cutoff > evt.getActiveTimestamp())
recentEvents.remove(i);
else if (evt.getEventType().equals(type) && evt.getMessage().equals(message))
return true;
}
} finally {
recentEventsLock.writeLock().unlock();
}
return false;
}
use of com.serotonin.m2m2.rt.event.type.EventType in project ma-core-public by infiniteautomation.
the class AbstractEventHandlerModel method getEventTypes.
public List<EventTypeModel> getEventTypes() {
List<EventType> events = EventHandlerDao.instance.getEventTypesForHandler(this.data.getId());
List<EventTypeModel> models = new ArrayList<>(events.size());
for (EventType e : events) models.add(e.asModel());
return models;
}
Aggregations