com.fota.fota3g.deviceSetupMgt.controller.FrimwareMgtCTR.java Source code

Java tutorial

Introduction

Here is the source code for com.fota.fota3g.deviceSetupMgt.controller.FrimwareMgtCTR.java

Source

/*
 * M2M ServiceFOTA ONM version 1.0
 *
 *  Copyright  2014 kt corp. All rights reserved.
 *
 *  This is a proprietary software of kt corp, and you may not use this file except in
 *  compliance with license agreement with kt corp. Any redistribution or use of this
 *  software, with or without modification shall be strictly prohibited without prior written
 *  approval of kt corp, and the copyright notice above does not evidence any actual or
 *  intended publication of such software.
 */
package com.fota.fota3g.deviceSetupMgt.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJacksonJsonView;

import com.fota.comm.util.FileDownloadManager;
import com.fota.comm.util.Masking;
import com.fota.comm.util.VoV;
import com.fota.commMgt.vo.UserLoginVO;
import com.fota.fota3g.comm.util.CommUtil;
import com.fota.fota3g.comm.vo.ThreeFotaDevVo;
//import com.fota.fota3g.devMgt.service.DevMgtAdvSVC;
import com.fota.fota3g.deviceSetupMgt.service.FirmwareMgtSVC;
import com.fota.fota3g.deviceSetupMgt.vo.FirmwareMgtBaseInfoVo;
import com.fota.fota3g.deviceSetupMgt.vo.FirmwareMgtDetailHistoryVo;
import com.fota.fota3g.deviceSetupMgt.vo.FirmwareMgtDiffPackageDetailVo;
import com.fota.fota3g.deviceSetupMgt.vo.FirmwareMgtDiffPackageListVo;
import com.fota.fota3g.deviceSetupMgt.vo.FirmwareMgtViewVo;
//import antlr.collections.List;
import com.oreilly.servlet.MultipartRequest;

@Controller
@RequestMapping("/commonDevice")
public class FrimwareMgtCTR {

    private static final Logger logger = LoggerFactory.getLogger(FrimwareMgtCTR.class);

    /**
     * @uml.property  name="firmMgtSVC"
     * @uml.associationEnd  readOnly="true"
     */
    @Autowired
    FirmwareMgtSVC firmMgtSVC;

    /**
     * @uml.property  name="ajaxMainView"
     * @uml.associationEnd  readOnly="true"
     */
    @Autowired
    private MappingJacksonJsonView ajaxMainView;

    //   String gDetailModel = "";
    //   String gDetailVersion = "";
    //   String gDetailOsVersion = "";

    private static final String gSaveFilePath = "/firmwareDiff/";
    //   private static final String gSaveFilePath = "/jb_log/pkg_tmp/";

    //   private static final String gPath = gSaveFilePath + "realFile/";

    // ?? : 100M
    private static final int MAX_FILE_SIZE = 100 * 1024 * 1024;

    /**
     *  firmware 
     * @param request
     * @param model / maker
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deviceSetup/FirmwareMgt")
    public String getView(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
        if (!request.getServletPath().equals("/commonDevice/deviceSetup/FirmwareMgt")) {
            response.setStatus(403);
            return "redirect:/lresources/errorPage.jsp";
        }

        return "fota3g/deviceSetupMgt/FirmwareMgtView";
    }

    /**
     * firmware 
     * @param request
     * @param model / maker
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deviceSetup/getFirmwareMgtList")
    @ResponseBody
    public ModelAndView search(@ModelAttribute("ThreeFotaDevVo") ThreeFotaDevVo vo, ModelMap model)
            throws Exception {
        //      logger.warn(" >>>>> FirmwareMgtCTR - search() - vo data\r\n"
        //            + "maker : " + vo.getMaker() + "\r\n"
        //            + "firmwareVersion : " + vo.getFirmwareVersion() + "\r\n"
        //            + "model : " + vo.getModel() + "\r\n"
        //            + "page / rowsPerPage : " + vo.getPage() + " / " + vo.getRowsPerPage()
        //      );

        List fotaFirmwareMgtResultList = firmMgtSVC.getFirmwareMgtListResultHashMapList(vo);
        // {approved_cnt=0, last_yn= , model=GMM-W21x, firmware_version=GMM-W21x-KT.STD.023@01.00, 
        // profile_name=GMM-W21x-KT.STD.023@01.00, rnum=276, diff_cnt=1, maker=, last_version_yn=null}

        //      logger.warn("fotaFirmwareMgtResultList size : " + fotaFirmwareMgtResultList.size());
        //      logger.warn("-------------------------------------------------------------------------------------------");
        //      for(int i=0; i<fotaFirmwareMgtResultList.size(); i++) {
        //         logger.warn("fotaFirmwareMgtResultList[" + i + "] : " + fotaFirmwareMgtResultList.get(i).toString());
        //      }

        // 3g-fota -> service fota  
        List<FirmwareMgtViewVo> firmwareMgtViewList = changeServiceFotaViewData(fotaFirmwareMgtResultList, 0);

        // ??   ? 
        int totalCount = firmMgtSVC.getFirmwareMgtResultListTotalCount(vo);
        int totalPage = totalCount / Integer.valueOf(vo.getRowsPerPage());
        if (totalCount % Integer.valueOf(vo.getRowsPerPage()) != 0)
            totalPage++;

        //      logger.warn("toalPage : " + totalPage + " / totalCount : " + totalCount);

        model.addAttribute("gridData", firmwareMgtViewList);
        model.addAttribute("page", vo.getPage());
        model.addAttribute("totalPage", totalPage);

        return new ModelAndView(ajaxMainView, model);
    }

    /**
     * firmware 
     * @param request
     * @param model / maker
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deviceSetup/getFirmwareMgtBaseInfo")
    @ResponseBody
    public ModelAndView searchBaseInfo(@ModelAttribute("ThreeFotaDevVo") ThreeFotaDevVo vo, ModelMap model)
            throws Exception {
        //      logger.warn(" >>>>> getFirmwareMgtBaseInfo - search() - vo data\r\n"
        //            + "maker : " + vo.getMaker() + "\r\n"
        //            + "firmwareVersion : " + vo.getFirmwareVersion() + "\r\n"
        //            + "model : " + vo.getModel() + "\r\n");      

        List fotaFirmwareMgtResultList = firmMgtSVC.getFirmwareMgtListResultHashMapList(vo);

        //      logger.warn("fotaFirmwareMgtResultList size : " + fotaFirmwareMgtResultList.size());
        //      for(int i=0; i<fotaFirmwareMgtResultList.size(); i++) {
        //         logger.warn("fotaFirmwareMgtResultList[" + i + "] : " + fotaFirmwareMgtResultList.get(i).toString());
        //      }

        // 3g-fota -> service fota  
        List<FirmwareMgtViewVo> firmwareMgtViewList = changeServiceFotaViewData(fotaFirmwareMgtResultList, 1);

        //      model.addAttribute("baseInfoGridData", firmwareMgtViewList);
        model.addAttribute("maker", firmwareMgtViewList.get(0).getMaker());
        model.addAttribute("model", firmwareMgtViewList.get(0).getModel());
        model.addAttribute("profile", firmwareMgtViewList.get(0).getFirmwareDiffName());
        model.addAttribute("version", firmwareMgtViewList.get(0).getFirmwareVersion());
        model.addAttribute("document", firmwareMgtViewList.get(0).getDocument());
        model.addAttribute("firmwareType", firmwareMgtViewList.get(0).getFirmwareType());
        model.addAttribute("osVersion", firmwareMgtViewList.get(0).getOsVersion());

        return new ModelAndView(ajaxMainView, model);
    }

    // sFlag  1? base info 
    public List<FirmwareMgtViewVo> changeServiceFotaViewData(List resultList, int sFlag) {
        List<FirmwareMgtViewVo> firmwareMgtViewList = null;

        // resultList  
        // {approved_cnt=0, last_yn= , model=GMM-W21x, firmware_version=GMM-W21x-KT.STD.023@01.00, 
        // profile_name=GMM-W21x-KT.STD.023@01.00, rnum=276, diff_cnt=1, maker=, last_version_yn=null}
        // ? ?
        if (resultList.size() > 0) {
            firmwareMgtViewList = new ArrayList<FirmwareMgtViewVo>();

            HashMap tempResultListMap = null;
            FirmwareMgtViewVo tempViewVo = null;

            String tempPkg = "";
            for (int i = 0; i < resultList.size(); i++) {
                tempResultListMap = (HashMap) resultList.get(i);

                tempViewVo = new FirmwareMgtViewVo();
                tempViewVo.setFirmwareType(tempResultListMap.get("firmware_type").toString());
                tempViewVo.setMaker(tempResultListMap.get("maker").toString());
                tempViewVo.setModel(tempResultListMap.get("model").toString());
                tempViewVo.setFirmwareDiffName(tempResultListMap.get("profile_name").toString());
                tempViewVo.setFirmwareVersion(tempResultListMap.get("firmware_version").toString());
                if (sFlag == 1) {
                    tempViewVo.setDocument(tempResultListMap.get("description").toString());
                }

                tempPkg = tempResultListMap.get("approved_cnt").toString() + " ("
                        + tempResultListMap.get("diff_cnt").toString() + ")";
                tempViewVo.setPackageCnt(tempPkg);
                tempViewVo.setOsVersion(tempResultListMap.get("os_version").toString());

                firmwareMgtViewList.add(tempViewVo);
            } // end of for(int i=0; i<resultList.size(); i++)

        } // end of if(resultList.size() > 0)

        return firmwareMgtViewList;
    }

    /**
     * DeviceSetup - FirmwareMgtInsert
     * @param model/maker/profile/version/document
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deviceSetup/FirmwareMgtInsert")
    @ResponseBody
    public ModelAndView regFirmwareInfo(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute("FirmwareMgtBaseInfoVo") FirmwareMgtBaseInfoVo vo, ModelMap model) throws Exception {
        int retValue = -2, retValueProfile = -2;
        String regMaker = VoV.replaceRoundBracket(vo.getMaker());
        vo.setMaker(regMaker); // ?  
        //      logger.warn(">>>firmwareMgtInsert : "
        //            + "loginid : " + vo.getLoginId() + "\r\n "
        //            + "maker : " + vo.getMaker() + "\r\n "
        //            + "model : " + vo.getModel() + "\r\n"
        //            + "type : " + vo.getFirmwareType() + "\r\n"
        //            + "profile : " + vo.getProfile() + "\r\n"
        //            + "version : " + vo.getVersion() + "\r\n"
        //            + "description : " + vo.getDescription()
        //      );

        // ? ?  db ? default  '-'  
        if (vo.getVersion().isEmpty()) {
            vo.setVersion("-");
        }
        if (vo.getOsVersion().isEmpty()) {
            vo.setOsVersion("-");
        }

        // insert  ?  
        retValue = firmMgtSVC.insertCheckFirmwareBaseInfo(vo);
        // ? 
        if (retValue == 0) {
            //         logger.warn("insert possible!!!!");

            // firmware base info 
            retValue = firmMgtSVC.setFirmwareBaseInfo(vo);
            //         logger.warn("insert ret value : " + retValue);

            if (retValue == -1) {
                //            logger.warn(">>>firmwareMgtInsert Fail....");
            } else {
                //  TBL_FIRMWARE insert  ?, TBL_DEVICE_PROFILE ? insert 
                vo.setProfileId(CommUtil.getUniqueNumber() + ""); // profile id 
                vo.setDdfId("0");
                //            logger.warn(">>>setDeviceProfileInfo : profileId : " + vo.getProfileId());
                retValueProfile = firmMgtSVC.setDeviceProfileInfo(vo);
            }
        } else {
            retValue = -10;
            //         logger.warn("already exist this firmware info...... so... not inserted");
        }

        //      logger.warn("retValue : " + retValue + " / retValueProfile : " + retValueProfile);

        model.addAttribute("retValue", retValue);
        model.addAttribute("retValueProfile", retValueProfile);

        return new ModelAndView(ajaxMainView, model);
    }

    /**
     *  ? ?  view 
     * @param vo
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deviceSetup/FirmwareMgtDetailView")
    @ResponseBody
    public ModelAndView firmDetailView(HttpServletRequest request, HttpServletResponse response,
            //                        @ModelAttribute("FirmwareMgtBaseInfoVo") FirmwareMgtBaseInfoVo vo,
            Model model) throws Exception {
        //      logger.warn("param key 1 : " + request.getParameter("key"));
        //      String key = new String(request.getParameter("key").getBytes("8859_1"), "UTF-8");
        //      logger.warn("param key 2 : " + key);
        //      String[] keySplit = key.split("\\^");

        //      gDetailModel = new String(request.getParameter("model").getBytes("8859_1"), "UTF-8");
        //      gDetailVersion = new String(request.getParameter("version").getBytes("8859_1"), "UTF-8");
        //      gDetailOsVersion = new String(request.getParameter("os").getBytes("8859_1"), "UTF-8");

        //      gDetailModel = keySplit[0];
        //      gDetailVersion = keySplit[1];
        //      gDetailOsVersion = keySplit[2];

        //      logger.warn(" >> key split data ....\r\n"
        //            + "gDetailModel : " + gDetailModel + "\r\n"
        //            + "gDetailVersion : " + gDetailVersion + "\r\n"
        //            + "gDetailOsVersion : " + gDetailOsVersion + "\r\n"
        //            );

        //      if(gDetailVersion.isEmpty())    { gDetailVersion="-"; }
        //      if(gDetailOsVersion.isEmpty())    { gDetailOsVersion="-"; }

        //      logger.warn("get... gDetailModel : " + gDetailModel + " / gDetailVersion : " + gDetailVersion);
        if (!request.getServletPath().equals("/commonDevice/deviceSetup/FirmwareMgtDetailView")) {
            response.setStatus(403);
            return new ModelAndView("redirect:/lresources/errorPage.jsp");
            //         return null;
        }

        String firmVer = new String(request.getParameter("version").getBytes("8859_1"), "UTF-8");
        String osVer = new String(request.getParameter("os").getBytes("8859_1"), "UTF-8");

        if (firmVer.isEmpty()) {
            firmVer = "-";
        }
        if (osVer.isEmpty()) {
            osVer = "-";
        }

        model.addAttribute("model", new String(request.getParameter("model").getBytes("8859_1"), "UTF-8"));
        model.addAttribute("firm", firmVer);
        model.addAttribute("os", osVer);

        return new ModelAndView("fota3g/deviceSetupMgt/FirmwareMgtDetailView");
    }

    /**
     * firmware ?(DeviceSetup - FirmwareMgt - FirmwareMgtDiffList)
     * @param profile/version
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deviceSetup/FirmwareMgtDiffBeforeList")
    @ResponseBody
    public ModelAndView diffPackageFirmwareInfo(@ModelAttribute("FirmwareMgtBaseInfoVo") FirmwareMgtBaseInfoVo vo,
            //                       @ModelAttribute("ThreeFotaDevVo") ThreeFotaDevVo vo,
            ModelMap model) throws Exception {
        //      logger.warn("\r\n >>> FirmwareMgtDiffBeforeList : model : " + vo.getModel() + ", version : " + vo.getVersion() + ", os : " + vo.getOsVersion());
        // baseinfo setting
        //      model.addAttribute("baseInfoGridData", vo); 

        List fotaFirmwareMgtDiffPackageList = firmMgtSVC.getFirmwareMgtDiffPackageListResultHashMapList(vo);
        //      logger.warn("---------- FirmwareMgtDiffBeforeList start ---------------------------------------------------------");
        //      for(int i=0; i<fotaFirmwareMgtDiffPackageList.size(); i++) {
        //         logger.warn("fotaFirmwareMgtDiffPackageList[" + i + "] : " + fotaFirmwareMgtDiffPackageList.get(i).toString());
        //      }
        //      logger.warn("---------- FirmwareMgtDiffBeforeList end ---------------------------------------------------------");

        // 3g-fota -> service fota  
        List<FirmwareMgtDiffPackageListVo> firmwareMgtViewList = changeDiffPackageListData(
                fotaFirmwareMgtDiffPackageList);
        model.addAttribute("firmwareDiffPackageGridData", firmwareMgtViewList);

        return new ModelAndView(ajaxMainView, model);
    }

    /**
     * firmware ?(DeviceSetup - FirmwareMgt - FirmwareMgtDiffAfterList)
     * @param profile/version
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deviceSetup/FirmwareMgtDiffAfterList")
    @ResponseBody
    public ModelAndView diffPackageAfterFirmwareInfo(
            @ModelAttribute("FirmwareMgtBaseInfoVo") FirmwareMgtBaseInfoVo vo,
            //                       @ModelAttribute("ThreeFotaDevVo") FirmwareMgtBaseInfoVo vo,
            ModelMap model) throws Exception {
        //      logger.warn("\r\n >>> FirmwareMgtDiffAfterList : model : " + vo.getModel() + ", version : " + vo.getVersion() + ", os : " + vo.getOsVersion());

        List fotaFirmwareMgtDiffPackageList = firmMgtSVC.getFirmwareMgtDiffPackageAfterListResultHashMapList(vo);
        //      logger.warn("---------- FirmwareMgtDiffAfterList start ---------------------------------------------------------");
        //      for(int i=0; i<fotaFirmwareMgtDiffPackageList.size(); i++) {
        //         logger.warn("fotaFirmwareMgtDiffPackageList[" + i + "] : " + fotaFirmwareMgtDiffPackageList.get(i).toString());
        //      }
        //      logger.warn("---------- FirmwareMgtDiffAfterList end ---------------------------------------------------------");

        // 3g-fota -> service fota  
        List<FirmwareMgtDiffPackageListVo> firmwareMgtViewList = changeDiffPackageListData(
                fotaFirmwareMgtDiffPackageList);
        model.addAttribute("firmwareDiffPackageAfterGridData", firmwareMgtViewList);

        return new ModelAndView(ajaxMainView, model);
    }

    public List<FirmwareMgtDiffPackageListVo> changeDiffPackageListData(List resultList) {
        List<FirmwareMgtDiffPackageListVo> firmwareMgtViewList = null;

        // resultList        
        // ? ?

        // {diff_package_size=           2,686, estimated_download_time=             360, 
        // model=A300, estimated_upload_time=             360, 
        // firmware_version=KMGW300V012F@A300, state=Inactive, firmware_diff_name=A300_KMGW300V011F@A300_KMGW300V012F@A300, 
        // diff_package_name=KMGW300V012F@A300, application_firmware_version=KMGW300V011F@A300}

        if (resultList.size() > 0) {
            firmwareMgtViewList = new ArrayList<FirmwareMgtDiffPackageListVo>();

            HashMap tempResultListMap = null;
            FirmwareMgtDiffPackageListVo tempViewVo = null;

            for (int i = 0; i < resultList.size(); i++) {
                tempResultListMap = (HashMap) resultList.get(i);

                tempViewVo = new FirmwareMgtDiffPackageListVo();

                tempViewVo.setModel(tempResultListMap.get("model").toString());
                tempViewVo.setState(tempResultListMap.get("state").toString());
                tempViewVo.setDiffPackageName(tempResultListMap.get("diff_package_name").toString());
                tempViewVo.setApplicationFirmwareVersion(
                        tempResultListMap.get("application_firmware_version").toString());
                tempViewVo.setFirmwareVersion(tempResultListMap.get("firmware_version").toString());
                if (tempResultListMap.get("estimated_upload_time") != null
                        && !tempResultListMap.get("estimated_upload_time").toString().isEmpty()) {
                    tempViewVo.setEstimatedUploadTime(
                            tempResultListMap.get("estimated_upload_time").toString().trim());
                } else {
                    tempViewVo.setEstimatedUploadTime("0");
                }
                if (tempResultListMap.get("estimated_download_time") != null
                        && !tempResultListMap.get("estimated_download_time").toString().isEmpty()) {
                    tempViewVo.setEstimatedDownloadTime(
                            tempResultListMap.get("estimated_download_time").toString().trim());
                } else {
                    tempViewVo.setEstimatedDownloadTime("0");
                }

                if (tempResultListMap.get("diff_package_size") != null
                        && !tempResultListMap.get("diff_package_size").toString().isEmpty()) {
                    tempViewVo.setDiffPackageSize(tempResultListMap.get("diff_package_size").toString().trim());
                } else {
                    tempViewVo.setDiffPackageSize("0");
                }

                if (tempResultListMap.get("firmware_diff_name") != null
                        && !tempResultListMap.get("firmware_diff_name").toString().isEmpty()) {
                    tempViewVo.setFirmwareDiffName(tempResultListMap.get("firmware_diff_name").toString().trim());
                } else {
                    tempViewVo.setFirmwareDiffName("-");
                }

                if (tempResultListMap.get("os_prev_version") != null
                        && !tempResultListMap.get("os_prev_version").toString().isEmpty()) {
                    tempViewVo.setOsPrevVersion(tempResultListMap.get("os_prev_version").toString().trim());
                } else {
                    tempViewVo.setOsPrevVersion("-");
                }
                if (tempResultListMap.get("os_next_version") != null
                        && !tempResultListMap.get("os_next_version").toString().isEmpty()) {
                    tempViewVo.setOsNextVersion(tempResultListMap.get("os_next_version").toString().trim());
                } else {
                    tempViewVo.setOsNextVersion("-");
                }

                firmwareMgtViewList.add(tempViewVo);
            } // end of for(int i=0; i<resultList.size(); i++)

        } // end of if(resultList.size() > 0)

        return firmwareMgtViewList;
    }

    /**
     * firmware 
     * @param request
     * @param model / maker
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deviceSetup/getFirmwareMgtBaseInfoDetail")
    @ResponseBody
    public ModelAndView searchBaseInfoDetail(@ModelAttribute("ThreeFotaDevVo") ThreeFotaDevVo vo, ModelMap model)
            throws Exception {
        //      logger.warn("\r\n >>>>> getFirmwareMgtBaseInfoDetail()\r\n"
        //            + "firmwareVersion : " + vo.getFirmwareVersion() + "\r\n"
        //            + "osVersion : " + vo.getOsVersion() + "\r\n"
        //            + "model : " + vo.getModel() + "\r\n"
        //            );

        //      ThreeFotaDevVo voTmp = new ThreeFotaDevVo();
        //      voTmp.setModel(gDetailModel);
        //      voTmp.setFirmwareVersion(gDetailVersion);
        //      voTmp.setOsVersion(gDetailOsVersion);

        List fotaFirmwareMgtResultList = firmMgtSVC.getFirmwareMgtListResultDetailInfo(vo);

        //      logger.warn("---------- getFirmwareMgtBaseInfo start ----------------------------------");
        //      for(int i=0; i<fotaFirmwareMgtResultList.size(); i++) {
        //         logger.warn("fotaFirmwareMgtResultList[" + i + "] : " + fotaFirmwareMgtResultList.get(i).toString());
        //      }
        //      logger.warn("---------- getFirmwareMgtBaseInfo end ----------------------------------");
        // {approved_cnt=0, last_yn= , model=A300, firmware_type=3G, firmware_version=KMGW300V012F@A300, 
        // profile_name=KMGW300V012F@A300, rnum=5, description=, diff_cnt=1, maker=?, last_version_yn=null, os_version=-}

        // grid data   list ? 
        HashMap tempResultMap = null;

        if (fotaFirmwareMgtResultList != null && fotaFirmwareMgtResultList.size() > 0) {
            tempResultMap = (HashMap) fotaFirmwareMgtResultList.get(0);
            //         logger.warn(" >>> tempResultMap : " + tempResultMap.toString());

            List<FirmwareMgtViewVo> firmwareMgtViewList = new ArrayList<FirmwareMgtViewVo>();
            FirmwareMgtViewVo tempVo = new FirmwareMgtViewVo();

            tempVo.setFirmwareType(tempResultMap.get("firmware_type").toString());
            tempVo.setMaker(tempResultMap.get("maker").toString());
            tempVo.setModel(tempResultMap.get("model").toString());

            tempVo.setProfileId(tempResultMap.get("profile_id").toString());
            tempVo.setProfileName(tempResultMap.get("profile_name").toString());

            tempVo.setFirmwareDiffName(tempResultMap.get("profile_name").toString());
            tempVo.setFirmwareVersion(tempResultMap.get("firmware_version").toString());

            if (tempResultMap.get("os_version") != null && !tempResultMap.get("os_version").toString().isEmpty()) {
                tempVo.setOsVersion(tempResultMap.get("os_version").toString());
            } else {
                tempVo.setOsVersion("-");
            }

            String tempCnt = tempResultMap.get("approved_cnt").toString() + " ("
                    + tempResultMap.get("diff_cnt").toString() + ")";
            tempVo.setPackageCnt(tempCnt);

            if (tempResultMap.get("description") != null
                    && !tempResultMap.get("description").toString().isEmpty()) {
                tempVo.setDescription(tempResultMap.get("description").toString());
            }
            if (tempResultMap.get("last_yn") != null && !tempResultMap.get("last_yn").toString().isEmpty()) {
                tempVo.setLastYn(tempResultMap.get("last_yn").toString());
            }
            if (tempResultMap.get("last_version_yn") != null
                    && !tempResultMap.get("last_version_yn").toString().isEmpty()) {
                tempVo.setLastVersionYn(tempResultMap.get("last_version_yn").toString());
            }

            firmwareMgtViewList.add(tempVo);

            model.addAttribute("gridData", firmwareMgtViewList);
        } // end of if(fotaFirmwareMgtResultList != null && fotaFirmwareMgtResultList.size() > 0)

        return new ModelAndView(ajaxMainView, model);
    }

    /**
     * firmware ?(DeviceSetup - FirmwareMgt - FirmwareMgtDiffList)
     * @param profile/version
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deviceSetup/FirmwareMgtDiffBeforeListDetail")
    @ResponseBody
    public ModelAndView diffPackageFirmwareInfoDetail(
            @ModelAttribute("FirmwareMgtBaseInfoVo") FirmwareMgtBaseInfoVo vo, ModelMap model) throws Exception {
        //      logger.warn("\r\n >>>>> FirmwareMgtDiffBeforeListDetail\r\n"
        //            + "model : " + vo.getModel() + "\r\n"
        //            + "firmVer : " + vo.getVersion() + "\r\n"
        //            + "osVer : " + vo.getOsVersion()
        //            );

        //      FirmwareMgtBaseInfoVo voTmp = new FirmwareMgtBaseInfoVo();
        //      voTmp.setMaker("");
        //      // baseinfo setting
        //      voTmp.setModel(gDetailModel);
        //      voTmp.setVersion(gDetailVersion);
        //      voTmp.setOsVersion(gDetailOsVersion);

        List fotaFirmwareMgtDiffPackageList = firmMgtSVC.getFirmwareMgtDiffPackageListResultHashMapList(vo);
        //      logger.warn(" ---------- FirmwareMgtDiffBeforeListDetail start -----------------------------------");
        //      for(int i=0; i<fotaFirmwareMgtDiffPackageList.size(); i++) {
        //         logger.warn("fotaFirmwareMgtDiffPackageListDetail[" + i + "] : " + fotaFirmwareMgtDiffPackageList.get(i).toString());
        //      }
        //      logger.warn(" ---------- FirmwareMgtDiffBeforeListDetail end -----------------------------------");
        //      logger.warn("firmwareMgtDiffBeforeListDetail2-----------------------------------------------------------------");
        // {diff_package_size=           2,686, estimated_download_time=             360, 
        // model=A300, estimated_upload_time=             360, 
        // firmware_version=KMGW300V012F@A300, state=Inactive, firmware_diff_name=A300_KMGW300V011F@A300_KMGW300V012F@A300, 
        // diff_package_name=KMGW300V012F@A300, application_firmware_version=KMGW300V011F@A300, os_version=-}

        // 3g-fota -> service fota  
        List<FirmwareMgtDiffPackageListVo> firmwareMgtViewList = changeDiffPackageListData(
                fotaFirmwareMgtDiffPackageList);
        model.addAttribute("gridData", firmwareMgtViewList);

        return new ModelAndView(ajaxMainView, model);
    }

    /**
     * firmware ?(DeviceSetup - FirmwareMgt - FirmwareMgtDiffAfterList)
     * @param profile/version
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deviceSetup/FirmwareMgtDiffAfterListDetail")
    @ResponseBody
    public ModelAndView diffPackageAfterFirmwareInfoDetail(
            @ModelAttribute("FirmwareMgtBaseInfoVo") FirmwareMgtBaseInfoVo vo, ModelMap model) throws Exception {

        //      logger.warn("\r\n >>>>> FirmwareMgtDiffAfterListDetail\r\n"
        //            + "model : " + vo.getModel() + "\r\n"
        //            + "firmVer : " + vo.getVersion() + "\r\n"
        //            + "osVer : " + vo.getOsVersion()
        //            );

        //      FirmwareMgtBaseInfoVo voTmp = new FirmwareMgtBaseInfoVo();
        //      // baseinfo setting
        //      voTmp.setModel(gDetailModel);
        //      voTmp.setVersion(gDetailVersion);
        //      voTmp.setOsVersion(gDetailOsVersion);

        List fotaFirmwareMgtDiffPackageList = firmMgtSVC.getFirmwareMgtDiffPackageAfterListResultHashMapList(vo);
        //      logger.warn(" ---------- FirmwareMgtDiffAfterListDetail start -----------------------------------");
        //      for(int i=0; i<fotaFirmwareMgtDiffPackageList.size(); i++) {
        //         logger.warn("fotaFirmwareMgtDiffPackageListDetail[" + i + "] : " + fotaFirmwareMgtDiffPackageList.get(i).toString());
        //      }
        //      logger.warn(" ---------- FirmwareMgtDiffAfterListDetail end -----------------------------------");

        // 3g-fota -> service fota  
        List<FirmwareMgtDiffPackageListVo> firmwareMgtViewList = changeDiffPackageListData(
                fotaFirmwareMgtDiffPackageList);
        model.addAttribute("gridData", firmwareMgtViewList);

        return new ModelAndView(ajaxMainView, model);
    }

    /**
     *  ?
     * @param vo
     * @param model
     * @return
     */
    @RequestMapping(value = "/deviceSetup/setFirmwareDetailInfo")
    @ResponseBody
    public ModelAndView setFirmwareDetailInfo(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute("FirmwareMgtDiffPackageDetailVo") FirmwareMgtDiffPackageDetailVo vo, ModelMap model)
            throws Exception {
        //      Date now = new Date();
        //      logger.info("setFirmwareDetailInfo, File update start : " + now.toString());
        //      logger.info("setFirmwareDetailInfo, File update start \r\n"
        //            + "gSaveFilePath : " + gSaveFilePath + "\r\n"
        //            );

        //      String saveFilePath = "D:\\dms_workspace\\firmwareDiffPackage\\";
        //      gSaveFilePath = "./firmwareDiffPackage/";

        //    ? ?
        File temp_folder = new File(gSaveFilePath);
        if (!temp_folder.exists() || !temp_folder.isDirectory()) {
            //         logger.error("File Save Directory Not Exists : " + gSaveFilePath);
            response.setStatus(500);

            temp_folder.mkdirs();
            //         return new ModelAndView (ajaxMainView, model);
        }

        //      logger.warn("temp_folder create end.... path : " + gSaveFilePath);

        MultipartRequest multi = null;
        File upfile = null;

        try {
            //  ?
            multi = new MultipartRequest(request, gSaveFilePath, MAX_FILE_SIZE, "utf-8");
            //         logger.warn("MultipartRequest get....");

            upfile = new File(gSaveFilePath + multi.getFilesystemName("file"));
            //         logger.warn("upfile get....");

            //         logger.info("setFirmwareDetailInfo >>>>>>> file name : " + upfile.getName());
            //         vo.setDiffPackageName(VoV.valid(upfile.getName(), 200, 8));
            vo.setDiffPackageName(multi.getParameter("diffPackageName"));
            //         vo.setDiffPackageSize(String.valueOf(upfile.length()));
            vo.setDiffPackageSize(multi.getParameter("diffPackageSize"));
            //         (   model, firmware_version, description, diff_package, firmware_diff_name
            //         ,diff_package_name, diff_package_size, application_firmware_version
            //         ,estimated_download_time, estimated_upload_time, state
            //         ,inner_description, release_notes
            //         ,descriptor_mime_type, firmware_mime_type
            //           ,write_id, write_date, modify_date   )      
            vo.setLoginId(VoV.valid(multi.getParameter("UserLoginId"), 30));
            vo.setModel(VoV.valid(multi.getParameter("model"), 30));
            vo.setFirmwareVersion(VoV.valid(multi.getParameter("version"), 30)); // ?  
            //         vo.setOsNextVersion(VoV.valid(multi.getParameter("osNextVersion"), 64)); // os ?  
            //         vo.setOsPrevVersion(VoV.valid(multi.getParameter("osPrevVersion"), 64)); // os ?  
            //         vo.setFirmwareType(VoV.valid(multi.getParameter("firmwareType"), 16)); // ?  
            vo.setMaker(VoV.valid(multi.getParameter("maker"), 30));
            vo.setDocument(VoV.valid(multi.getParameter("document"), 1000));
            vo.setDiffPackage(VoV.valid(multi.getParameter("diffPackage"), 100));
            vo.setApplicationFirmwareVersion(multi.getParameter("selectPackage")); // ? 
            if (multi.getParameter("downTime") == null || multi.getParameter("downTime") == "") {
                vo.setEstimatedDownloadTime("0"); // ? ?
            } else {
                vo.setEstimatedDownloadTime(multi.getParameter("downTime")); // ? ?
            }
            if (multi.getParameter("installTime") == null || multi.getParameter("installTime") == "") {
                vo.setEstimatedUploadTime("0"); // ? ?
            } else {
                vo.setEstimatedUploadTime(multi.getParameter("installTime")); // ? ?
            }

            vo.setOsNextVersion(multi.getParameter("osNextVersion")); // os ?  
            vo.setOsPrevVersion(multi.getParameter("osPrevVersion")); // os ?  
            vo.setFirmwareType(multi.getParameter("firmwareType")); // ?  

            //         logger.warn("os : " + vo.getOsPrevVersion() + " / " + vo.getOsNextVersion());

            vo.setState("N"); // new , ?
            vo.setDocument(multi.getParameter("document"));
            vo.setDocumentIn(multi.getParameter("documentIn"));
            vo.setReleaseNote(multi.getParameter("releaseNote"));
            vo.setDescMimeType(multi.getParameter("descMimeType"));
            vo.setFirmMimeType(multi.getParameter("firmMimeType"));
            // firmware diff name ? model_ApplicationFirmwareVersion 
            vo.setFirmwareDiffName(vo.getModel() + "_" + vo.getApplicationFirmwareVersion());
            //         if (!vo.getFotaType().equals("") && !vo.getFotaType().equals("PUSH") && !vo.getFotaType().equals("POLLING") && !vo.getFotaType().equals("PUSHPOLLING"))
            //            throw new Exception();
            //         vo.setDiffPackage(gSaveFilePath + vo.getDiffPackageName());

            //         logger.warn("diff pkg : " + vo.getDiffPackage());

            //vo.setFirmwareId(VoV.valid(multi.getParameter("firmwareId"), 30, 4));
            //vo.setFirmwareDesc(VoV.valid(multi.getParameter("firmwareDesc"), 1000, 9));
            //         vo.setFirmwareVer(VoV.valid(multi.getParameter("firmwareVer"), 100, 4));
            //         vo.setFirmwareMakerVer(VoV.valid(multi.getParameter("firmwareMakerVer"), 100, 8));
            //         vo.setVerMemo(VoV.valid(multi.getParameter("verMemo"), 1000, 9));

            //         logger.warn("file upload vo setting completed...");

            //   ? ?
            //         String path = gSaveFilePath + "realFile/";
            String path = gSaveFilePath + vo.getModel() + "/";
            File pysicalfolder = new File(path);
            if (!pysicalfolder.exists() || !pysicalfolder.isDirectory()) {
                pysicalfolder.mkdirs();
            }
            //         vo.setDiffPackage(VoV.valid(gPath, 200)); // diff package file save info

            //  ???
            File destFile = new File(path + upfile.getName());
            if (destFile.exists()) {
                destFile.delete(); //  ??   ?.
            }

            FileUtils.moveFile(upfile, destFile);

            vo.setDiffPackage(path + vo.getDiffPackageName());

            //CRC, '0' 
            //         vo.setCrc("0");
            //         vo.setCretNm(((UserLoginVO)request.getSession().getAttribute("userInfo")).getUserNm());

        } catch (Exception e) { //  ?? 
            // ??? ? ? 
            if (upfile != null && upfile.exists()) {
                upfile.delete();
            }

            String errorMSG = e.getMessage();
            if (errorMSG != null && !errorMSG.isEmpty() && errorMSG.indexOf("exceeds") != 0) {
                model.addAttribute("error", "?? 10MB ?.");
            } else {
                logger.error("Firm Upload Exception Msg : " + errorMSG);
                e.printStackTrace();
            }

            //         logger.info("File update error : " + errorMSG);
            response.setStatus(500);
            return new ModelAndView(ajaxMainView, model);
        }

        String innerDescription = getMD5Checksum(vo.getDiffPackage());
        vo.setDocumentIn(innerDescription);

        //      logger.warn(" << diff pkg insert info >> \r\n"
        //            + "model : " + vo.getModel() + "\r\n"
        //            + "firmwareVersion : " + vo.getFirmwareVersion() + "\r\n"
        //            + "document : " + vo.getDocument() + "\r\n"
        //            + "diffPackage : " + vo.getDiffPackage() + "\r\n"
        //            + "firmwareDiffName : " + vo.getFirmwareDiffName() + "\r\n"
        //            + "diffPackageName : " + vo.getDiffPackageName() + "\r\n"
        //            + "diffPackageSize : " + vo.getDiffPackageSize() + "\r\n"
        //            + "applicationFirmwareVersion : " + vo.getApplicationFirmwareVersion() + "\r\n"
        //            + "estimatedDownloadTime : " + vo.getEstimatedDownloadTime() + "\r\n"
        //            + "estimatedUploadTime : " + vo.getEstimatedUploadTime() + "\r\n"
        //            + "state : " + vo.getState() + "\r\n"
        //            + "documentIn : " + vo.getDocumentIn() + "\r\n"
        //            + "releaseNote : " + vo.getReleaseNote() + "\r\n"
        //            + "osVersion : " + vo.getOsVersion() + "\r\n"
        //            + "osPrevVersion : " + vo.getOsPrevVersion() + "\r\n"
        //            + "osNextVersion : " + vo.getOsNextVersion() + "\r\n"
        //            + "descMimeType : " + vo.getDescMimeType() + "\r\n"
        //            + "firmMimeType : " + vo.getFirmMimeType() + "\r\n"
        //            + "firmwareType : " + vo.getFirmwareType() + "\r\n"
        //            + "loginId : " + vo.getLoginId() + "\r\n"
        //            );

        // insert  ? '-'  
        if (vo.getApplicationFirmwareVersion().isEmpty()) {
            vo.setApplicationFirmwareVersion("-");
        }
        if (vo.getFirmwareVersion().isEmpty()) {
            vo.setFirmwareVersion("-");
        }
        if (vo.getOsVersion().isEmpty()) {
            vo.setOsVersion("-");
        }
        if (vo.getOsPrevVersion().isEmpty()) {
            vo.setOsPrevVersion("-");
        }
        if (vo.getOsNextVersion().isEmpty()) {
            vo.setOsNextVersion("-");
        }

        //      mySVC.regi(vo);
        // firmware detail info 
        int retValueHistory = -1;
        int retValue = firmMgtSVC.setFirmwareDetailInfo(vo);

        //      logger.warn("insert retValue : " + retValue);
        if (retValue == -1) {
            //         logger.warn(">>>setFirmwareDetailInfo Fail....");
        } else {
            //  diff package insert  ?, history ? insert 
            vo.setHistoryId(CommUtil.getUniqueNumber() + ""); // history id 
            //         logger.warn(">>>setFirmwareHistoryInfo : historyId : " + vo.getHistoryId());
            retValueHistory = firmMgtSVC.setFirmwareHistoryInfo(vo);
        }

        //      logger.warn(">>>setFirmwareDetailInfo retValue : " + retValue + ", setFirmwareHistoryInfo retValue : " + retValueHistory);
        model.addAttribute("retValue", retValue);
        model.addAttribute("retValueHistory", retValueHistory);

        //      now = new Date();
        //      logger.info(">>>>File update end : " + now.toString());

        return new ModelAndView(ajaxMainView, model);
    }

    /**
     * firmware 
     * @param request
     * @param model / maker
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deviceSetup/getFirmwareMgtDetailInfo")
    @ResponseBody
    public ModelAndView getFirmwareMgtDetailInfo(
            @ModelAttribute("FirmwareMgtDiffPackageDetailVo") FirmwareMgtDiffPackageDetailVo vo, ModelMap model)
            throws Exception {
        //      logger.warn(" >>>>> getFirmwareMgtDetailInfo\r\n"
        //            + "model : " + vo.getModel() + "\r\n"
        //            + "firmwareVersion : " + vo.getFirmwareVersion() + "\r\n"
        //            + "applFirmwareVersion : " + vo.getApplicationFirmwareVersion() + "\r\n"
        //            + "osPrevVersion : " + vo.getOsPrevVersion() + "\r\n"
        //            + "osNextVersion : " + vo.getOsNextVersion() + "\r\n"
        //            );

        if (vo.getFirmwareVersion().isEmpty()) {
            vo.setFirmwareVersion("-");
        }
        if (vo.getApplicationFirmwareVersion().isEmpty()) {
            vo.setApplicationFirmwareVersion("-");
        }
        if (vo.getOsPrevVersion().isEmpty()) {
            vo.setOsPrevVersion("-");
        }
        if (vo.getOsNextVersion().isEmpty()) {
            vo.setOsNextVersion("-");
        }

        List fotaFirmwareMgtResultList = firmMgtSVC.getFirmwareMgtDetailResultList(vo);

        //      logger.warn("getFirmwareMgtDetailInfo()----------------------------------");
        //      for(int i=0; i<fotaFirmwareMgtResultList.size(); i++) {
        //         logger.warn("fotaFirmwareMgtResultList[" + i + "] : " + fotaFirmwareMgtResultList.get(i).toString());
        //      }
        //{estimated_download_time=             100, model=NOKIA-N5800, estimated_upload_time=             100, 
        // diff_package=null, release_notes=, maker=(), state=A, code_subject=Approved, 
        // application_firmware_version=RM-356_20.7.006 20.7.006.32.01 20.7.006.KT_8000_GRAY.01, 
        // inner_description=, diff_package_size=         583,988, 
        // firmware_version=test profile, 
        // firmware_mime_type=application/vnd.nokia.swupd.dp2, description=, 
        // descriptor_mime_type=application/vnd.oma.dd+xml, 
        // firmware_diff_name=NOKIA-N5800_RM-356_20.7.006 20.7.006.32.01 20.7.006.KT_8000_GRAY.01_test profile, 
        // diff_package_name=test profile}

        if (fotaFirmwareMgtResultList != null && fotaFirmwareMgtResultList.size() > 0) {
            HashMap tempResultListMap = (HashMap) fotaFirmwareMgtResultList.get(0);
            //         logger.warn("tempResultListMap : " + tempResultListMap.toString());

            // 3g-fota -> service fota  
            //         List<FirmwareMgtViewVo> firmwareMgtViewList = changeServiceFotaViewData(fotaFirmwareMgtResultList, 1);
            //         logger.warn("getFirmwareMgtDetailInfo2----------------------------------");         

            // History
            vo.setNewVersion(tempResultListMap.get("firmware_version").toString());
            vo.setLastVersion(tempResultListMap.get("application_firmware_version").toString());
            vo.setOsPrevVersion(tempResultListMap.get("os_prev_version").toString());
            vo.setOsNextVersion(tempResultListMap.get("os_next_version").toString());

            List resultHistoryList = firmMgtSVC.getFirmwareDiffHistoryList(vo);
            //         logger.warn("-------------------------------------------------------------------------------------------");
            //         for(int i=0; i<resultHistoryList.size(); i++) {
            //            logger.warn("resultHistoryList[" + i + "] : " + resultHistoryList.get(i).toString());
            //         }
            //         logger.warn("-------------------------------------------------------------------------------------------");

            List<FirmwareMgtDetailHistoryVo> firmDetailHistoryList = new ArrayList<FirmwareMgtDetailHistoryVo>();

            Map tempResultHistoryMap = null;
            FirmwareMgtDetailHistoryVo tempFirmwareMgtDetailHistoryVo = null;

            if (resultHistoryList != null && resultHistoryList.size() > 0) {
                for (int i = 0; i < resultHistoryList.size(); i++) {
                    tempResultHistoryMap = (HashMap) resultHistoryList.get(i);
                    tempFirmwareMgtDetailHistoryVo = new FirmwareMgtDetailHistoryVo();

                    tempFirmwareMgtDetailHistoryVo.setWriteDate(tempResultHistoryMap.get("write_date").toString());
                    tempFirmwareMgtDetailHistoryVo.setState(tempResultHistoryMap.get("state").toString());
                    tempFirmwareMgtDetailHistoryVo
                            .setCodeSubject(tempResultHistoryMap.get("code_subject").toString());
                    if (tempResultHistoryMap.get("write_id") != null
                            && !tempResultHistoryMap.get("write_id").toString().isEmpty()) {
                        //                  tempFirmwareMgtDetailHistoryVo.setWriteId(tempResultHistoryMap.get("write_id").toString());
                        // -  ?   java-Ctrl ?  - DMS ?
                        tempFirmwareMgtDetailHistoryVo
                                .setWriteId(Masking.convertId(tempResultHistoryMap.get("write_id").toString()));
                    }
                    tempFirmwareMgtDetailHistoryVo.setModel(tempResultHistoryMap.get("model").toString());
                    tempFirmwareMgtDetailHistoryVo.setHistoryId(tempResultHistoryMap.get("history_id").toString());

                    firmDetailHistoryList.add(tempFirmwareMgtDetailHistoryVo);
                }
            }

            //         logger.warn("tempResultListMap : " + tempResultListMap.toString());
            // tempResultListMap : 
            // {estimated_download_time=             360, model=A300, 
            // estimated_upload_time=             360, diff_package=null, 
            // release_notes=, maker=?, state=I, code_subject=Inactive, 
            // application_firmware_version=KMGW300V011F@A300, os_prev_version=null, 
            // inner_description=, diff_package_size=           2,686, 
            // firmware_type=3G, firmware_version=KMGW300V012F@A300, 
            // firmware_mime_type=application/octet-stream, 
            // description=, descriptor_mime_type=application/vnd.oma.dd+xml, 
            // os_next_version=null, firmware_diff_name=A300_KMGW300V011F@A300_KMGW300V012F@A300, 
            // diff_package_name=KMGW300V012F@A300}

            //         model.addAttribute("baseInfoGridData", firmwareMgtViewList);
            model.addAttribute("maker", tempResultListMap.get("maker").toString()); // 
            model.addAttribute("model", tempResultListMap.get("model").toString()); // ?
            model.addAttribute("firmwareDiffName", tempResultListMap.get("firmware_diff_name").toString()); // Package ?
            model.addAttribute("lastVersion", tempResultListMap.get("application_firmware_version").toString()); // ? 
            model.addAttribute("newVersion", tempResultListMap.get("firmware_version").toString()); // ? 
            model.addAttribute("stateName", tempResultListMap.get("code_subject").toString().trim()); // ?
            model.addAttribute("state", tempResultListMap.get("state").toString()); // ? 
            model.addAttribute("diffPackageName", tempResultListMap.get("diff_package_name").toString()); // Package ?

            if (tempResultListMap.get("diff_package_size") != null
                    && !tempResultListMap.get("diff_package_size").toString().isEmpty()) {
                model.addAttribute("diffPackageSize",
                        tempResultListMap.get("diff_package_size").toString().trim() + " byte"); // Package ?
            } else {
                model.addAttribute("diffPackageSize", "0 byte"); // Package ?
            }
            if (tempResultListMap.get("estimated_download_time") != null
                    && !tempResultListMap.get("estimated_download_time").toString().isEmpty()) {
                model.addAttribute("downloadTime",
                        tempResultListMap.get("estimated_download_time").toString().trim()); // ?  ()
            } else {
                model.addAttribute("downloadTime", "0"); // ?  ()
            }
            if (tempResultListMap.get("estimated_upload_time") != null
                    && !tempResultListMap.get("estimated_upload_time").toString().isEmpty()) {
                model.addAttribute("uploadTime", tempResultListMap.get("estimated_upload_time").toString().trim()); // ?  ()
            } else {
                model.addAttribute("uploadTime", "0"); // ?  ()
            }

            model.addAttribute("descMimeType", tempResultListMap.get("descriptor_mime_type").toString()); // Descriptor MIME Type
            model.addAttribute("firmMimeType", tempResultListMap.get("firmware_mime_type").toString()); // Firmware MIME Type
            model.addAttribute("firmwareType", tempResultListMap.get("firmware_type").toString()); // Firmware Type

            if (tempResultListMap.get("os_prev_version") != null
                    && !tempResultListMap.get("os_prev_version").toString().isEmpty()) {
                model.addAttribute("osPrevVersion", tempResultListMap.get("os_prev_version").toString()); // os_prev_version
            } else {
                model.addAttribute("osPrevVersion", "-"); // os_prev_version
            }

            if (tempResultListMap.get("os_next_version") != null
                    && !tempResultListMap.get("os_next_version").toString().isEmpty()) {
                model.addAttribute("osNextVersion", tempResultListMap.get("os_next_version").toString()); // os_next_version
            } else {
                model.addAttribute("osNextVersion", "-"); // os_next_version
            }

            if (tempResultListMap.get("description") != null
                    && !tempResultListMap.get("description").toString().isEmpty()) {
                model.addAttribute("description", tempResultListMap.get("description").toString()); // 
            } else {
                model.addAttribute("description", "");
            }
            if (tempResultListMap.get("inner_description") != null
                    && !tempResultListMap.get("inner_description").toString().isEmpty()) {
                model.addAttribute("internalDescription", tempResultListMap.get("inner_description").toString()); // 
            } else {
                model.addAttribute("internalDescription", "");
            }
            if (tempResultListMap.get("release_notes") != null
                    && !tempResultListMap.get("release_notes").toString().isEmpty()) {
                model.addAttribute("releaseNote", tempResultListMap.get("release_notes").toString()); // Release Notes
            } else {
                model.addAttribute("releaseNote", "");
            }

            int totalCount = 0;
            int totalPage = 0;

            if (firmDetailHistoryList != null && firmDetailHistoryList.size() > 0) {
                totalCount = firmDetailHistoryList.size();
                totalPage = totalCount / Integer.valueOf(vo.getRowsPerPage());
                if (totalCount % Integer.valueOf(vo.getRowsPerPage()) != 0)
                    totalPage++;
            }

            model.addAttribute("historyList", firmDetailHistoryList); // history - list
            model.addAttribute("historyListTotalPage", totalPage); // history - total
            model.addAttribute("historyListPage", vo.getPage()); // history - total
        } // end of if(fotaFirmwareMgtResultList != null && fotaFirmwareMgtResultList.size() > 0)

        return new ModelAndView(ajaxMainView, model);
    }

    @RequestMapping(value = "/deviceSetup/updateFirmwareDiffState")
    @ResponseBody
    public ModelAndView updateFirmwareDiffState(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute("FirmwareMgtDiffPackageDetailVo") FirmwareMgtDiffPackageDetailVo vo, ModelMap model)
            throws Exception {
        //      logger.warn(" >>>>> FrimwareMgtCTR - updateFirmwareDiffState()\r\n"
        //            + "model : " + vo.getModel() + "\r\n"
        //            + "state : " + vo.getState() + "\r\n"
        //            + "newState : " + vo.getNewState() + "\r\n"
        //            + "lastVersion : " + vo.getLastVersion() + "\r\n"
        //            + "newVersion : " + vo.getNewVersion() + "\r\n"
        //            + "osPrevVersion : " + vo.getOsPrevVersion() + "\r\n"
        //            + "osNextVersion : " + vo.getOsNextVersion()
        //            );

        Map<String, String> entity = new HashMap<String, String>();

        //      entity.put("new_state", "I");
        entity.put("new_state", vo.getNewState());
        entity.put("model", vo.getModel());
        entity.put("lastVersion", vo.getLastVersion());
        entity.put("newVersion", vo.getNewVersion());
        entity.put("osPrevVersion", vo.getOsPrevVersion());
        entity.put("osNextVersion", vo.getOsNextVersion());
        entity.put("state", vo.getState());

        int insertRet = 0;
        int updateRet = 0;

        //      if(vo.getState().equals("I") || vo.getState().equals("A")) {
        String prevState = vo.getState();

        // login ? user  
        HttpSession httpSession = request.getSession(false);
        UserLoginVO userSessionVo = (UserLoginVO) httpSession.getAttribute("userInfo");

        String userId = userSessionVo.getUserId();

        String nextHistId = firmMgtSVC.getNextDiffHistSeq();

        entity.put("history_id", nextHistId);
        entity.put("login_id", userId);

        //         logger.warn("\r\nchangeInfo : " + entity.toString());
        // UpdateFirmwareDiffByState ?   ? history ?? insert !! 
        // ?.... update ...  ??  ...
        insertRet = firmMgtSVC.insertFirmwareDiffHistoryByState(entity);
        //         logger.warn("insertRet : " + insertRet);
        updateRet = firmMgtSVC.updateFirmwareDiffByState(entity);
        //         logger.warn("updateRet : " + updateRet);

        //      }

        //  ? DL ?, Detail  
        // ??   ...
        // src.com.dki.dm. ?
        // action.FirmwareAction.setFirmwareDiffState()
        // business.updateDiffState4HistoryInactived()  ...

        model.addAttribute("updateRet", updateRet);
        //      logger.warn("getFirmwareMgtDetailInfo3----------------------------------");
        return new ModelAndView(ajaxMainView, model);
    }

    @RequestMapping(value = "/deviceSetup/updateFirmwareDiff")
    @ResponseBody
    public ModelAndView updateFirmwareDiff(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute("FirmwareMgtDiffPackageDetailVo") FirmwareMgtDiffPackageDetailVo vo, ModelMap model)
            throws Exception {
        //      logger.warn(" >>>>> FrimwareMgtCTR - updateFirmwareDiff()\r\n"
        //            + "maker : " + vo.getMaker() + "\r\n"
        //            + "model : " + vo.getModel() + "\r\n"
        //            + "firmwareDiffName : " + vo.getFirmwareDiffName() + "\r\n"
        //            + "newState : " + vo.getNewState() + "\r\n"
        //            + "diffPackageFile : " + vo.getDiffPackageFile() + "\r\n"
        //            + "lastVersion : " + vo.getLastVersion() + "\r\n"
        //            + "newVersion : " + vo.getNewVersion() + "\r\n"
        //            + "downloadTime : " + vo.getDownloadTime() + "\r\n"
        //            + "uploadTime : " + vo.getUploadTime() + "\r\n"
        //            + "description : " + vo.getDescription() + "\r\n"
        //            + "internalDescription : " + vo.getInternalDescription() + "\r\n"
        //            + "releaseNote : " + vo.getReleaseNote() + "\r\n"
        //            + "descMimeType : " + vo.getDescMimeType() + "\r\n"
        //            + "firmMimeType : " + vo.getFirmMimeType() + "\r\n"
        //            + "osPrevVersion : " + vo.getOsPrevVersion() + "\r\n"
        //            + "osNextVersion : " + vo.getOsNextVersion()
        //            );

        vo.setMaker(VoV.replaceRoundBracket(vo.getMaker()));

        // ?? Diff    ?
        int approvedCnt = firmMgtSVC.checkApprovedFirmDiff(vo);
        //      logger.warn("approved count : " + approvedCnt);

        int updateRet = 0;
        // Approved ?? Diff Package    .
        if (approvedCnt > 0) {
            updateRet = -1;
        } else {
            // login ? user  
            HttpSession httpSession = request.getSession(false);
            UserLoginVO userSessionVo = (UserLoginVO) httpSession.getAttribute("userInfo");

            String userId = userSessionVo.getUserId();
            vo.setUserId(userId);

            // ? Comma 
            if (vo.getUploadTime() != null && !vo.getUploadTime().isEmpty()) {
                vo.setUploadTime(vo.getUploadTime().replaceAll(",", ""));
            }
            if (vo.getDownloadTime() != null && !vo.getDownloadTime().isEmpty()) {
                vo.setDownloadTime(vo.getDownloadTime().replaceAll(",", ""));
            }

            updateRet = firmMgtSVC.updateFirmwareDiff(vo);
            //         logger.warn("updateRet : " + updateRet);
        }

        model.addAttribute("updateRet", updateRet);

        return new ModelAndView(ajaxMainView, model);
    }

    @RequestMapping(value = "/deviceSetup/deleteFirmwareDiff")
    @ResponseBody
    public ModelAndView deleteFirmwareDiff(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute("FirmwareMgtDiffPackageDetailVo") FirmwareMgtDiffPackageDetailVo vo, ModelMap model)
            throws Exception {
        //      logger.warn(" >>>>> FrimwareMgtCTR - deleteFirmwareDiff()\r\n"
        //            + "maker : " + vo.getMaker() + "\r\n"
        //            + "model : " + vo.getModel() + "\r\n"
        //            + "firmwareDiffName : " + vo.getFirmwareDiffName() + "\r\n"
        //            + "state : " + vo.getState() + "\r\n"
        //            + "diffPackageName : " + vo.getDiffPackageName() + "\r\n"
        //            + "lastVersion : " + vo.getLastVersion() + "\r\n"
        //            + "newVersion : " + vo.getNewVersion() + "\r\n"
        //            + "downloadTime : " + vo.getDownloadTime() + "\r\n"
        //            + "uploadTime : " + vo.getUploadTime() + "\r\n"
        //            + "description : " + vo.getDescription() + "\r\n"
        //            + "internalDescription : " + vo.getInternalDescription() + "\r\n"
        //            + "releaseNote : " + vo.getReleaseNote() + "\r\n"
        //            + "descMimeType : " + vo.getDescMimeType() + "\r\n"
        //            + "firmMimeType : " + vo.getFirmMimeType() + "\r\n"
        //            + "osPrevVersion : " + vo.getOsPrevVersion() + "\r\n"
        //            + "osNextVersion : " + vo.getOsNextVersion() + "\r\n"
        //            );

        vo.setMaker(VoV.replaceRoundBracket(vo.getMaker()));

        String path = gSaveFilePath + vo.getModel() + "/";

        // ?? Diff    ?
        int approvedCnt = firmMgtSVC.checkApprovedFirmDiff(vo);
        //      logger.warn("approved count : " + approvedCnt);

        String diffState = firmMgtSVC.checkStateFirmDiff(vo);
        //      logger.warn("diffState : " + diffState);

        int deleteRet = 1;
        // Approved ?? Diff Package    .
        if (approvedCnt > 0) {
            deleteRet = -1;
        } else {
            // Diff Package ? New, Ready ? 
            if (!diffState.equals("N") && !diffState.equals("R")) {
                deleteRet = -2;
            } else {
                // login ? user  
                HttpSession httpSession = request.getSession(false);
                UserLoginVO userSessionVo = (UserLoginVO) httpSession.getAttribute("userInfo");

                String userId = userSessionVo.getUserId();
                vo.setUserId(userId);

                /////////////////////////////////////////
                // DB ?? 
                /////////////////////////////////////////
                // firmware diff history delete
                deleteRet = firmMgtSVC.deleteFirmwareDiffHistory(vo);
                //            logger.warn("deleteFirmwareDiffHistory() : " + deleteRet);
                // firmware diff delete
                deleteRet = firmMgtSVC.deleteFirmwareDiff(vo);
                //            logger.warn("deleteFirmwareDiff() : " + deleteRet);

                // ?   insertOpHistory ? 
                String operation = "[?:" + vo.getModel() + "][->:" + vo.getLastVersion() + "->"
                        + vo.getNewVersion() + "]";
                Map<String, String> entity = new HashMap<String, String>();
                entity.put("userId", vo.getUserId());
                entity.put("operation", operation);
                entity.put("nextOpHistSeq", firmMgtSVC.getNextOpHistSeq());

                firmMgtSVC.insertFirmwareDiffOpHistory(entity);

                /////////////////////////////////////////
                // file    !!!!
                /////////////////////////////////////////
                // Diff ? ?    ??    ?
                //  DB  .
                //            String fileName = path + vo.getDiffPackageName();
                //
                //             File f = new File(fileName);
                //
                ////             logger.warn(" >>>>>>>>>>>>>>>>>>> file delete start ..... : " + fileName);
                //             
                //             if (f.delete()) {   // file 
                //                logger.warn("Modem Firmware File delete completed.... [ " + vo.getDiffPackageName() + " ]");
                //             }
                //             else {
                //                logger.warn("Modem Firmware File delete fail [ " + vo.getDiffPackageName() + " ]");
                //                deleteRet = -3;
                //             }
            }
        }

        model.addAttribute("deleteRet", deleteRet);

        return new ModelAndView(ajaxMainView, model);
    }

    /*****************************************************************************************************************/
    /*****************************************************************************************************************/
    /*****************************************************************************************************************/
    /* ********** Firmware   / ********** */

    @RequestMapping(value = "/deviceSetup/getDDFList")
    @ResponseBody
    public ModelAndView getDDFList(ModelMap model) throws Exception {
        model.addAttribute("ddfList", firmMgtSVC.getDDFList());

        return new ModelAndView(ajaxMainView, model);
    }

    @RequestMapping(value = "/deviceSetup/getDeviceProfileInfo")
    @ResponseBody
    public ModelAndView getDeviceProfileInfo(
            @ModelAttribute("FirmwareMgtDiffPackageDetailVo") FirmwareMgtDiffPackageDetailVo vo, ModelMap model)
            throws Exception {
        model.addAttribute("deviceProfileInfo", firmMgtSVC.getDeviceProfileInfo(vo));

        return new ModelAndView(ajaxMainView, model);
    }

    @RequestMapping(value = "/deviceSetup/getDDFSuportService")
    @ResponseBody
    public ModelAndView getDDFSuportService(
            @ModelAttribute("FirmwareMgtDiffPackageDetailVo") FirmwareMgtDiffPackageDetailVo vo, ModelMap model)
            throws Exception {
        String serviceSupport = "";

        if (!vo.getDdfId().isEmpty()) {
            List resultList = firmMgtSVC.getDDFServiceList(vo);

            HashMap tempResultMap = null;
            if (resultList != null && resultList.size() > 0) {
                for (int i = 0; i < resultList.size(); i++) {
                    tempResultMap = (HashMap) resultList.get(i);

                    if (tempResultMap.get("ddf_id") != null && !tempResultMap.get("ddf_id").toString().isEmpty()
                            && tempResultMap.get("ddf_id").toString().equals(vo.getDdfId())) {

                        serviceSupport += "[" + tempResultMap.get("reference2").toString() + "] ";
                    }

                }
            }
        }

        model.addAttribute("serviceSupport", serviceSupport);

        return new ModelAndView(ajaxMainView, model);
    }

    /*
     * DMS ? ?  ? 
     */
    @RequestMapping(value = "/deviceSetup/updateFirmBaseInfo")
    @ResponseBody
    public ModelAndView updateFirmBaseInfo(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute("FirmwareMgtDiffPackageDetailVo") FirmwareMgtDiffPackageDetailVo vo, ModelMap model)
            throws Exception {
        String loginUserId = ((UserLoginVO) request.getSession().getAttribute("userInfo")).getUserId();
        vo.setUserId(loginUserId);

        // firmwareDiffName
        int cnt = firmMgtSVC.getProfileCheck(vo);
        int result = 0;
        if (cnt > 0) {
            result = -3;
        } else {
            //  3G FOTA ? Firmware  ?? 
            //  ?   ?  select ?.
            //  ? ?  ?  Dialog  
            //    ?...
            // but.. 
            //       select .
            FirmwareMgtDiffPackageDetailVo tempVo = firmMgtSVC.getFirmwareView(vo);
            if (tempVo != null && !tempVo.getLastVersionYn().isEmpty()) {
                vo.setLastVersionYn(tempVo.getLastVersionYn());
            } else {
                vo.setLastVersionYn("");
            }

            // Firm 
            int updateRet = firmMgtSVC.updateFirmwareBaseInfo(vo);
            //         logger.warn("firmware update ret : " + updateRet);
            if (updateRet == 1) {
                updateRet = firmMgtSVC.updateDeviceProfile(vo);
                //            logger.warn("updateDeviceProfile() : " + updateRet);
            }
            if (updateRet == 1) {
                updateRet = firmMgtSVC.updateDiffPackageName(vo);
                //            logger.warn("updateDiffPackageName() : " + updateRet);
            }

            result = updateRet;
        }

        model.addAttribute("updateRet", result);

        return new ModelAndView(ajaxMainView, model);
    }

    @RequestMapping(value = "/deviceSetup/deleteFirmBaseInfo")
    @ResponseBody
    public ModelAndView deleteFirmBaseInfo(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute("FirmwareMgtDiffPackageDetailVo") FirmwareMgtDiffPackageDetailVo vo, ModelMap model)
            throws Exception {
        int deleteRet = 0;

        //      logger.warn("\r\n >>>> FirmwareMgtCTR - deleteFirmBaseInfo()\r\n"
        //            + "model : " + vo.getModel() + "\r\n"
        //            + "firmwareVersion : " + vo.getFirmwareVersion() + "\r\n"
        //            + "osVersion : " + vo.getOsVersion() + "\r\n"
        //            + "profileId : " + vo.getProfileId()
        //            );

        int approvedCnt = firmMgtSVC.checkApprovedFirm(vo); // ?? Firm Diff    ?
        //      logger.warn("approvedCnt : " + approvedCnt);
        int newApprovedCnt = firmMgtSVC.checkNewApprovedFirm(vo); // ? ? ?? Firm Diff    ?
        //      logger.warn("newApprovedCnt : " + newApprovedCnt);

        // Approved ?  Diff Package ? 
        if (approvedCnt == 0) {
            // ? ? Approved ? Diff Package ?
            if (newApprovedCnt == 0) {
                String loginUserId = ((UserLoginVO) request.getSession().getAttribute("userInfo")).getUserId();
                vo.setUserId(loginUserId);

                //            logger.warn(loginUserId + "   !!!!!");

                // Firm  (TBL_FIRMWARE)
                deleteRet = firmMgtSVC.deleteFirmware(vo);
            } // end of if(newApprovedCnt == 0)
            else {
                // ? ? Approved ? Diff Package ? 
                deleteRet = -3;
            }
        } // end of if(approvedCnt == 0)
        else {
            // Approved ? Diff Package ? 
            deleteRet = -2;
        }

        //      logger.warn("deleteFirmBaseInfo - deleteRet : " + deleteRet);

        model.addAttribute("deleteRet", deleteRet);

        return new ModelAndView(ajaxMainView, model);
    }

    public static byte[] createChecksum(String filename) throws Exception {
        InputStream fis = new FileInputStream(filename);
        byte[] buffer = new byte[1024];
        MessageDigest complete = MessageDigest.getInstance("MD5");

        int numRead;

        do {
            numRead = fis.read(buffer);

            if (numRead > 0) {
                complete.update(buffer, 0, numRead);
            }
        } while (numRead != -1);

        fis.close();
        return complete.digest();
    }

    // see this How-to for a faster way to convert
    // a byte array to a HEX string
    public static String getMD5Checksum(String filename) throws Exception {
        byte[] b = createChecksum(filename);
        int bLen = b.length;

        String result = "";

        for (int i = 0; i < bLen; i++) {
            result += Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1);
        }
        return result;
    }

    /**
     *  
     * @param vo
     * @param model
     * @return
     */
    @RequestMapping(value = "/deviceSetup/downFirm")
    public String download(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute("FirmwareMgtDiffPackageDetailVo") FirmwareMgtDiffPackageDetailVo vo, ModelMap model)
            throws Exception {
        //      if (!request.getServletPath().equals("/commonDevice/deviceSetup/downFirm")) {
        //         response.setStatus(403);
        //         return null;
        //      }

        //      logger.warn("FirmwareMgtCTR - download()\r\n"
        //            + "diffPackageFile : " + vo.getDiffPackageFile()
        //            );
        String filePath = vo.getDiffPackageFile();

        String[] filePathSplit = filePath.split("\\/");
        // filePathSplit[0] : model name
        // filePathSplit[1] : file name

        FileDownloadManager fd = new FileDownloadManager();
        fd.downloadExistFile2(gSaveFilePath + filePath, filePathSplit[1], response);

        return null;
    }

}