com.kcs.action.FrfImpExpAction.java Source code

Java tutorial

Introduction

Here is the source code for com.kcs.action.FrfImpExpAction.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;

import static com.kcs.action.IrfImpExpAction.logger;
import com.kcs.core.actions.BaseAction;
import com.kcs.core.utilities.PaggingList;
import com.kcs.model.Datasetfrf;
import com.kcs.model.Datasetirf;
import com.kcs.service.DatasetFrfService;
import com.kcs.service.DatasetIrfService;
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.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author vorawats
 */
public class FrfImpExpAction extends BaseAction {
    static Logger logger = Logger.getLogger(FrfImpExpAction.class);
    private String dataSetDate;
    private PaggingList paging;
    private String systemCode;
    private int resultSize;
    private File toBeUploaded;
    private String fileName;
    private InputStream excelStream;

    @Autowired
    private DatasetFrfService datasetFrfService;
    private List<Datasetfrf> resultList;

    @Override
    public String success() throws Exception {
        searchMain();
        return SUCCESS;
    }

    @Override
    public String retrieve() throws Exception {
        searchMain();
        return SEARCH;
    }

    @Override
    public String export() throws Exception {
        // paging = datasetIrfService.findListIrf(createPaginate(), dataSetDate, systemCode);
        resultList = getDatasetFrfService().findMainList(dataSetDate, "");
        resultSize = resultList.size();
        logger.debug("exportExcel : begin...");
        logger.debug("exportExcel : list >>> " + resultSize);

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

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

            row.createCell(cellnum++).setCellValue("orgId");
            row.createCell(cellnum++).setCellValue("dataSetDate");
            row.createCell(cellnum++).setCellValue("loanDepsitTrnTye");
            row.createCell(cellnum++).setCellValue("currCode");
            row.createCell(cellnum++).setCellValue("paymentMethod");
            row.createCell(cellnum++).setCellValue("brOrBcFlg");
            row.createCell(cellnum++).setCellValue("commInLieuRate");
            row.createCell(cellnum++).setCellValue("minCommInLieu");
            row.createCell(cellnum++).setCellValue("maxCommInLieu");
            row.createCell(cellnum++).setCellValue("othFeeDesc");
            row.createCell(cellnum++).setCellValue("effectiveDate");
            row.createCell(cellnum++).setCellValue("endDate");
            row.createCell(cellnum++).setCellValue("seq");
            row.createCell(cellnum++).setCellValue("updBy");
            row.createCell(cellnum++).setCellValue("updDate");
            row.createCell(cellnum++).setCellValue("sysCode");

            for (Datasetfrf obj : resultList) {
                Row rowData = mySheet.createRow(rownum++);
                cellnum = 0;
                rowData.createCell(cellnum++).setCellValue(obj.getOrgId() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getDataSetDate() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getLoanDepsitTrnTye() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getCurrCode() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getPaymentMethod() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getBrOrBcFlg() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getCommInLieuRate() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getMinCommInLieu() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getMaxCommInLieu() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getOthFeeDesc() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getEffectiveDate() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getEndDate() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getSeq() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getUpdBy() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getUpdDate() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getSysCode() + "");
            }
        }

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

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

    private void searchMain() throws Exception {
        paging = getDatasetFrfService().findMainListPaging(createPaginate(), dataSetDate, systemCode);

        if (null == paging.getList()) {
            resultSize = 0;
        } else {
            resultSize = paging.getList().size();
        }

        System.out.println("result size" + resultSize);

    }

    public String getDataSetDate() {
        return dataSetDate;
    }

    public void setDataSetDate(String dataSetDate) {
        this.dataSetDate = dataSetDate;
    }

    public PaggingList getPaging() {
        return paging;
    }

    public void setPaging(PaggingList paging) {
        this.paging = paging;
    }

    /**
     * @return the systemCode
     */
    public String getSystemCode() {
        return systemCode;
    }

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

    /**
     * @return the resultSize
     */
    public int getResultSize() {
        return resultSize;
    }

    /**
     * @param resultSize the resultSize to set
     */
    public void setResultSize(int resultSize) {
        this.resultSize = resultSize;
    }

    /**
     * @return the resultList
     */
    public List<Datasetfrf> getResultList() {
        return resultList;
    }

    /**
     * @param resultList the resultList to set
     */
    public void setResultList(List<Datasetfrf> resultList) {
        this.resultList = resultList;
    }

    /**
     * @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 datasetFrfService
     */
    public DatasetFrfService getDatasetFrfService() {
        return datasetFrfService;
    }

    /**
     * @param datasetFrfService the datasetFrfService to set
     */
    public void setDatasetFrfService(DatasetFrfService datasetFrfService) {
        this.datasetFrfService = datasetFrfService;
    }

}