1 package org.openecomp.sdc.asdctool.migration.tasks.handlers;
3 import java.io.FileOutputStream;
4 import java.text.DateFormat;
5 import java.text.SimpleDateFormat;
7 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
8 import org.apache.poi.ss.usermodel.Cell;
9 import org.apache.poi.ss.usermodel.Row;
10 import org.apache.poi.ss.usermodel.Sheet;
11 import org.apache.poi.ss.usermodel.Workbook;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
15 public class XlsOutputHandler implements OutputHandler {
17 private final static Logger LOGGER = LoggerFactory.getLogger(XlsOutputHandler.class);
19 private Workbook workbook;
20 private Sheet activeSheet;
21 private Row currentRow;
24 public XlsOutputHandler(Object... title){
29 public void initiate(Object... title) {
30 LOGGER.info("Starting to initiate xls output handler. ");
31 workbook = new HSSFWorkbook();
32 activeSheet = workbook.createSheet("Upgrade Migration 1710.0 results");
34 LOGGER.info("Xls output handler has been initiated. ");
38 public void addRecord(Object... record) {
39 LOGGER.debug("Going to add record {} to output. ", record);
40 currentRow = activeSheet.createRow(rowCount++);
41 LOGGER.debug("A new row has been created");
44 for(Object cellValue : record){
45 cell = currentRow.createCell(columnCount++);
47 cell.setCellValue(cellValue.toString());
52 public boolean writeOutput() {
54 DateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss");
55 String fileName = "UpgradeMigration1710Results_" + df.format(System.currentTimeMillis()) + ".xls";
56 LOGGER.info("Going to write xls output file {}. ", fileName);
57 workbook.write(new FileOutputStream(fileName));
59 } catch (Exception e) {
60 LOGGER.error("Failed to write an output file upon Upgrade migration 1710. Exception {} occured. ", e);