Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
Signed-off-by: jamal-khey <[email protected]>
  • Loading branch information
jamal-khey committed Aug 22, 2024
1 parent 256056c commit 7b716f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/main/java/com/powsybl/caseserver/CaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public List<CaseInfos> 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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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"));
}
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/com/powsybl/caseserver/CaseControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7b716f1

Please sign in to comment.