com.kcs.action.ImportExportDsDipAction.java Source code

Java tutorial

Introduction

Here is the source code for com.kcs.action.ImportExportDsDipAction.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.DateUtil;
import com.kcs.core.utilities.PaggingList;
import com.kcs.core.utilities.Utility;
import com.kcs.model.Datasetdip;
import com.kcs.model.Datasetirf;
import com.kcs.model.PositionReport;
import com.kcs.service.DatasetDipService;
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.Row;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author LENOVO
 */
public class ImportExportDsDipAction extends BaseAction {

    private static Logger logger = Logger.getLogger(ImportExportDsDipAction.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;
    private List<Datasetdip> resultList;

    @Autowired
    private DatasetDipService service;

    @Override
    public String success() throws Exception {
        dataSetDate = service.getMaxDateDsDip();
        if (Utility.isNull(getPaging())) {
            setPaging(new PaggingList());
        }
        search();
        return SUCCESS;

    }

    @Override
    public String search() throws Exception {
        paging = service.findByCriteriaService(createPaginate(),
                DateUtil.getDateFromString(getDataSetDate(), DateUtil.DEFAULT_DATE_FORMAT), "");
        resultSize = paging.getList().size();

        return SEARCH;
    }

    @Override
    public String export() throws Exception {
        resultList = service.findByCriteriaServiceList(DateUtil.convertDateFromJsp(getDataSetDate()), "");
        getLogger().debug("exportExcel : begin...");
        getLogger().debug("exportExcel : list >>> " + resultList.size());

        DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
        HSSFWorkbook myWorkBook = new HSSFWorkbook();
        HSSFSheet mySheet = myWorkBook.createSheet("DS_DIP");
        setFileName("DS_DIP_" + 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("DataPvdrBrcNo");
            row.createCell(cellnum++).setCellValue("FiRptGrp");
            row.createCell(cellnum++).setCellValue("DataSetDate");
            row.createCell(cellnum++).setCellValue("ItemType");
            row.createCell(cellnum++).setCellValue("ItemDesc");
            row.createCell(cellnum++).setCellValue("CtryId");
            row.createCell(cellnum++).setCellValue("Curr");
            row.createCell(cellnum++).setCellValue("Amt");
            row.createCell(cellnum++).setCellValue("UpdDate");
            row.createCell(cellnum++).setCellValue("UpdBy");
            row.createCell(cellnum++).setCellValue("SysCode");
            row.createCell(cellnum++).setCellValue("Seq");
            row.createCell(cellnum++).setCellValue("CustCode");

            for (Datasetdip obj : resultList) {
                Row rowData = mySheet.createRow(rownum++);
                cellnum = 0;
                rowData.createCell(cellnum++).setCellValue(obj.getOrgId() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getDataPvdrBrcNo() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getFiRptGrp() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getDataSetDate() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getItemType() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getItemDesc() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getCtryId() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getCurr() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getAmt() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getUpdDate() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getUpdBy() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getSysCode() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getSeq() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getCustCode() + "");
            }

            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 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 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 resultList
     */
    public List<Datasetdip> getResultList() {
        return resultList;
    }

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

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

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

}