Search in sources :

Example 1 with EventLevelSummaryModel

use of com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventLevelSummaryModel 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();
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) EventInstanceModel(com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventInstanceModel) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) EventLevelSummaryModel(com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventLevelSummaryModel) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EventInstance (com.serotonin.m2m2.rt.event.EventInstance)1 User (com.serotonin.m2m2.vo.User)1 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)1 EventInstanceModel (com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventInstanceModel)1 EventLevelSummaryModel (com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventLevelSummaryModel)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1