From 209959320e8a30e45f63267bd3e6bcc31101b08b Mon Sep 17 00:00:00 2001 From: Etienne Homer Date: Thu, 7 Nov 2024 15:28:53 +0100 Subject: [PATCH] Remove 'summaries' + remove warning on multiple files Signed-off-by: Etienne Homer --- .../caseserver/service/S3CaseService.java | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/powsybl/caseserver/service/S3CaseService.java b/src/main/java/com/powsybl/caseserver/service/S3CaseService.java index fbb89b4..c66774b 100644 --- a/src/main/java/com/powsybl/caseserver/service/S3CaseService.java +++ b/src/main/java/com/powsybl/caseserver/service/S3CaseService.java @@ -197,9 +197,9 @@ public String uuidToKeyWithOriginalFileName(UUID caseUuid) { return uuidToKeyWithFileName(caseUuid, getOriginalFilename(caseUuid)); } - private List getCasesSummaries(String prefix) { + private List getCaseS3Objects(String keyPrefix) { List s3Objects = new ArrayList<>(); - ListObjectsV2Iterable listObjectsV2Iterable = s3Client.listObjectsV2Paginator(getListObjectsV2Request(prefix)); + ListObjectsV2Iterable listObjectsV2Iterable = s3Client.listObjectsV2Paginator(getListObjectsV2Request(keyPrefix)); listObjectsV2Iterable.iterator().forEachRemaining(listObjectsChunk -> s3Objects.addAll(listObjectsChunk.contents()) ); @@ -210,23 +210,8 @@ private ListObjectsV2Request getListObjectsV2Request(String prefix) { return ListObjectsV2Request.builder().bucket(bucketName).prefix(prefix).build(); } - private List getCaseFileSummaries(UUID caseUuid) { - List files = getCasesSummaries(uuidToKeyPrefix(caseUuid)); - if (files.size() > 1) { - LOGGER.warn("Multiple files for case {}", caseUuid); - } - return files; - } - - private List infosFromDownloadCaseFileSummaries(List objectSummaries) { - List caseInfosList = new ArrayList<>(); - for (S3Object objectSummary : objectSummaries) { - final var caseInfo = getCaseInfos(parseUuidFromKey(objectSummary.key())); - if (Objects.nonNull(caseInfo)) { - caseInfosList.add(caseInfo); - } - } - return caseInfosList; + private List getCaseS3Objects(UUID caseUuid) { + return getCaseS3Objects(uuidToKeyPrefix(caseUuid)); } @Override @@ -266,17 +251,24 @@ public Optional getCaseBytes(UUID caseUuid) { @Override public List getCases() { - List s3ObjectSummaries = getCasesSummaries(CASES_PREFIX); - return infosFromDownloadCaseFileSummaries(s3ObjectSummaries); + List caseInfosList = new ArrayList<>(); + CaseInfos caseInfos; + for (S3Object o : getCaseS3Objects(CASES_PREFIX)) { + caseInfos = getCaseInfos(parseUuidFromKey(o.key())); + if (Objects.nonNull(caseInfos)) { + caseInfosList.add(caseInfos); + } + } + return caseInfosList; } @Override public boolean caseExists(UUID uuid) { - return !getCasesSummaries(uuidToKeyPrefix(uuid)).isEmpty(); + return !getCaseS3Objects(uuid).isEmpty(); } public Boolean datasourceExists(UUID caseUuid, String fileName) { - if (getCaseFileSummaries(caseUuid).size() > 1 && fileName.equals(getCaseName(caseUuid))) { + if (getCaseS3Objects(caseUuid).size() > 1 && fileName.equals(getCaseName(caseUuid))) { return Boolean.FALSE; } @@ -324,7 +316,7 @@ public Set listName(UUID caseUuid, String regex) { // For a compressed file basename.xml.gz, listName() should return ['basename.xml']. That's why we remove the compression extension to the filename. fileNames = List.of(removeExtension(getOriginalFilename(caseUuid), "." + getCompressionFormat(caseUuid))); } else { - List s3Objects = getCaseFileSummaries(caseUuid); + List s3Objects = getCaseS3Objects(caseUuid); fileNames = s3Objects.stream().map(obj -> Paths.get(obj.key()).toString().replace(CASES_PREFIX + caseUuid.toString() + DELIMITER, "")).toList(); // For archived cases : if (isArchivedCaseFile(getOriginalFilename(caseUuid))) {