Search in sources :

Example 1 with ArchivedProcessFailure

use of com.adobe.acs.commons.mcp.model.impl.ArchivedProcessFailure in project acs-aem-commons by Adobe-Consulting-Services.

the class ProcessErrorReportExcelServletTest method addFailure.

private void addFailure(String path, String error, String stacktrace) {
    ArchivedProcessFailure fail = new ArchivedProcessFailure();
    fail.error = error;
    fail.nodePath = path;
    fail.time = new Date();
    fail.stackTrace = stacktrace;
    failures.add(fail);
}
Also used : ArchivedProcessFailure(com.adobe.acs.commons.mcp.model.impl.ArchivedProcessFailure) Date(java.util.Date)

Example 2 with ArchivedProcessFailure

use of com.adobe.acs.commons.mcp.model.impl.ArchivedProcessFailure in project acs-aem-commons by Adobe-Consulting-Services.

the class ProcessErrorReportExcelServlet method createSpreadsheet.

@SuppressWarnings("squid:S3776")
protected Workbook createSpreadsheet(ManagedProcess report) {
    Workbook wb = new XSSFWorkbook();
    String name = report.getName();
    for (char ch : new char[] { '\\', '/', '*', '[', ']', ':', '?' }) {
        name = StringUtils.remove(name, ch);
    }
    Sheet sheet = wb.createSheet(name);
    sheet.createFreezePane(0, 1, 0, 1);
    Row headerRow = sheet.createRow(0);
    CellStyle headerStyle = createHeaderStyle(wb);
    CellStyle dateStyle = wb.createCellStyle();
    CreationHelper createHelper = wb.getCreationHelper();
    dateStyle.setDataFormat(createHelper.createDataFormat().getFormat("yyy/mm/dd h:mm:ss"));
    for (String columnName : Arrays.asList("Time", "Path", "Error", "Stack trace")) {
        Cell headerCell = headerRow.createCell(headerRow.getPhysicalNumberOfCells());
        headerCell.setCellValue(columnName);
        headerCell.setCellStyle(headerStyle);
    }
    Collection<ArchivedProcessFailure> rows = report.getReportedErrors();
    // make rows, don't forget the header row
    for (ArchivedProcessFailure error : rows) {
        Row row = sheet.createRow(sheet.getPhysicalNumberOfRows());
        Cell c;
        c = row.createCell(0);
        c.setCellValue(error.time);
        c.setCellStyle(dateStyle);
        c = row.createCell(1);
        c.setCellValue(error.nodePath);
        c = row.createCell(2);
        c.setCellValue(error.error);
        c = row.createCell(3);
        c.setCellValue(error.stackTrace);
    }
    autosize(sheet, 4);
    sheet.setAutoFilter(new CellRangeAddress(0, 1 + rows.size(), 0, 3));
    return wb;
}
Also used : CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Row(org.apache.poi.ss.usermodel.Row) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) CellStyle(org.apache.poi.ss.usermodel.CellStyle) ArchivedProcessFailure(com.adobe.acs.commons.mcp.model.impl.ArchivedProcessFailure) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook)

Aggregations

ArchivedProcessFailure (com.adobe.acs.commons.mcp.model.impl.ArchivedProcessFailure)2 Date (java.util.Date)1 Cell (org.apache.poi.ss.usermodel.Cell)1 CellStyle (org.apache.poi.ss.usermodel.CellStyle)1 CreationHelper (org.apache.poi.ss.usermodel.CreationHelper)1 Row (org.apache.poi.ss.usermodel.Row)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)1 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1