Java tutorial
/* * 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.deviceMgt.controller; import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; 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.Masking; import com.fota.comm.util.VoV; import com.fota.commMgt.vo.UserLoginVO; import com.fota.fota3g.deviceMgt.service.TargetGroupMgtSVC; import com.fota.fota3g.deviceMgt.vo.TargetGroupVo; import com.oreilly.servlet.MultipartRequest; @Controller @RequestMapping("/commonFota/deviceMgt") public class TargetGroupMgtCTR { private static final Logger logger = LoggerFactory.getLogger(TargetGroupMgtCTR.class); /** * @uml.property name="firmSVC" * @uml.associationEnd readOnly="true" */ @Autowired TargetGroupMgtSVC targetSVC; /** * @uml.property name="ajaxMainView" * @uml.associationEnd readOnly="true" */ @Autowired private MappingJacksonJsonView ajaxMainView; /** * targetGroup View * @param request * @param model * @return * @throws Exception */ @RequestMapping(value = "/targetGroupManagement") public String getView(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception { // logger.warn("#############targetGroupManagement################"); if (!request.getServletPath().equals("/commonFota/deviceMgt/targetGroupManagement")) { response.setStatus(403); return "redirect:/lresources/errorPage.jsp"; } return "fota3g/deviceMgt/TargetGroupView"; } /** * targetGroup list * @param param * @param response * @return */ @RequestMapping(value = "/targetGroupList") @ResponseBody public ModelAndView getDeviceLinkList(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("TargetGroupVo") TargetGroupVo vo, ModelMap model) throws Exception { // logger.warn("#############targetGroupList################"); vo = targetSVC.targetGroupList(vo); // - ? java-Ctrl ? - DMS ? TargetGroupVo tempVo; if (vo.getResults() != null && vo.getResults().size() > 0) { // for(int i=0; i<vo.getResults().size(); i++) { // tempVo = vo.getResults().get(i); // // if(tempVo.getModifyId() != null && !tempVo.getModifyId().isEmpty()) { // tempVo.setModifyId(Masking.convertId(tempVo.getModifyId())); // } // } } model.addAttribute("gridData", vo.getResults()); // model.addAttribute("resultsSize", vo.getTotalRows()); model.addAttribute("page", vo.getPage()); model.addAttribute("totalPage", vo.getTotalPage()); return new ModelAndView(ajaxMainView, model); } /** * targetGroup insert * @param param * @param response * @return */ @RequestMapping(value = "/addTargetGroup") @ResponseBody public ModelAndView addTargetGroup(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("TargetGroupVo") TargetGroupVo vo, ModelMap model) throws Exception { logger.warn("#############addTargetGroup################"); int result = 0; // user HttpSession httpSession = request.getSession(false); UserLoginVO userVo = (UserLoginVO) httpSession.getAttribute("userInfo"); String userId = userVo.getUserId(); vo.setMoId(userId); vo = targetSVC.insertTargetGroup(vo); result = vo.getResultVal(); model.addAttribute("retValue", result); return new ModelAndView(ajaxMainView, model); } /** * targetGroup insert - Excel * @param param * @param response * @return */ @RequestMapping(value = "/addTargetGroupExcel") @ResponseBody public ModelAndView addTargetGroupExcel(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws Exception { // logger.warn(" >>> TargetGroupMgtCTR - addTargetGroupExcel() start... "); String retMsg = ""; // ? ? String path = "/jb_log/excelUpload/targetGroup/"; File pysicalFolder = new File(path); if (!pysicalFolder.exists() || !pysicalFolder.isDirectory()) { pysicalFolder.mkdirs(); } // ? MultipartRequest multi = new MultipartRequest(request, path, 10 * 1024 * 1024, "utf-8"); String upFileName = multi.getFilesystemName("deviceIdF"); // logger.warn("path : " + path + " ### name : " + upFileName); // user HttpSession httpSession = request.getSession(false); UserLoginVO userVo = (UserLoginVO) httpSession.getAttribute("userInfo"); String userId = userVo.getUserId(); TargetGroupVo vo = new TargetGroupVo(); vo.setMoId(userId); vo.setListGroupName(multi.getParameter("listGroupName")); vo.setDescription(multi.getParameter("description")); vo.setDelYN(multi.getParameter("delYN")); vo.setDeviceType(multi.getParameter("deviceType")); vo.setInputType(multi.getParameter("inputType")); // logger.warn(" >>> TargetGroupMgtCTR - addTargetGroupExcel() vo info\r\n" // + "moId : " + vo.getMoId() + "\r\n" // + "listGroupName : " + vo.getListGroupName() + "\r\n" // + "description : " + vo.getDescription() + "\r\n" // + "delYN : " + vo.getDelYN() + "\r\n" // + "deviceType : " + vo.getDeviceType() + "\r\n" // + "inputType : " + vo.getInputType() + "\r\n" // ); // poi ? ? ? File upfile = new File(path + upFileName); // poi try { FileInputStream file = new FileInputStream(upfile); //.xlsx file XSSFWorkbook workbook = new XSSFWorkbook(file); // XSSFSheet sheet = workbook.getSheetAt(0); // Iterator<Row> rowIterator = sheet.iterator(); // ? ? ctn list ? List<String> ctnList = new ArrayList<String>(); // ? // rowIterator.next(); String tempCtn = ""; while (rowIterator.hasNext()) { Row row = rowIterator.next(); //For each row, iterate through all the columns Iterator<Cell> cellIterator = row.cellIterator(); tempCtn = ""; // ctn Cell cell = row.getCell(0); tempCtn = cell.toString().trim(); if (tempCtn != null && !tempCtn.isEmpty()) { ctnList.add(tempCtn); } } // logger.warn("-----------------------------------------------------------------"); // for(int i=0; i<ctnList.size(); i++) { // logger.warn("ctnList[" + i + "] : " + ctnList.get(i)); // } // logger.warn("-----------------------------------------------------------------"); // ? (console) ? // ? ? '?' ?? vo.setInputType("console"); StringBuffer sbTempDevIdC = new StringBuffer(); for (int i = 0; i < ctnList.size(); i++) { sbTempDevIdC.append(ctnList.get(i) + "\n"); } // logger.warn("ctn str >>>>>\r\n" + sbTempDevIdC.toString()); vo.setDeviceIdC(sbTempDevIdC.toString()); vo = targetSVC.insertTargetGroup(vo); } catch (Exception e) { logger.warn("?? ? ."); e.printStackTrace(); model.addAttribute("msg", "?? ? ."); } // db ? ? upfile.delete(); return new ModelAndView(ajaxMainView, model); } /** * targetGroup insert * @param param * @param response * @return */ @RequestMapping(value = "/selectShowDevice") @ResponseBody public ModelAndView showDevice(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("TargetGroupVo") TargetGroupVo vo, ModelMap model) throws Exception { logger.warn("#############selectShowDevice################"); // user HttpSession httpSession = request.getSession(false); UserLoginVO userVo = (UserLoginVO) httpSession.getAttribute("userInfo"); String userId = userVo.getUserId(); vo.setMoId(userId); vo = targetSVC.insertTargetGroup(vo); return new ModelAndView(ajaxMainView, model); } /** * targetGroup detail * @param param * @param response * @return */ @RequestMapping(value = "/getDetailView") @ResponseBody public ModelAndView targetGroupDetailView(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("TargetGroupVo") TargetGroupVo vo, ModelMap model) throws Exception { logger.warn("#############targetGroupDetailView################" + vo.getGroupName()); String GroupName = VoV.replaceRoundBracket(vo.getGroupName()); vo.setGroupName(GroupName); vo = targetSVC.getDetailView(vo); return new ModelAndView(ajaxMainView, model); } /** * targetGroup delete * @param param * @param response * @return */ @RequestMapping(value = "/setDeleteGroup") @ResponseBody public ModelAndView targetGroupDelete(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("TargetGroupVo") TargetGroupVo vo, ModelMap model) throws Exception { logger.warn("#############setDeleteGroup################" + vo.getGroupName()); int retValue = -1; String GroupName = VoV.replaceRoundBracket(vo.getGroupName()); vo.setGroupName(GroupName); retValue = targetSVC.setDeleteGroup(vo); model.addAttribute("retValue", retValue); return new ModelAndView(ajaxMainView, model); } }