Search in sources :

Example 1 with QueryDefinition

use of com.serotonin.m2m2.web.dwr.QueryDefinition 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 2 with QueryDefinition

use of com.serotonin.m2m2.web.dwr.QueryDefinition 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)

Example 3 with QueryDefinition

use of com.serotonin.m2m2.web.dwr.QueryDefinition in project ma-core-public by infiniteautomation.

the class EventExportServlet method exportExcel.

/**
 * @param response
 * @param def
 * @param user
 * @throws IOException
 */
private void exportExcel(HttpServletResponse response, User user) throws IOException {
    // Stream the content.
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    final EventInstanceEmporter sheetEmporter = new EventInstanceEmporter();
    final SpreadsheetEmporter emporter = new SpreadsheetEmporter(FileType.XLSX);
    BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
    emporter.prepareExport(bos);
    emporter.prepareSheetExport(sheetEmporter);
    QueryDefinition queryData = (QueryDefinition) user.getAttribute("eventInstanceExportDefinition");
    DojoQueryCallback<EventInstanceVO> callback = new DojoQueryCallback<EventInstanceVO>(false) {

        @Override
        public void row(EventInstanceVO vo, int rowIndex) {
            sheetEmporter.exportRow(vo);
        }
    };
    EventInstanceDao.instance.exportQuery(queryData.getQuery(), queryData.getSort(), null, null, queryData.isOr(), callback);
    emporter.finishExport();
}
Also used : QueryDefinition(com.serotonin.m2m2.web.dwr.QueryDefinition) EventInstanceEmporter(com.serotonin.m2m2.vo.event.EventInstanceEmporter) EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) DojoQueryCallback(com.serotonin.m2m2.db.dao.DojoQueryCallback) SpreadsheetEmporter(com.serotonin.m2m2.vo.emport.SpreadsheetEmporter) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

DojoQueryCallback (com.serotonin.m2m2.db.dao.DojoQueryCallback)3 EventInstanceVO (com.serotonin.m2m2.vo.event.EventInstanceVO)3 ResultSetCounter (com.serotonin.m2m2.db.dao.ResultSetCounter)2 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)2 User (com.serotonin.m2m2.vo.User)2 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)2 EventDao (com.serotonin.m2m2.db.dao.EventDao)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 BufferedOutputStream (java.io.BufferedOutputStream)1