조민수 조민수 03-27
fix: 잘못 반영된 파일 롤백
@a7cdb5a3e30aeb7913fdc1db8964e7214158cad5
src/main/java/egovframework/com/cmm/web/EgovFileDownloadController.java
--- src/main/java/egovframework/com/cmm/web/EgovFileDownloadController.java
+++ src/main/java/egovframework/com/cmm/web/EgovFileDownloadController.java
@@ -10,7 +10,6 @@
 import java.io.PrintWriter;
 import java.net.URLEncoder;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -107,7 +106,7 @@
 		String browser = getBrowser(request);
 
 		String dispositionPrefix = "attachment; filename=";
-		String encodedFilename = URLEncoder.encode(filename, "UTF-8").replaceAll("\\+", "%20");
+		String encodedFilename = null;
 
 		if (browser.equals("MSIE")) {
 			encodedFilename = URLEncoder.encode(filename, "UTF-8").replaceAll("\\+", "%20");
@@ -133,8 +132,7 @@
 			throw new IOException("Not supported browser");
 		}
 
-		response.setHeader("Content-Disposition",
-				"attachment; filename=\"" + encodedFilename + "\"; filename*=UTF-8''" + encodedFilename);
+		response.setHeader("Content-Disposition", dispositionPrefix + encodedFilename);
 
 		if ("Opera".equals(browser)) {
 			response.setContentType("application/octet-stream;charset=UTF-8");
@@ -740,71 +738,134 @@
 	
 	/* 파일 다운로드 - 일괄 zip 압축(사업관리)*/
 	@RequestMapping(value = "/cmm/fms/bizFileDownZip.do")
-	public void bizFileDownZip(@RequestParam Map<String, Object> commandMap,
-							   @ModelAttribute("bizCntrtVO") BizCntrtVO bizCntrtVO,
-							   BizItemVO bizItemVO,
-							   HttpServletRequest request,
-							   HttpServletResponse response) throws Exception {
-		List<String> atchFileIdList = new ArrayList<>();
-
-		if (bizItemVO.getAtchFileId() != null && !bizItemVO.getAtchFileId().trim().isEmpty()) {
-			String[] splitStr = bizItemVO.getAtchFileId().split(",");
-			for (String id : splitStr) {
-				if (id != null && !id.trim().isEmpty()) {
-					atchFileIdList.add(id.trim());
-				}
-			}
+	public void bizFileDownZip(@RequestParam Map<String, Object> commandMap, @ModelAttribute("bizCntrtVO") BizCntrtVO bizCntrtVO,
+			BizItemVO bizItemVO,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		
+		//파일ID를 리스트에 담기
+		List<String> atchFileIdList = new ArrayList<String>();
+		//split을 이용해 아이디를 각자 배열에 담기
+		String[] splitStr =bizItemVO.getAtchFileId().split(",");
+		//리스트에 아이디 담기
+		for(int i=0; i<splitStr.length; i++) {
+			atchFileIdList.add(splitStr[i]);
 		}
-
-		FileVO fileVO = new FileVO();
-		fileVO.setAtchFileIdList(!atchFileIdList.isEmpty() ? atchFileIdList : null);
-
-		List<FileVO> fvoList = fileService.selectBizFileInfs(fileVO);
-
-		if (fvoList == null || fvoList.isEmpty()) {
-			response.sendError(HttpServletResponse.SC_NOT_FOUND, "파일이 존재하지 않습니다.");
-			return;
-		}
-
+		
+		//zip파일 이름 (메뉴명+글 제목명 +날짜)
 		String menuNm = "사업관리";
-		String orgnZipNm = menuNm + "_"
-				+ bizCntrtVO.getBizNm() + "_"
-				+ bizCntrtVO.getFrstRegistPnttm() + ".zip";
-
-		response.reset();
-		response.setContentType("application/zip");
-
-		String encodedFileName = URLEncoder.encode(orgnZipNm, "UTF-8").replaceAll("\\+", "%20");
-
-		response.setHeader("Content-Disposition",
-				"attachment; filename=\"" + encodedFileName + "\"; filename*=UTF-8''" + encodedFileName);
-
-		byte[] buffer = new byte[1024];
-
-		try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(response.getOutputStream())) {
-
-			zos.setEncoding("UTF-8");
-
-			for (FileVO vo : fvoList) {
-
-				File file = new File(vo.getFileStreCours(), vo.getStreFileNm());
-
-				if (!file.exists()) continue;
-
-				try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file))) {
-
-					zos.putArchiveEntry(new ZipArchiveEntry(vo.getOrignlFileNm()));
-
-					int len;
-					while ((len = bis.read(buffer)) != -1) {
-						zos.write(buffer, 0, len);
+		String orgnZipNm = menuNm+"_"+bizCntrtVO.getBizNm()+"_"+bizCntrtVO.getFrstRegistPnttm()+".zip"; // 압축 파일명 필요..
+		
+		
+		FileVO fileVO = new FileVO();
+		fileVO.setAtchFileIdList(atchFileIdList);
+		List<FileVO> fvoList = fileService.selectBizFileInfs(fileVO); // 해당 기능에 맞게 파일 조회
+		
+		if(fvoList.size() == 0){
+			response.setContentType("application/x-msdownload");
+			PrintWriter printwriter = response.getWriter();
+			printwriter.println("<html>");
+			printwriter.println("<br><br><br><h2>Could not get file name:<br></h2>");
+			printwriter.println("<br><br><br><center><h3><a href='javascript: history.go(-1)'>Back</a></h3></center>");
+			printwriter.println("<br><br><br>&copy; webAccess");
+			printwriter.println("</html>");
+			printwriter.flush();
+			printwriter.close();
+			return ;
+		}
+		
+		
+		// buffer size
+        int size = 1024;
+        byte[] buf = new byte[size];
+        
+        String outZipNm = fvoList.get(0).getFileStreCours()+File.separator + orgnZipNm;
+        FileInputStream fis = null;
+        ZipArchiveOutputStream zos = null;
+        BufferedInputStream bis = null;
+         
+        try {
+            // Zip 파일생성
+            zos = new ZipArchiveOutputStream(new BufferedOutputStream(new FileOutputStream(outZipNm)));
+            
+            for ( FileVO vo :  fvoList ){
+                zos.setEncoding("UTF-8");
+                 
+                //buffer에 해당파일의 stream을 입력한다.
+                fis = new FileInputStream(vo.getFileStreCours() + "/" + vo.getStreFileNm());
+                bis = new BufferedInputStream(fis,size);
+                 
+                //zip에 넣을 다음 entry 를 가져온다.
+                zos.putArchiveEntry(new ZipArchiveEntry(vo.getOrignlFileNm()));
+                 
+                //준비된 버퍼에서 집출력스트림으로 write 한다.
+                int len;
+                while((len = bis.read(buf,0,size)) != -1) zos.write(buf,0,len);
+                 
+                bis.close();
+                fis.close();
+                zos.closeArchiveEntry();
+            }
+            
+            zos.close();
+ 
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        }finally{
+            if( zos != null ) zos.close();
+            if( fis != null ) fis.close();
+            if( bis != null ) bis.close();
+        }
+        
+		File uFile = new File(fvoList.get(0).getFileStreCours(), orgnZipNm);
+		long fSize = uFile.length();
+		
+		if (fSize > 0) {
+			String mimetype = "application/x-msdownload";
+			
+			response.setContentType(mimetype);
+			setDisposition(orgnZipNm, request, response);
+			//response.setContentLength(fSize);
+			
+			BufferedInputStream in = null;
+			BufferedOutputStream out = null;
+			
+			try {
+				in = new BufferedInputStream(new FileInputStream(uFile));
+				out = new BufferedOutputStream(response.getOutputStream());
+				
+				FileCopyUtils.copy(in, out);
+				out.flush();
+			} catch (Exception ex) {
+				LOGGER.debug("IGNORED: {}", ex.getMessage());
+			} finally {
+				if (in != null) {
+					try {
+						in.close();
+					} catch (Exception ignore) {
+						LOGGER.debug("IGNORED: {}", ignore.getMessage());
 					}
-
-					zos.closeArchiveEntry();
+				}
+				if (out != null) {
+					try {
+						out.close();
+					} catch (Exception ignore) {
+						LOGGER.debug("IGNORED: {}", ignore.getMessage());
+					}
 				}
 			}
-
-			zos.finish();
+			//파일 다운로드 후 파일 삭제
+			File delFile = new File(outZipNm);
+			delFile.delete();
+		} else {
+			response.setContentType("application/x-msdownload");
+			PrintWriter printwriter = response.getWriter();
+			printwriter.println("<html>");
+			printwriter.println("<br><br><br><h2>Could not get file name:<br>" + orgnZipNm + "</h2>");
+			printwriter.println("<br><br><br><center><h3><a href='javascript: history.go(-1)'>Back</a></h3></center>");
+			printwriter.println("<br><br><br>&copy; webAccess");
+			printwriter.println("</html>");
+			printwriter.flush();
+			printwriter.close();
 		}
 	}
 	
src/main/java/egovframework/let/itsm/security/service/RuleVO.java
--- src/main/java/egovframework/let/itsm/security/service/RuleVO.java
+++ src/main/java/egovframework/let/itsm/security/service/RuleVO.java
@@ -88,5 +88,5 @@
 	public void setRuleDetailUrl(String ruleDetailUrl) {
 		this.ruleDetailUrl = ruleDetailUrl;
 	}
-
+	
 }
src/main/webapp/WEB-INF/jsp/uss/itsm/bizCntrt/BizCntrtView.jsp
--- src/main/webapp/WEB-INF/jsp/uss/itsm/bizCntrt/BizCntrtView.jsp
+++ src/main/webapp/WEB-INF/jsp/uss/itsm/bizCntrt/BizCntrtView.jsp
@@ -607,9 +607,10 @@
 		var frm = document.writeForm
 		window.opener.name="parentPage";
 		frm.target = "parentPage";
-		frm.action="/cmm/fms/bizFileDownZip.do?";
+		frm.action="/cmm/fms/bizFileDownZip.do?atchFileId="+checkboxId;
 		frm.submit();
-	}
+		
+		}
 
 /* 감사기간 validate */
 function validateDate(neceFlag){
Add a comment
List