From 7b716f1c05a15fc58380e988fae6a1c8d3d23d0b Mon Sep 17 00:00:00 2001 From: jamal-khey Date: Thu, 22 Aug 2024 09:58:04 +0200 Subject: [PATCH] fix review comments Signed-off-by: jamal-khey --- src/main/java/com/powsybl/caseserver/CaseService.java | 8 ++++++-- .../java/com/powsybl/caseserver/CaseControllerTest.java | 2 -- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/powsybl/caseserver/CaseService.java b/src/main/java/com/powsybl/caseserver/CaseService.java index 942463b..cf2ddf5 100644 --- a/src/main/java/com/powsybl/caseserver/CaseService.java +++ b/src/main/java/com/powsybl/caseserver/CaseService.java @@ -115,7 +115,7 @@ public List getCases(Path directory) { private CaseInfos getCaseInfos(Path file) { try { - return createInfos(file.getFileName().toString(), UUID.fromString(file.getParent().getFileName().toString()), getFormat(file)); + return createInfos(file, UUID.fromString(file.getParent().getFileName().toString())); } catch (Exception e) { LOGGER.error("Error processing file {}: {}", file.getFileName(), e.getMessage(), e); return null; @@ -232,7 +232,7 @@ UUID duplicateCase(UUID sourceCaseUuid, boolean withExpiration) { Files.copy(existingCaseFile, newCaseFile, StandardCopyOption.COPY_ATTRIBUTES); CaseMetadataEntity existingCase = getCaseMetaDataEntity(sourceCaseUuid); - CaseInfos caseInfos = createInfos(newCaseFile.getFileName().toString(), newCaseUuid, getFormat(newCaseFile)); + CaseInfos caseInfos = createInfos(newCaseFile, newCaseUuid); if (existingCase.isIndexed()) { caseInfosService.addCaseInfos(caseInfos); } @@ -247,6 +247,10 @@ UUID duplicateCase(UUID sourceCaseUuid, boolean withExpiration) { } } + private CaseInfos createInfos(Path caseFile, UUID caseUuid) { + return createInfos(caseFile.getFileName().toString(), caseUuid, getFormat(caseFile)); + } + private CaseMetadataEntity getCaseMetaDataEntity(UUID caseUuid) { return caseMetadataRepository.findById(caseUuid).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "case " + caseUuid + " not found")); } diff --git a/src/test/java/com/powsybl/caseserver/CaseControllerTest.java b/src/test/java/com/powsybl/caseserver/CaseControllerTest.java index 92a6eb5..bdcfb5d 100644 --- a/src/test/java/com/powsybl/caseserver/CaseControllerTest.java +++ b/src/test/java/com/powsybl/caseserver/CaseControllerTest.java @@ -493,9 +493,7 @@ public void testDuplicateNonIndexedCase() throws Exception { .andReturn().getResponse().getContentAsString(); UUID duplicateCaseUuid = UUID.fromString(duplicateCaseStr.substring(1, duplicateCaseStr.length() - 1)); assertNotNull(outputDestination.receive(1000, caseImportDestination)); - assertFalse(caseMetadataRepository.findById(duplicateCaseUuid).get().isIndexed()); - } private UUID importCase(String testCase, Boolean withExpiration) throws Exception {