From ba9963457c9f71a87543e85b058c73867a3c6cd3 Mon Sep 17 00:00:00 2001 From: jinno Yun Date: Wed, 25 Sep 2024 15:01:53 +0900 Subject: [PATCH] =?UTF-8?q?#21=20Refactor:=20=ED=95=98=EB=82=98=EC=9D=98?= =?UTF-8?q?=20=EC=9D=B8=EC=A6=9D=EC=84=9C=20=EC=82=AD=EC=A0=9C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EB=A9=94=ED=83=80=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1=20:?= =?UTF-8?q?=20=EC=98=A4=EB=A5=98=20=EC=A1=B4=EC=9E=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compileJava/previous-compilation-data.bin | Bin 2183005 -> 2183005 bytes .../s3Storage/service/S3StorageService.java | 58 ++++++++++++++++-- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/web3-credential-server/build/tmp/compileJava/previous-compilation-data.bin b/web3-credential-server/build/tmp/compileJava/previous-compilation-data.bin index 3db4634b81dee137d4abe74ff55ac2136d4fae9b..7d178044cfd71582310c941af1e897d542cb230d 100644 GIT binary patch delta 165 zcmWl~yA6U+06@|3K)@e75ydZ`4H&}&I_98b141Z_D>ws%i8D9^iG_vb>q(54;^g%A zM(feNg>0Pm^1VHZD*L6^*YK&8XqC_~uEW3tCM?*PVum>uSi*q|i4{Do;bVg>0_?EI Q0Y{v0Mu-UUQ;DR^|Mho6%K!iX delta 165 zcmWl~u?>Pi06@`jAnJ(-2r3GSJ2(ZgWDVmCgb;cXTW8S9#0i{1bBPu8jlidPdFoyp z3Xi|=I{E&5pFedgPHmZAWu-- metadata = getPdfMetadata(fileName); - log.info("metadata = {}",metadata); - metadata.remove("page-" + pageNumberToRemove); - // 최종 PDF를 S3에 업로드 + // 기존 키들을 리스트로 변환 후 정렬 + List pageNumbers = new ArrayList<>(); + for (String key : metadata.keySet()) { + // "page-" 뒤의 숫자 추출 + if (key.startsWith("page-")) { + int pageNum = Integer.parseInt(key.substring(5)); + pageNumbers.add(pageNum); //pageNumbers 리스트에 페이지 넘버 다 넣기 + } + } + + // 페이지 번호 정렬 + pageNumbers.sort(Integer::compareTo); + int pageSize = getPageSize(pageNumberToRemove, pageNumbers); + + pageNumbers.removeIf(pageNum -> pageNum == pageNumberToRemove); + + for (int i = 0; i < pageNumbers.size(); i++) { + if (pageNumbers.get(i) > pageNumberToRemove) { + pageNumbers.set(i, pageNumbers.get(i) - pageSize); + } + } + System.out.println("pageNumbers = " + pageNumbers); + + // 새로운 메타데이터 해시맵 생성 + HashMap newMetadata = new HashMap<>(); + int newPageNumber = 1; + + // 기존 메타데이터의 값을 유지하면서 새로운 키로 추가 + for (int oldPageNum : pageNumbers) { + newMetadata.put("page-" + newPageNumber, metadata.get("page-" + oldPageNum)); + newPageNumber++; + } + + // 최종 PDF를 S3에 업로 try { - uploadToS3(fileName, metadata, finalPdfBytes); + uploadToS3(fileName, newMetadata, finalPdfBytes); } catch (S3Exception e) { throw new IOException("Failed to upload pdf to S3: " + e.getMessage()); } finally { @@ -364,7 +397,20 @@ public void deletePdfForPage(Wallet wallet, int pageNumberToRemove) throws IOExc } - private static void checkPageExist(boolean pageIndexToRemove, boolean pageIndexToRemove1, String pageNumberToRemove) { + //삭제할 인증서의 페이지 수 구하기 + private int getPageSize(int pageNumberToRemove, List pageNumbers) { + //삭제할 인증서와 다음 인증서의 차 구하기 (삭제할 인증서의 페이지 수 구하기) + for (int i = 0; i< pageNumbers.size(); i++){ + if (pageNumbers.get(i) == pageNumberToRemove){ + if (i != pageNumbers.size()-1){ + return pageNumbers.get(i+1) - pageNumbers.get(i); + } + } + } + return 0; + } + + private void checkPageExist(boolean pageIndexToRemove, boolean pageIndexToRemove1, String pageNumberToRemove) { if (pageIndexToRemove || pageIndexToRemove1) { throw new IllegalArgumentException(pageNumberToRemove); }