com.kcs.action.report.MaturitySummaryAction.java Source code

Java tutorial

Introduction

Here is the source code for com.kcs.action.report.MaturitySummaryAction.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kcs.action.report;

import com.kcs.core.actions.BaseAction;
import com.kcs.core.utilities.DateUtil;
import com.kcs.model.Journal;
import com.kcs.model.Maturity;
import com.kcs.service.JournalService;
import com.kcs.service.MaturityService;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author LENOVO
 */
public class MaturitySummaryAction extends BaseAction {
    private Logger logger = Logger.getLogger(this.getClass());
    private String dataSetDate;
    private List<Maturity> list;

    private File toBeUploaded;
    private String fileName;
    private InputStream excelStream;

    @Autowired
    private MaturityService service;

    @Override
    public String success() throws Exception {
        setDataSetDate(getService().getBotDate());
        return SUCCESS;
    }

    public String report() throws Exception {
        try {
            getLogger().debug("Report : begin...");
            getLogger().debug("Criteria : dataSetDate >>> " + getDataSetDate() + "  Convert >>> "
                    + DateUtil.convertDateFromJsp(getDataSetDate()));
            setList(getService().findMaturitySummaryByCriteria(DateUtil.convertDateFromJsp(getDataSetDate())));
            getLogger().debug("Report : end...");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return REPORT;
    }

    public String print() throws Exception {
        try {
            getLogger().debug("Print : begin...");
            getLogger().debug("Criteria : dataSetDate >>> " + getDataSetDate() + "  Convert >>> "
                    + DateUtil.convertDateFromJsp(getDataSetDate()));
            setList(getService().findMaturitySummaryByCriteria(DateUtil.convertDateFromJsp(getDataSetDate())));
            getLogger().debug("Print : end...");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "print";
    }

    @Override
    public String export() throws Exception {

        setList(getService().findMaturitySummaryByCriteria(DateUtil.convertDateFromJsp(getDataSetDate())));

        getLogger().debug("exportExcel : begin...");
        getLogger().debug("exportExcel : list >>> " + getList());

        DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
        HSSFWorkbook myWorkBook = new HSSFWorkbook();
        HSSFSheet mySheet = myWorkBook.createSheet("Journal");
        setFileName("Export Data Maturity (Summary) " + dateFormat.format(new Date()) + "excel".concat(".xls"));

        if (null != getList() && getList().size() > 0) {
            int rownum = 0;
            Row row = mySheet.createRow(rownum++);
            int cellnum = 0;

            row.createCell(cellnum++).setCellValue("MaturityGroup");
            row.createCell(cellnum++).setCellValue("Ccy");
            row.createCell(cellnum++).setCellValue("BuyAmt");
            row.createCell(cellnum++).setCellValue("SellAmt");
            row.createCell(cellnum++).setCellValue("TranType");
            row.createCell(cellnum++).setCellValue("Proc Date");

            for (Maturity obj : getList()) {
                Row rowData = mySheet.createRow(rownum++);
                cellnum = 0;
                rowData.createCell(cellnum++).setCellValue(obj.getMATURITY_GROUP() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getCCY() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getBUY_AMT() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getSELL_AMT() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getTRANS_TYPE() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getPROC_DATE() + "");
            }
            for (int j = 0; j < cellnum; j++) {
                mySheet.autoSizeColumn(j);
            }
        }

        ByteArrayOutputStream boas = new ByteArrayOutputStream();
        myWorkBook.write(boas);
        setExcelStream(new ByteArrayInputStream(boas.toByteArray()));

        getLogger().debug("exportExcel : end...");
        return "excel";
    }

    /**
     * @return the logger
     */
    public Logger getLogger() {
        return logger;
    }

    /**
     * @param logger the logger to set
     */
    public void setLogger(Logger logger) {
        this.logger = logger;
    }

    /**
     * @return the dataSetDate
     */
    public String getDataSetDate() {
        return dataSetDate;
    }

    /**
     * @param dataSetDate the dataSetDate to set
     */
    public void setDataSetDate(String dataSetDate) {
        this.dataSetDate = dataSetDate;
    }

    /**
     * @return the toBeUploaded
     */
    public File getToBeUploaded() {
        return toBeUploaded;
    }

    /**
     * @param toBeUploaded the toBeUploaded to set
     */
    public void setToBeUploaded(File toBeUploaded) {
        this.toBeUploaded = toBeUploaded;
    }

    /**
     * @return the fileName
     */
    public String getFileName() {
        return fileName;
    }

    /**
     * @param fileName the fileName to set
     */
    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    /**
     * @return the excelStream
     */
    public InputStream getExcelStream() {
        return excelStream;
    }

    /**
     * @param excelStream the excelStream to set
     */
    public void setExcelStream(InputStream excelStream) {
        this.excelStream = excelStream;
    }

    /**
     * @return the service
     */
    public MaturityService getService() {
        return service;
    }

    /**
     * @param service the service to set
     */
    public void setService(MaturityService service) {
        this.service = service;
    }

    /**
     * @return the list
     */
    public List<Maturity> getList() {
        return list;
    }

    /**
     * @param list the list to set
     */
    public void setList(List<Maturity> list) {
        this.list = list;
    }

}