update dockers base version to 1.4.0
[sdc.git] / asdctool / src / main / java / org / openecomp / sdc / asdctool / migration / tasks / handlers / XlsOutputHandler.java
1 package org.openecomp.sdc.asdctool.migration.tasks.handlers;
2
3 import java.io.FileOutputStream;
4 import java.text.DateFormat;
5 import java.text.SimpleDateFormat;
6
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;
14
15 public class XlsOutputHandler implements OutputHandler {
16
17         private final static Logger LOGGER = LoggerFactory.getLogger(XlsOutputHandler.class);
18         
19         private Workbook workbook;
20         private Sheet activeSheet;
21         private Row currentRow;
22         int rowCount = 0;
23         
24         public XlsOutputHandler(Object... title){
25                 initiate(title);
26         }
27         
28         @Override
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");
33                 addRecord(title);
34                 LOGGER.info("Xls output handler has been initiated. ");
35         }
36
37         @Override
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");
42         int columnCount = 0;
43         Cell cell;
44         for(Object cellValue : record){
45             cell = currentRow.createCell(columnCount++);
46             if(cellValue != null)
47                 cell.setCellValue(cellValue.toString());
48         }
49         }
50
51         @Override
52         public boolean writeOutput() {
53         try {
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));
58                         return true;
59                 } catch (Exception e) {
60                         LOGGER.error("Failed to write an output file upon  Upgrade migration 1710. Exception {} occured. ", e);
61                         return false;
62                 }
63         }
64
65 }