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;
}
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;
}
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();
}
Aggregations