From 75dc800e9b00924c0d47fc271081caea378feae5 Mon Sep 17 00:00:00 2001 From: jinno Yun Date: Wed, 25 Sep 2024 16:15:06 +0900 Subject: [PATCH] =?UTF-8?q?#21=20Refactor:=20=EB=A9=94=ED=83=80=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=88=98=EC=A0=95=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?changeForNewMetadata=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A1=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../s3Storage/service/S3StorageService.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/web3-credential-server/src/main/java/web3/s3Storage/service/S3StorageService.java b/web3-credential-server/src/main/java/web3/s3Storage/service/S3StorageService.java index 938f5c3..3239aec 100644 --- a/web3-credential-server/src/main/java/web3/s3Storage/service/S3StorageService.java +++ b/web3-credential-server/src/main/java/web3/s3Storage/service/S3StorageService.java @@ -354,6 +354,20 @@ public void deletePdfForPage(Wallet wallet, int pageNumberToRemove) throws IOExc HashMap metadata = getPdfMetadata(fileName); // 기존 키들을 리스트로 변환 후 정렬 + HashMap newMetadata = changeForNewMetadata(pageNumberToRemove, metadata); + + // 최종 PDF를 S3에 업로 + try { + uploadToS3(fileName, newMetadata, finalPdfBytes); + } catch (S3Exception e) { + throw new IOException("Failed to upload pdf to S3: " + e.getMessage()); + } finally { + originalDocument.close(); + } + + } + + private HashMap changeForNewMetadata(int pageNumberToRemove, HashMap metadata) { List pageNumbers = new ArrayList<>(); for (String key : metadata.keySet()) { // "page-" 뒤의 숫자 추출 @@ -362,7 +376,6 @@ public void deletePdfForPage(Wallet wallet, int pageNumberToRemove) throws IOExc pageNumbers.add(pageNum); //pageNumbers 리스트에 페이지 넘버 다 넣기 } } - System.out.println("metadata = " + metadata); // 페이지 번호 정렬 pageNumbers.sort(Integer::compareTo); int pageSize = getPageSize(pageNumberToRemove, pageNumbers); @@ -387,23 +400,11 @@ public void deletePdfForPage(Wallet wallet, int pageNumberToRemove) throws IOExc for (int newPageNum : newPageNumbers) { if(newPageNum + pageSize > pageNumberToRemove) { newMetadata.put("page-" + newPageNum, metadata.get("page-" + (newPageNum+pageSize))); - System.out.println("newPageNum+pageSize = " + newPageNum+pageSize); }else{ newMetadata.put("page-" + newPageNum, metadata.get("page-" + newPageNum)); - System.out.println("newPageNum = " + newPageNum); } } - System.out.println("newMetadata = " + newMetadata); - - // 최종 PDF를 S3에 업로 - try { - uploadToS3(fileName, newMetadata, finalPdfBytes); - } catch (S3Exception e) { - throw new IOException("Failed to upload pdf to S3: " + e.getMessage()); - } finally { - originalDocument.close(); - } - + return newMetadata; } //삭제할 인증서의 페이지 수 구하기