Skip to content

Commit

Permalink
fix a bug affecting duplication of non indexed cases
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 21, 2024
1 parent b9d7b67 commit 256056c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/java/com/powsybl/caseserver/CaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.zip.ZipOutputStream;

import static com.powsybl.caseserver.CaseException.createDirectoryNotFound;
import static com.powsybl.caseserver.dto.CaseInfos.*;

/**
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com>
Expand Down Expand Up @@ -230,12 +231,14 @@ UUID duplicateCase(UUID sourceCaseUuid, boolean withExpiration) {
newCaseFile = newCaseUuidDirectory.resolve(existingCaseFile.getFileName());
Files.copy(existingCaseFile, newCaseFile, StandardCopyOption.COPY_ATTRIBUTES);

CaseInfos existingCaseInfos = caseInfosService.getCaseInfosByUuid(sourceCaseUuid.toString()).orElseThrow();
CaseInfos caseInfos = createInfos(existingCaseInfos.getName(), newCaseUuid, existingCaseInfos.getFormat());
caseInfosService.addCaseInfos(caseInfos);

CaseMetadataEntity existingCase = getCaseMetaDataEntity(sourceCaseUuid);
CaseInfos caseInfos = createInfos(newCaseFile.getFileName().toString(), newCaseUuid, getFormat(newCaseFile));
if (existingCase.isIndexed()) {
caseInfosService.addCaseInfos(caseInfos);
}

createCaseMetadataEntity(newCaseUuid, withExpiration, existingCase.isIndexed());

sendImportMessage(caseInfos.createMessage());
return newCaseUuid;

Expand Down
24 changes: 24 additions & 0 deletions src/test/java/com/powsybl/caseserver/CaseControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,30 @@ public void test() throws Exception {
assertTrue(response.contains("\"format\":\"XIIDM\""));
}

@Test
public void testDuplicateNonIndexedCase() throws Exception {
// create the storage dir
createStorageDir();

// import IIDM test case
String caseUuid = mvc.perform(multipart("/v1/cases")
.file(createMockMultipartFile(TEST_CASE))
.param("withExpiration", "false")
.param("withIndexation", "false"))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
assertNotNull(outputDestination.receive(1000, caseImportDestination));
//duplicate an existing case
String duplicateCaseStr = mvc.perform(post("/v1/cases?duplicateFrom=" + caseUuid.substring(1, caseUuid.length() - 1)))
.andExpect(status().isOk())
.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 {
String importedCase;
if (withExpiration) {
Expand Down

0 comments on commit 256056c

Please sign in to comment.