Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,15 @@ public ResponseEntity<Void> cutAndPasteNode(@PathVariable("studyUuid") UUID stud
return ResponseEntity.ok().build();
}

@RequestMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/network", method = RequestMethod.HEAD)
@GetMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/network")
@Operation(summary = "check study root network existence")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "The network does exist"),
@ApiResponse(responseCode = "204", description = "The network doesn't exist")})
public ResponseEntity<Void> checkNetworkExistence(@PathVariable("studyUuid") UUID studyUuid, @PathVariable("rootNetworkUuid") UUID rootNetworkUuid) {
public ResponseEntity<RootNetworkStatusInfos> checkNetworkExistence(@PathVariable("studyUuid") UUID studyUuid, @PathVariable("rootNetworkUuid") UUID rootNetworkUuid) {
UUID networkUUID = rootNetworkService.getNetworkUuid(rootNetworkUuid);
return networkStoreService.doesNetworkExist(networkUUID)
? ResponseEntity.ok().build()
: ResponseEntity.noContent().build();

return ResponseEntity.ok().body(new RootNetworkStatusInfos(networkStoreService.doesNetworkExist(networkUUID),
rootNetworkService.getRootNetworkLoadStatus(rootNetworkUuid)));
Comment thread
ghazwarhili marked this conversation as resolved.
}

@PostMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/network", params = {"caseUuid"})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.gridsuite.study.server.dto;

@ghazwarhili ghazwarhili Sep 8, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

author and licence

public record RootNetworkStatusInfos(boolean exists, RootNetworkLoadStatus rootNetworkLoadStatus) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public UUID getNetworkUuid(UUID rootNetworkUuid) {
return getRootNetwork(rootNetworkUuid).map(RootNetworkEntity::getNetworkUuid).orElseThrow(() -> new StudyException(NOT_FOUND, "Root network not found"));
}

public RootNetworkLoadStatus getRootNetworkLoadStatus(UUID networkUuid) {
Optional<RootNetworkEntity> rootNetworkEntity = getRootNetwork(networkUuid);
return rootNetworkEntity.map(RootNetworkEntity::getLoadStatus).orElseThrow(() -> new StudyException(NOT_FOUND, "Root network not found"));
}

public UUID getRootReportUuid(UUID rootNetworkUuid) {
return getRootNetwork(rootNetworkUuid).map(RootNetworkEntity::getReportUuid).orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.head;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

/**
Expand Down Expand Up @@ -162,17 +164,18 @@ void testCheckNetworkExistenceReturnsOk() throws Exception {
}

@Test
void testCheckNetworkExistenceReturnsNotContent() throws Exception {
void testCheckNetworkExistenceReturnsNetworkNotFound() throws Exception {
Map<String, Object> importParameters = new HashMap<>();
importParameters.put("param1", "changedValue1, changedValue2");
importParameters.put("param2", "changedValue");
String userId = "userId";
UUID studyUuid = createStudy(userId, importParameters);
UUID firstRootNetworkUuid = studyTestUtils.getOneRootNetworkUuid(studyUuid);
when(networkStoreService.getNetwork(NETWORK_UUID)).thenThrow(new PowsyblException("Network '" + NETWORK_UUID + "' not found"));
mockMvc.perform(head("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/network", studyUuid, firstRootNetworkUuid)
mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/network", studyUuid, firstRootNetworkUuid)
.header(USER_ID_HEADER, userId))
.andExpect(status().isNoContent());
.andExpect(status().isOk())
.andExpect(jsonPath("$.exists").value(false));
}

@Test
Expand Down
Loading