Search in sources :

Example 1 with EventInstanceEmporter

use of com.serotonin.m2m2.vo.event.EventInstanceEmporter 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)1 SpreadsheetEmporter (com.serotonin.m2m2.vo.emport.SpreadsheetEmporter)1 EventInstanceEmporter (com.serotonin.m2m2.vo.event.EventInstanceEmporter)1 EventInstanceVO (com.serotonin.m2m2.vo.event.EventInstanceVO)1 QueryDefinition (com.serotonin.m2m2.web.dwr.QueryDefinition)1 BufferedOutputStream (java.io.BufferedOutputStream)1