com.kcs.action.OffImpExpAction.java Source code

Java tutorial

Introduction

Here is the source code for com.kcs.action.OffImpExpAction.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 com.kcs.core.actions.BaseAction;
import com.kcs.core.utilities.PaggingList;
import com.kcs.model.Datasetfrw;
import com.kcs.model.Datasetoff;
import com.kcs.service.DatasetOffService;
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 OffImpExpAction 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 DatasetOffService datasetOffService;
    private List<Datasetoff> resultList;

    @Override
    public String success() throws Exception {
        System.out.println("on success");
        retrieve();
        return SUCCESS;
    }

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

    @Override
    public String export() throws Exception {
        resultList = getDatasetOffService().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 OFF");
        setFileName("Export Data DS_OFF_" + 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("arrgmentTye");
            row.createCell(cellnum++).setCellValue("currCode");
            row.createCell(cellnum++).setCellValue("minimOpenAcctAmt");
            row.createCell(cellnum++).setCellValue("minimBalForMaintenanceFee");
            row.createCell(cellnum++).setCellValue("maintenanceFee");
            row.createCell(cellnum++).setCellValue("inactiveTerm");
            row.createCell(cellnum++).setCellValue("inactiveTermUnt");
            row.createCell(cellnum++).setCellValue("inactiveFee");
            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 (Datasetoff 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.getArrgmentTye() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getCurrCode() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getMinimOpenAcctAmt() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getMinimBalForMaintenanceFee() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getMaintenanceFee() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getInactiveTerm() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getInactiveTermUnt() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getInactiveFee() + "");
                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 DatasetOffService DatasetOffService() {
        return getDatasetOffService();
    }

    /**
     * @param datasetFrwDatasetOffServiceService the DatasetOffService to set
     */
    public void DatasetOffService(DatasetOffService DatasetOffService) {
        this.setDatasetOffService(getDatasetOffService());
    }

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

    /**
     * @param resultList the resultList to set
     */
    public void setResultList(List<Datasetoff> 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 datasetOffService
     */
    public DatasetOffService getDatasetOffService() {
        return datasetOffService;
    }

    /**
     * @param datasetOffService the datasetOffService to set
     */
    public void setDatasetOffService(DatasetOffService datasetOffService) {
        this.datasetOffService = datasetOffService;
    }

}