use of com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventInstanceModel in project ma-modules-public by infiniteautomation.
the class EventsRestController method getById.
@ApiOperation(value = "Get event by ID", notes = "")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/{id}")
public ResponseEntity<EventInstanceModel> getById(@ApiParam(value = "Valid Event ID", required = true, allowMultiple = false) @PathVariable Integer id, HttpServletRequest request) {
RestProcessResult<EventInstanceModel> result = new RestProcessResult<EventInstanceModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
EventInstanceVO vo = EventInstanceDao.instance.get(id);
if (vo == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
if (!Permissions.hasEventTypePermission(user, vo.getEventType())) {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
EventInstanceModel model = new EventInstanceModel(vo);
return result.createResponseEntity(model);
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventInstanceModel in project ma-modules-public by infiniteautomation.
the class EventsRestController method getActiveSummary.
@ApiOperation(value = "Get the active events summary", notes = "List of counts for all active events by type and the most recent active alarm for each.")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/active-summary")
public ResponseEntity<List<EventLevelSummaryModel>> getActiveSummary(HttpServletRequest request) {
RestProcessResult<List<EventLevelSummaryModel>> result = new RestProcessResult<List<EventLevelSummaryModel>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
List<EventLevelSummaryModel> list = new ArrayList<EventLevelSummaryModel>();
// This query is slow the first time as it must fill the UserEventCache
List<EventInstance> events = Common.eventManager.getAllActiveUserEvents(user.getId());
int lifeSafetyTotal = 0;
EventInstance lifeSafetyEvent = null;
int criticalTotal = 0;
EventInstance criticalEvent = null;
int urgentTotal = 0;
EventInstance urgentEvent = null;
int warningTotal = 0;
EventInstance warningEvent = null;
int importantTotal = 0;
EventInstance importantEvent = null;
int informationTotal = 0;
EventInstance informationEvent = null;
int noneTotal = 0;
EventInstance noneEvent = null;
int doNotLogTotal = 0;
EventInstance doNotLogEvent = null;
for (EventInstance event : events) {
switch(event.getAlarmLevel()) {
case AlarmLevels.LIFE_SAFETY:
lifeSafetyTotal++;
lifeSafetyEvent = event;
break;
case AlarmLevels.CRITICAL:
criticalTotal++;
criticalEvent = event;
break;
case AlarmLevels.URGENT:
urgentTotal++;
urgentEvent = event;
break;
case AlarmLevels.WARNING:
warningTotal++;
warningEvent = event;
break;
case AlarmLevels.IMPORTANT:
importantTotal++;
importantEvent = event;
break;
case AlarmLevels.INFORMATION:
informationTotal++;
informationEvent = event;
break;
case AlarmLevels.NONE:
noneTotal++;
noneEvent = event;
break;
case AlarmLevels.DO_NOT_LOG:
doNotLogTotal++;
doNotLogEvent = event;
break;
}
}
EventInstanceModel model;
// Life Safety
if (lifeSafetyEvent != null)
model = new EventInstanceModel(lifeSafetyEvent);
else
model = null;
list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.LIFE_SAFETY), lifeSafetyTotal, model));
// Critical Events
if (criticalEvent != null)
model = new EventInstanceModel(criticalEvent);
else
model = null;
list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.CRITICAL), criticalTotal, model));
// Urgent Events
if (urgentEvent != null)
model = new EventInstanceModel(urgentEvent);
else
model = null;
list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.URGENT), urgentTotal, model));
// Warning Events
if (warningEvent != null)
model = new EventInstanceModel(warningEvent);
else
model = null;
list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.WARNING), warningTotal, model));
// Important Events
if (importantEvent != null)
model = new EventInstanceModel(importantEvent);
else
model = null;
list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.IMPORTANT), importantTotal, model));
// Information Events
if (informationEvent != null)
model = new EventInstanceModel(informationEvent);
else
model = null;
list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.INFORMATION), informationTotal, model));
// None Events
if (noneEvent != null)
model = new EventInstanceModel(noneEvent);
else
model = null;
list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.NONE), noneTotal, model));
// Do Not Log Events
if (doNotLogEvent != null)
model = new EventInstanceModel(doNotLogEvent);
else
model = null;
list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.DO_NOT_LOG), doNotLogTotal, model));
return result.createResponseEntity(list);
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventInstanceModel in project ma-modules-public by infiniteautomation.
the class EventsRestController method acknowledgeEvent.
/**
* Update an event
* @param vo
* @param xid
* @param builder
* @param request
* @return
*/
@ApiOperation(value = "Acknowledge an existing event", notes = "")
@RequestMapping(method = RequestMethod.PUT, consumes = { "application/json" }, produces = { "application/json" }, value = "/acknowledge/{id}")
public ResponseEntity<EventInstanceModel> acknowledgeEvent(@PathVariable Integer id, @RequestBody(required = false) TranslatableMessageModel message, UriComponentsBuilder builder, HttpServletRequest request) {
RestProcessResult<EventInstanceModel> result = new RestProcessResult<EventInstanceModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
TranslatableMessage tlm = null;
if (message != null)
tlm = new TranslatableMessage(message.getKey(), message.getArgs().toArray());
EventInstance event = EventDao.instance.get(id);
if (event == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
} else if (!Permissions.hasEventTypePermission(user, event.getEventType())) {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
Common.eventManager.acknowledgeEventById(id, System.currentTimeMillis(), user, tlm);
// if event has a different ack timestamp, user or message it was already acked, we could return a different message
EventInstanceModel model = new EventInstanceModel(event);
// Put a link to the updated data in the header?
URI location = builder.path("/v1/events/{id}").buildAndExpand(id).toUri();
result.addRestMessage(getResourceUpdatedMessage(location));
return result.createResponseEntity(model);
}
// Not logged in
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventInstanceModel 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);
}
Aggregations