Skip to content

Commit d88b747

Browse files
authored
Loadflow modifications endpoint (#830)
Signed-off-by: LE SAULNIER Kevin <[email protected]>
1 parent ee669ca commit d88b747

File tree

6 files changed

+79
-0
lines changed

6 files changed

+79
-0
lines changed

src/main/java/org/gridsuite/study/server/RestResponseEntityExceptionHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ protected ResponseEntity<Object> handleStudyException(StudyException exception)
3434
STUDY_NOT_FOUND,
3535
NODE_NOT_FOUND,
3636
ROOT_NETWORK_NOT_FOUND,
37+
LOADFLOW_NOT_FOUND,
3738
SECURITY_ANALYSIS_NOT_FOUND,
3839
SENSITIVITY_ANALYSIS_NOT_FOUND,
3940
SHORT_CIRCUIT_ANALYSIS_NOT_FOUND,

src/main/java/org/gridsuite/study/server/StudyConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ private StudyConstants() {
4444

4545
public static final String DELIMITER = "/";
4646
public static final String QUERY_PARAM_VARIANT_ID = "variantId";
47+
public static final String QUERY_PARAM_NETWORK_UUID = "networkUuid";
4748
public static final String QUERY_PARAM_EQUIPMENT_TYPE = "equipmentType";
4849
public static final String QUERY_PARAM_ELEMENT_TYPE = "elementType";
4950
public static final String QUERY_PARAM_SIDE = "side";

src/main/java/org/gridsuite/study/server/controller/StudyController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,16 @@ public ResponseEntity<LoadFlowComputationInfos> getLoadFlowComputationInfos(@Par
764764
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(rootNetworkNodeInfoService.getLoadFlowComputationInfos(nodeUuid, rootNetworkUuid));
765765
}
766766

767+
@GetMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/loadflow/modifications")
768+
@Operation(summary = "Get the loadflow modifications on study node and root network")
769+
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The loadflow computation infos"),
770+
@ApiResponse(responseCode = "404", description = "The loadflow computation has not been found")})
771+
public ResponseEntity<String> getLoadFlowModifications(@Parameter(description = "Study UUID") @PathVariable("studyUuid") UUID studyUuid,
772+
@Parameter(description = "rootNetworkUuid") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid,
773+
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid) {
774+
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(rootNetworkNodeInfoService.getLoadFlowModifications(nodeUuid, rootNetworkUuid));
775+
}
776+
767777
@PutMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/loadflow/stop")
768778
@Operation(summary = "stop loadflow on study")
769779
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The loadflow has been stopped")})

src/main/java/org/gridsuite/study/server/service/LoadFlowService.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,23 @@ public String getLoadFlowResult(UUID resultUuid, String filters, Sort sort) {
143143
return result;
144144
}
145145

146+
public String getLoadFlowModifications(UUID resultUuid) {
147+
String result;
148+
149+
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath(DELIMITER + LOADFLOW_API_VERSION + "/results/{resultUuid}/modifications");
150+
String path = uriComponentsBuilder.buildAndExpand(resultUuid).toUriString();
151+
152+
try {
153+
result = restTemplate.getForObject(loadFlowServerBaseUri + path, String.class);
154+
} catch (HttpStatusCodeException e) {
155+
if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
156+
throw new StudyException(LOADFLOW_NOT_FOUND);
157+
}
158+
throw e;
159+
}
160+
return result;
161+
}
162+
146163
public LoadFlowStatus getLoadFlowStatus(UUID resultUuid) {
147164
LoadFlowStatus result;
148165

src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,15 @@ public LoadFlowComputationInfos getLoadFlowComputationInfos(UUID nodeUuid, UUID
655655
return new LoadFlowComputationInfos(isWithRatioTapChangers);
656656
}
657657

658+
@Transactional(readOnly = true)
659+
public String getLoadFlowModifications(UUID nodeUuid, UUID rootNetworkUuid) {
660+
UUID resultUuid = getComputationResultUuid(nodeUuid, rootNetworkUuid, LOAD_FLOW);
661+
if (resultUuid == null) {
662+
throw new StudyException(LOADFLOW_NOT_FOUND);
663+
}
664+
return loadFlowService.getLoadFlowModifications(resultUuid);
665+
}
666+
658667
@Transactional(readOnly = true)
659668
public SecurityAnalysisStatus getSecurityAnalysisStatus(UUID nodeUuid, UUID rootNetworkUuid) {
660669
UUID resultUuid = getComputationResultUuid(nodeUuid, rootNetworkUuid, SECURITY_ANALYSIS);

src/test/java/org/gridsuite/study/server/LoadFlowTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class LoadFlowTest {
145145
private static final String LOADFLOW_RESULT_DESTINATION = "loadflow.result";
146146
private static final String LOADFLOW_STOPPED_DESTINATION = "loadflow.stopped";
147147
private static final String LOADFLOW_FAILED_DESTINATION = "loadflow.run.dlx";
148+
private static final String LOADFLOW_MODIFICATIONS = "loadflow modifications mock";
148149

149150
@Autowired
150151
private MockMvc mockMvc;
@@ -274,6 +275,10 @@ public MockResponse dispatch(RecordedRequest request) {
274275
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), COMPUTING_STATUS_JSON);
275276
} else if (path.matches("/v1/results/" + LOADFLOW_RESULT_UUID + "/computation")) {
276277
return new MockResponse(404);
278+
} else if (path.matches("/v1/results/" + LOADFLOW_RESULT_UUID + "/modifications")) {
279+
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), "loadflow modifications mock");
280+
} else if (path.matches("/v1/results/" + LOADFLOW_ERROR_RESULT_UUID + "/modifications")) {
281+
return new MockResponse(404);
277282
} else if (path.matches("/v1/results/invalidate-status\\?resultUuid=" + LOADFLOW_RESULT_UUID)) {
278283
return new MockResponse(200);
279284
} else if (path.matches("/v1/results/invalidate-status\\?resultUuid=" + LOADFLOW_RESULT_UUID + "&resultUuid=" + LOADFLOW_OTHER_NODE_RESULT_UUID)) {
@@ -958,6 +963,42 @@ void testInvalidateNodesAfterLoadflow(final MockWebServer server) throws Excepti
958963
assertEquals(NodeBuildStatusEmbeddable.from(BuildStatus.NOT_BUILT), rootNetworkNodeInfoService.getRootNetworkNodeInfo(node3.getId(), rootNetworkUuid).map(RootNetworkNodeInfoEntity::getNodeBuildStatus).orElseThrow());
959964
}
960965

966+
@Test
967+
void testGetLoadFlowModification(final MockWebServer server) throws Exception {
968+
StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_LOADFLOW_UUID, LOADFLOW_PARAMETERS_UUID);
969+
UUID studyUuid = studyEntity.getId();
970+
UUID rootNetworkUuid = studyTestUtils.getOneRootNetworkUuid(studyUuid);
971+
RootNode rootNode = getRootNode(studyUuid);
972+
NetworkModificationNode node1 = createNetworkModificationConstructionNode(studyUuid, rootNode.getId(), UUID.randomUUID(), VARIANT_ID, "N1");
973+
updateLoadflowResultUuid(node1.getId(), rootNetworkUuid, UUID.fromString(LOADFLOW_RESULT_UUID));
974+
975+
MvcResult mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/loadflow/modifications", studyUuid, rootNetworkUuid, node1.getId()))
976+
.andExpect(status().isOk())
977+
.andReturn();
978+
979+
assertEquals(LOADFLOW_MODIFICATIONS, mvcResult.getResponse().getContentAsString());
980+
981+
assertRequestsDone(server, List.of("/v1/results/" + LOADFLOW_RESULT_UUID + "/modifications"));
982+
}
983+
984+
@Test
985+
void testGetLoadFlowModificationNotFound(final MockWebServer server) throws Exception {
986+
StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_LOADFLOW_UUID, LOADFLOW_PARAMETERS_UUID);
987+
UUID studyUuid = studyEntity.getId();
988+
UUID rootNetworkUuid = studyTestUtils.getOneRootNetworkUuid(studyUuid);
989+
RootNode rootNode = getRootNode(studyUuid);
990+
NetworkModificationNode node1 = createNetworkModificationConstructionNode(studyUuid, rootNode.getId(), UUID.randomUUID(), VARIANT_ID, "N1");
991+
992+
mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/loadflow/modifications", studyUuid, rootNetworkUuid, node1.getId()))
993+
.andExpect(status().isNotFound());
994+
995+
updateLoadflowResultUuid(node1.getId(), rootNetworkUuid, UUID.fromString(LOADFLOW_ERROR_RESULT_UUID));
996+
mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/loadflow/modifications", studyUuid, rootNetworkUuid, node1.getId()))
997+
.andExpect(status().isNotFound());
998+
999+
assertRequestsDone(server, List.of("/v1/results/" + LOADFLOW_ERROR_RESULT_UUID + "/modifications"));
1000+
}
1001+
9611002
private void updateNodeBuildStatus(UUID nodeId, UUID rootNetworkUuid, BuildStatus buildStatus) {
9621003
RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(nodeId, rootNetworkUuid).orElseThrow();
9631004
rootNetworkNodeInfoEntity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(buildStatus));

0 commit comments

Comments
 (0)