Search in sources :

Example 1 with EventInstanceVO

use of com.serotonin.m2m2.vo.event.EventInstanceVO 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();
}
Also used : 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) EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with EventInstanceVO

use of com.serotonin.m2m2.vo.event.EventInstanceVO in project ma-modules-public by infiniteautomation.

the class EventsRestController method query.

@ApiOperation(value = "Query Events", notes = "Query by posting AST Model", response = EventInstanceModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }, value = "/query")
public ResponseEntity<QueryDataPageStream<EventInstanceVO>> query(@ApiParam(value = "Query", required = true) @RequestBody(required = true) ASTNode query, HttpServletRequest request) {
    RestProcessResult<QueryDataPageStream<EventInstanceVO>> result = new RestProcessResult<QueryDataPageStream<EventInstanceVO>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        query = addAndRestriction(query, new ASTNode("eq", "userId", user.getId()));
        return result.createResponseEntity(getPageStream(query));
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) QueryDataPageStream(com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream) EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) User(com.serotonin.m2m2.vo.User) ASTNode(net.jazdw.rql.parser.ASTNode) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with EventInstanceVO

use of com.serotonin.m2m2.vo.event.EventInstanceVO in project ma-core-public by infiniteautomation.

the class EventInstanceEmporter method exportRow.

/**
 * @param vo
 */
public void exportRow(EventInstanceVO vo) {
    int cellNum = 0;
    Cell cell;
    Row row;
    row = sheet.createRow(this.rowNum++);
    // Set Event Id
    cell = row.createCell(cellNum++);
    cell.setCellValue(vo.getId());
    // Alarm Level
    cell = row.createCell(cellNum++);
    cell.setCellValue(AlarmLevels.getAlarmLevelMessage(vo.getAlarmLevel()).translate(Common.getTranslations()));
    // Active Time
    cell = row.createCell(cellNum++);
    cell.setCellValue(new Date(vo.getActiveTimestamp()));
    cell.setCellStyle(dateStyle);
    // Message (Remove any HTML)
    cell = row.createCell(cellNum++);
    String messageStringHTML = vo.getMessageString();
    String messageString = StringEscapeUtils.unescapeHtml4(messageStringHTML);
    // Since we have <br/> in the code and that isn't proper HTML we need to remove it by hand
    messageString = messageString.replace("<br/>", "\n");
    cell.setCellValue(messageString);
    // Status
    cell = row.createCell(cellNum++);
    if (vo.isActive())
        cell.setCellValue(Common.translate("common.active"));
    else if (!vo.isRtnApplicable())
        cell.setCellValue("");
    else
        cell.setCellValue(vo.getRtnTimestampString() + " - " + vo.getRtnMessageString());
    // Ack Time
    // Ack User
    cell = row.createCell(cellNum++);
    Cell ackMsgCell = row.createCell(cellNum++);
    cell.setCellStyle(dateStyle);
    if (vo.isAcknowledged()) {
        cell.setCellValue(new Date(vo.getAcknowledgedTimestamp()));
        TranslatableMessage ackMessage;
        if (vo.getAcknowledgedByUserId() != 0) {
            ackMessage = new TranslatableMessage("events.export.ackedByUser", vo.getAcknowledgedByUsername());
        } else {
            ackMessage = vo.getAlternateAckSource();
        }
        if (ackMessage != null)
            ackMsgCell.setCellValue(ackMessage.translate(Common.getTranslations()));
    } else {
    // Do we need to set the cell to null explicitly
    }
}
Also used : Row(org.apache.poi.ss.usermodel.Row) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) Cell(org.apache.poi.ss.usermodel.Cell) Date(java.util.Date)

Example 4 with EventInstanceVO

use of com.serotonin.m2m2.vo.event.EventInstanceVO in project ma-core-public by infiniteautomation.

the class EventInstanceDwr method silenceEvents.

/**
 * Silence all events from the current User Event Query
 * @return
 */
@DwrPermission(user = true)
public ProcessResult silenceEvents() {
    ProcessResult response = new ProcessResult();
    final User user = Common.getHttpUser();
    if (user != null) {
        final EventDao eventDao = EventDao.instance;
        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.isSilenced()) {
                    // If not silenced then do it.
                    eventDao.toggleSilence(vo.getId(), user.getId());
                    counter.increment();
                }
            }
        };
        EventInstanceDao.instance.exportQuery(queryData.getQuery(), queryData.getSort(), null, null, queryData.isOr(), callback);
        resetLastAlarmLevelChange();
        response.addGenericMessage("events.silencedEvents", counter.getCount());
    } else {
        response.addGenericMessage("events.silencedEvents", 0);
    }
    return response;
}
Also used : User(com.serotonin.m2m2.vo.User) EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) EventDao(com.serotonin.m2m2.db.dao.EventDao) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DojoQueryCallback(com.serotonin.m2m2.db.dao.DojoQueryCallback) ResultSetCounter(com.serotonin.m2m2.db.dao.ResultSetCounter) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 5 with EventInstanceVO

use of com.serotonin.m2m2.vo.event.EventInstanceVO 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;
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) User(com.serotonin.m2m2.vo.User) EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DojoQueryCallback(com.serotonin.m2m2.db.dao.DojoQueryCallback) ResultSetCounter(com.serotonin.m2m2.db.dao.ResultSetCounter) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

EventInstanceVO (com.serotonin.m2m2.vo.event.EventInstanceVO)7 User (com.serotonin.m2m2.vo.User)6 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 DojoQueryCallback (com.serotonin.m2m2.db.dao.DojoQueryCallback)3 ASTNode (net.jazdw.rql.parser.ASTNode)3 ResultSetCounter (com.serotonin.m2m2.db.dao.ResultSetCounter)2 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)2 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)2 QueryDataPageStream (com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream)2 InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)1 EventDao (com.serotonin.m2m2.db.dao.EventDao)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 EventInstance (com.serotonin.m2m2.rt.event.EventInstance)1 SpreadsheetEmporter (com.serotonin.m2m2.vo.emport.SpreadsheetEmporter)1 EventInstanceEmporter (com.serotonin.m2m2.vo.event.EventInstanceEmporter)1 QueryDefinition (com.serotonin.m2m2.web.dwr.QueryDefinition)1 QueryArrayStream (com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream)1 EventInstanceModel (com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventInstanceModel)1