com.kcs.action.FrwImpExpAction.java Source code

Java tutorial

Introduction

Here is the source code for com.kcs.action.FrwImpExpAction.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.FrfImpExpAction.logger;
import com.kcs.core.actions.BaseAction;
import com.kcs.core.utilities.PaggingList;
import com.kcs.model.Datasetfrf;
import com.kcs.model.Datasetfrw;
import com.kcs.service.DatasetFrwService;
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;

public class FrwImpExpAction extends BaseAction {
    private static Logger logger = Logger.getLogger(FrfImpExpAction.class);

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

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

    private String dataSetDate;
    private PaggingList paging;
    private String systemCode;
    private int resultSize;
    private File toBeUploaded;
    private String fileName;
    private InputStream excelStream;
    @Autowired
    private DatasetFrwService datasetFrwService;
    private List<Datasetfrw> resultList;

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

    @Override
    public String retrieve() throws Exception {
        paging = getDatasetFrwService().findMainListPaging(createPaginate(), getDataSetDate(), "");
        if (null == paging.getList()) {
            resultSize = 0;
        } else {
            resultSize = paging.getList().size();
        }
        return SEARCH;
    }

    @Override
    public String export() throws Exception {

        resultList = datasetFrwService.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 FRW");
        setFileName("Export Data DS_FRW_" + 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("currCode");
            row.createCell(cellnum++).setCellValue("commInLieuRateForDepsit");
            row.createCell(cellnum++).setCellValue("minCommInLieuForDepsit");
            row.createCell(cellnum++).setCellValue("maxCommInLieuForDepsit");
            row.createCell(cellnum++).setCellValue("inwTransfFeeForDepsit");
            row.createCell(cellnum++).setCellValue("minInwTransfFeeForDepsit");
            row.createCell(cellnum++).setCellValue("maxInwTransfFeeForDepsit");
            row.createCell(cellnum++).setCellValue("othFeeDescForDepsit");
            row.createCell(cellnum++).setCellValue("commInLieuRateForWithdw");
            row.createCell(cellnum++).setCellValue("minCommInLieuRateFWithdw");
            row.createCell(cellnum++).setCellValue("maxCommInLieuRateFWithdw");
            row.createCell(cellnum++).setCellValue("withdwFeeForOthTransf");
            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 (Datasetfrw 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.getCurrCode() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getCommInLieuRateForDepsit() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getMinCommInLieuForDepsit() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getMaxCommInLieuForDepsit() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getInwTransfFeeForDepsit() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getMinInwTransfFeeForDepsit() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getMaxInwTransfFeeForDepsit() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getOthFeeDescForDepsit() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getCommInLieuRateForWithdw() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getMinCommInLieuRateFWithdw() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getMaxCommInLieuRateFWithdw() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getWithdwFeeForOthTransf() + "");
                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";
    }

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

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

    /**
     * @return the paging
     */
    public PaggingList getPaging() {
        return paging;
    }

    /**
     * @param paging the paging to set
     */
    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 datasetFrwService
     */
    public DatasetFrwService getDatasetFrwService() {
        return datasetFrwService;
    }

    /**
     * @param datasetFrwService the datasetFrwService to set
     */
    public void setDatasetFrwService(DatasetFrwService datasetFrwService) {
        this.datasetFrwService = datasetFrwService;
    }

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

    /**
     * @param resultList the resultList to set
     */
    public void setResultList(List<Datasetfrw> 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;
    }

}