egovframework.oe1.cms.arc.web.EgovOe1ScrinController.java Source code

Java tutorial

Introduction

Here is the source code for egovframework.oe1.cms.arc.web.EgovOe1ScrinController.java

Source

/*
 * Copyright 2010 MOPAS(Ministry of Public Administration and Security).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package egovframework.oe1.cms.arc.web;

import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springmodules.validation.commons.DefaultBeanValidator;

import egovframework.oe1.cms.arc.service.EgovOe1ScrinService;
import egovframework.oe1.cms.arc.service.EgovOe1ScrinVO;
import egovframework.oe1.cms.com.service.EgovOe1CmmUseService;
import egovframework.oe1.cms.com.service.EgovOe1ComDefaultCodeVO;
import egovframework.oe1.cms.com.service.EgovOe1FileMngService;
import egovframework.oe1.cms.com.service.EgovOe1FileMngUtil;
import egovframework.oe1.cms.com.service.EgovOe1FileVO;
import egovframework.oe1.cms.com.service.EgovOe1LoginVO;
import egovframework.rte.fdl.excel.EgovExcelService;
import egovframework.rte.fdl.idgnr.EgovIdGnrService;
import egovframework.rte.fdl.property.EgovPropertyService;
import egovframework.rte.fdl.security.userdetails.util.EgovUserDetailsHelper;
import egovframework.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;

/**
 *    ?
 * 
 * @author ?1 
 * @since 2010.08.10
 * @version 1.0
 * @see
 *
 * <pre>
 *  == ?(Modification Information) ==
 *   
 *   ?      ?           
 *  -------    --------    ---------------------------
 *   2010.08.10             ?
 *
 * </pre>
 */
@Controller
public class EgovOe1ScrinController {

    protected Log log = LogFactory.getLog(this.getClass());

    /** EgovOe1ScrinService */
    @Resource(name = "egovOe1ScrinService")
    private EgovOe1ScrinService egovOe1ScrinService;

    /** EgovPropertyService */
    @Resource(name = "propertiesService")
    protected EgovPropertyService propertiesService;

    /** Validator */
    @Resource(name = "beanValidator")
    protected DefaultBeanValidator beanValidator;

    /**
     * 
     */
    /***/
    @Resource(name = "excelService")
    private EgovExcelService excelService;

    /**
     * ?
     */
    /** EgovFileMngService */
    @Resource(name = "EgovFileMngService")
    private EgovOe1FileMngService fileMngService;
    /**
     * ?
     */
    /** EgovFileMngUtil */
    @Resource(name = "EgovFileMngUtil")
    private EgovOe1FileMngUtil fileUtil;

    /**
     * IdGeneration
     */
    @Resource(name = "egovScrinMngIdGnrService")
    private EgovIdGnrService idGnrService;

    /** EgovCmmUseService */
    @Resource(name = "EgovCmmUseService")
    public EgovOe1CmmUseService egovCmmUseService;

    /**
     *  .
     * @param ?  scrinVO 
     * @return "forward:/cms/arc/selectScrin.do";
     * @exception Exception
     */
    @RequestMapping(value = "/cms/arc/removeScrin.do")
    public String deleteScrin(@ModelAttribute("scrinId") EgovOe1ScrinVO scrinVO, ModelMap model) throws Exception {

        // Spring Security
        Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
        if (!isAuthenticated) {
            return "/cms/com/EgovLoginUsr"; // ? ??
        }

        /* ?  ? ID  N  */
        if (!scrinVO.getAtchFileId().equals("")) {
            EgovOe1FileVO fileVo = new EgovOe1FileVO();
            fileVo.setAtchFileId(scrinVO.getAtchFileId());// ? ID
            fileMngService.deleteAllFileInf(fileVo);
        }

        egovOe1ScrinService.deleteScrin(scrinVO);
        return "forward:/cms/arc/selectScrin.do";
    }

    /**
     *  ? ??.
     * @param ?  scrinVO 
     * @return "/cms/arc/EgovScrinRegist";
     * @exception Exception
     */
    @RequestMapping(value = "/cms/arc/addScrinView.do")
    public String insertScrinView(@ModelAttribute("scrinVO") EgovOe1ScrinVO scrinVO, ModelMap model)
            throws Exception {

        //  .
        EgovOe1ComDefaultCodeVO sysVo = new EgovOe1ComDefaultCodeVO();
        sysVo.setCodeId("OE1031");
        List CompnSysCodeList = egovCmmUseService.selectCmmCodeDetail(sysVo);
        model.addAttribute("compnSysCodeList", CompnSysCodeList);

        //  .
        EgovOe1ComDefaultCodeVO vo = new EgovOe1ComDefaultCodeVO();
        vo.setCodeId("OE1030");
        List CompnCodeList = egovCmmUseService.selectCmmCodeDetail(vo);
        model.addAttribute("compnCodeList", CompnCodeList);

        return "/cms/arc/EgovScrinRegist";
    }

    /**
     *  ?.
     * @param ?  scrinVO , multiRequest
     * @return "forward:/cms/arc/selectScrin.do";
     * @exception Exception
     */
    @RequestMapping(value = "/cms/arc/addScrin.do")
    public String insertScrin(final MultipartHttpServletRequest multiRequest,
            @ModelAttribute("scrinVO") EgovOe1ScrinVO scrinVO, ModelMap model, SessionStatus status)
            throws Exception {

        // Spring Security
        Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
        if (!isAuthenticated) {
            return "/cms/com/EgovLoginUsr"; // ? ??
        }

        // 
        EgovOe1LoginVO user = (EgovOe1LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
        scrinVO.setFrstRegisterId(user.getMberId());

        /** ?  */
        List<EgovOe1FileVO> _result = null;
        String _atchFileId = "";
        final Map<String, MultipartFile> files = multiRequest.getFileMap();
        if (!files.isEmpty()) {
            _result = fileUtil.parseFileInf(files, "", 0, "", "");
            _atchFileId = fileMngService.insertFileInfs(_result); // ?? ??
            // ?? ?
            // ID .
        }
        scrinVO.setAtchFileId(_atchFileId);

        // IDd
        scrinVO.setScrinId(idGnrService.getNextStringId());
        //   ?
        egovOe1ScrinService.insertScrin(scrinVO);

        return "forward:/cms/arc/selectScrin.do";
    }

    /**
     *  ?.
     * @param ?  scrinVO
     * @return "/cms/arc/EgovScrinDetail";
     * @exception Exception
     */
    @RequestMapping(value = "/cms/arc/getScrin.do")
    public String selectScrin(@ModelAttribute("scrinVO") EgovOe1ScrinVO scrinVO, ModelMap model) throws Exception {

        //  .
        EgovOe1ComDefaultCodeVO sysVo = new EgovOe1ComDefaultCodeVO();
        sysVo.setCodeId("OE1031");
        List CompnSysCodeList = egovCmmUseService.selectCmmCodeDetail(sysVo);
        model.addAttribute("compnSysCodeList", CompnSysCodeList);

        //  .
        EgovOe1ComDefaultCodeVO vo = new EgovOe1ComDefaultCodeVO();
        vo.setCodeId("OE1030");
        List CompnCodeList = egovCmmUseService.selectCmmCodeDetail(vo);
        model.addAttribute("compnCodeList", CompnCodeList);

        EgovOe1ScrinVO resultVO = new EgovOe1ScrinVO();

        resultVO = egovOe1ScrinService.selectScrin(scrinVO);

        EgovOe1FileVO fileVO = new EgovOe1FileVO();

        String _atchFileId = resultVO.getAtchFileId();//  ? ? ? ?
        // ? ID .
        fileVO.setAtchFileId(_atchFileId);
        List<EgovOe1FileVO> result = fileMngService.selectFileInfs(fileVO);

        //  ??  _atchFileId? ? 
        if (result.isEmpty()) {
            resultVO.setAtchFileId("");
        }

        model.addAttribute("scrinVO", resultVO);

        // ? ?  ?    
        List serviceList = egovOe1ScrinService.selectFunctionList(scrinVO);
        model.addAttribute("resultlist", serviceList);

        return "/cms/arc/EgovScrinDetail";
    }

    /**
     *  ?? .
     * @param ?  scrinVO
     * @return "/cms/arc/EgovScrinList";
     * @exception Exception
     */
    @RequestMapping(value = "/cms/arc/selectScrin.do")
    public String selectScrinList(@ModelAttribute("scrinVO") EgovOe1ScrinVO scrinVO, ModelMap model)
            throws Exception {

        /** EgovPropertyService.sample */
        scrinVO.setPageUnit(propertiesService.getInt("pageUnit"));
        scrinVO.setPageSize(propertiesService.getInt("pageSize"));

        /** pageing setting */
        PaginationInfo paginationInfo = new PaginationInfo();
        paginationInfo.setCurrentPageNo(scrinVO.getPageIndex());
        paginationInfo.setRecordCountPerPage(scrinVO.getPageUnit());
        paginationInfo.setPageSize(scrinVO.getPageSize());

        scrinVO.setFirstIndex(paginationInfo.getFirstRecordIndex());
        scrinVO.setLastIndex(paginationInfo.getLastRecordIndex());
        scrinVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage());

        List serviceList = egovOe1ScrinService.selectScrinList(scrinVO);

        model.addAttribute("resultList", serviceList);

        int totCnt = egovOe1ScrinService.selectScrinListTot(scrinVO);
        paginationInfo.setTotalRecordCount(totCnt);
        model.addAttribute("paginationInfo", paginationInfo);

        return "/cms/arc/EgovScrinList";
    }

    /**
     *  .
     * @param ?  scrinVO, multiRequest
     * @return "forward:/cms/arc/getScrin.do";
     * @exception Exception
     */
    @RequestMapping(value = "/cms/arc/updtScrin.do")
    public String updateScrin(final MultipartHttpServletRequest multiRequest,
            @ModelAttribute("scrinVO") EgovOe1ScrinVO scrinVO, ModelMap model) throws Exception {

        try {

            String _atchFileId = scrinVO.getAtchFileId();//  ? ? ?
            // ? ? ID .
            final Map<String, MultipartFile> files = multiRequest.getFileMap();
            if (!files.isEmpty()) {
                if ("".equals(_atchFileId) || _atchFileId == null) {
                    List<EgovOe1FileVO> _result = fileUtil.parseFileInf(files, "", 0, _atchFileId, "");
                    _atchFileId = fileMngService.insertFileInfs(_result); // ?
                    // ?
                    // ID
                    // .
                    scrinVO.setAtchFileId(_atchFileId); //   ? ? ??
                    // ? ID  .
                } else {
                    EgovOe1FileVO fvo = new EgovOe1FileVO();
                    fvo.setAtchFileId(_atchFileId); //  ? ? ??  VO? 
                    // ? ID .
                    int _cnt = fileMngService.getMaxFileSN(fvo); //  ? ID?
                    // ?  ?
                    // ? ??.
                    List<EgovOe1FileVO> _result = fileUtil.parseFileInf(files, "", _cnt, _atchFileId, "");
                    fileMngService.updateFileInfs(_result);
                }
            }

            // Spring Security
            Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
            if (!isAuthenticated) {
                return "/cms/com/EgovLoginUsr"; // ? ??
            }

            // 
            EgovOe1LoginVO user = (EgovOe1LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
            scrinVO.setFrstRegisterId(user.getMberId());

            egovOe1ScrinService.updateScrin(scrinVO);

            model.addAttribute("resultMsg", "?.");

            // status.setComplete();
            return "forward:/cms/arc/getScrin.do";
        } catch (Exception ex) {
            // ex.printStackTrace();
            throw ex;
        }

    }

    /**
     *  ? ??.
     * @param ?  scrinVO
     * @return "/cms/arc/EgovExcelScrinRegist";
     * @exception Exception
     */
    @RequestMapping(value = "/cms/arc/addExcelScrinView.do")
    public String insertExcelScrinView(@ModelAttribute("scrinVO") EgovOe1ScrinVO scrinVO, ModelMap model)
            throws Exception {
        return "/cms/arc/EgovExcelScrinRegist";
    }

    /**
     * ??   ?.
     * @param ?  scrinVO, request, model
     * @return forward:/cms/arc/selectScrin.do";
     * @exception Exception
     */
    @RequestMapping(value = "/cms/arc/excelScrinRegist.do")
    public String insertExcelScrin(@ModelAttribute("scrinVO") EgovOe1ScrinVO scrinVO,
            final HttpServletRequest request, Map commandMap, Model model) throws Exception {

        // Spring Security
        Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
        if (!isAuthenticated) {
            return "/cms/com/EgovLoginUsr"; // ? ??
        }

        // 
        EgovOe1LoginVO user = (EgovOe1LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
        scrinVO.setFrstRegisterId(user.getMberId());

        String sCmd = commandMap.get("cmd") == null ? "" : (String) commandMap.get("cmd");
        if (sCmd.equals("")) {
            return "/cms/arc/EgovExcelScrinRegist";
        }
        final MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
        final Map<String, MultipartFile> files = multiRequest.getFileMap();

        Iterator<Entry<String, MultipartFile>> itr = files.entrySet().iterator();
        MultipartFile file;

        while (itr.hasNext()) {
            Entry<String, MultipartFile> entry = itr.next();

            file = entry.getValue();
            if (!"".equals(file.getOriginalFilename())) {
                // ? ??    .
                egovOe1ScrinService.deleteExcelScrin();

                InputStream is = null;
                try {
                    is = file.getInputStream();
                    excelService.uploadExcel("egovOe1ScrinDAO.inserExceltScrin", is, 4);
                } catch (Exception e) {
                    throw e;
                } finally {
                    try {
                        if (is != null) {
                            is.close();
                        }
                    } catch (Exception e) {
                        // log none
                        log.info(e.getMessage());
                    }
                }
            }
        }

        return "forward:/cms/arc/selectScrin.do";
    }

}