Skip to content

Commit

Permalink
Merge branch 'supervision_remove_equipments_indexes' of https://githu…
Browse files Browse the repository at this point in the history
…b.com/gridsuite/study-server into supervision_remove_equipments_indexes
  • Loading branch information
sBouzols committed Oct 10, 2023
2 parents 342aa3b + 72d2a20 commit 8d8e49c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,19 @@ public List<UUID> getStudyDynamicSimulationResultUuids(UUID studyUuid) {
return resultUuids;
}

@Transactional(readOnly = true)
public List<UUID> getStudyVoltageInitResultUuids(UUID studyUuid) {
List<UUID> resultUuids = new ArrayList<>();
List<NodeEntity> nodes = nodesRepository.findAllByStudyId(studyUuid);
nodes.forEach(n -> {
UUID resultUuid = repositories.get(n.getType()).getVoltageInitResultUuid(n.getIdNode());
if (resultUuid != null) {
resultUuids.add(resultUuid);
}
});
return resultUuids;
}

private void getBuildInfos(NodeEntity nodeEntity, BuildInfos buildInfos) {
AbstractNode node = repositories.get(nodeEntity.getType()).getNode(nodeEntity.getIdNode());
if (node.getType() == NodeType.NETWORK_MODIFICATION) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,10 @@ public void invalidateLoadFlowStatusOnAllNodes(UUID studyUuid) {
loadflowService.invalidateLoadFlowStatus(networkModificationTreeService.getLoadFlowResultUuids(studyUuid));
}

public void invalidateVoltageInitStatusOnAllNodes(UUID studyUuid) {
voltageInitService.invalidateVoltageInitStatus(networkModificationTreeService.getStudyVoltageInitResultUuids(studyUuid));
}

private StudyEntity insertStudyEntity(UUID uuid, String userId, UUID networkUuid, String networkId,
String caseFormat, UUID caseUuid, String caseName, LoadFlowParametersEntity loadFlowParameters,
UUID importReportUuid, ShortCircuitParametersEntity shortCircuitParameters, DynamicSimulationParametersEntity dynamicSimulationParameters, UUID voltageInitParametersUuid, Map<String, String> importParameters) {
Expand Down Expand Up @@ -1302,6 +1306,7 @@ public void createOrUpdateVoltageInitParameters(UUID studyUuid, String parameter
} else {
voltageInitService.updateVoltageInitParameters(voltageInitParametersUuid, parameters);
}
invalidateVoltageInitStatusOnAllNodes(studyUuid);
}

public void updateSecurityAnalysisParameters(UUID studyUuid, SecurityAnalysisParametersEntity securityAnalysisParametersEntity) {
Expand Down Expand Up @@ -1932,6 +1937,7 @@ public UUID runVoltageInit(UUID studyUuid, UUID nodeUuid, String userId) {
@Transactional
public void setVoltageInitParameters(UUID studyUuid, String parameters, String userId) {
createOrUpdateVoltageInitParameters(studyUuid, parameters);
notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_VOLTAGE_INIT_STATUS);
notificationService.emitElementUpdated(studyUuid, userId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
*/
@Service
public class VoltageInitService {

static final String RESULT_UUID = "resultUuid";

private String voltageInitServerBaseUri;

@Autowired
Expand Down Expand Up @@ -259,4 +262,14 @@ public UUID getModificationsGroupUuid(UUID nodeUuid) {
return modificationsGroupUuid;
}

public void invalidateVoltageInitStatus(List<UUID> uuids) {
if (!uuids.isEmpty()) {
String path = UriComponentsBuilder
.fromPath(DELIMITER + VOLTAGE_INIT_API_VERSION + "/results/invalidate-status")
.queryParam(RESULT_UUID, uuids).build().toUriString();

restTemplate.put(voltageInitServerBaseUri + path, Void.class);
}
}

}
46 changes: 32 additions & 14 deletions src/test/java/org/gridsuite/study/server/VoltageInitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ public MockResponse dispatch(RecordedRequest request) {
.build(), voltageInitStoppedDestination);
return new MockResponse().setResponseCode(200)
.addHeader("Content-Type", "application/json; charset=utf-8");
} else if (path.matches("/v1/results/invalidate-status.*")) {
return new MockResponse().setResponseCode(200);
} else if (path.matches("/v1/parameters/" + VOLTAGE_INIT_PARAMETERS_UUID)) {
if (method.equals("PUT")) {
return new MockResponse().setResponseCode(200);
Expand Down Expand Up @@ -290,6 +292,22 @@ private void initMockBeans(Network network) {
when(networkStoreService.getNetwork(UUID.fromString(NETWORK_UUID_STRING))).thenReturn(network);
}

private void createOrUpdateParametersAndDoChecks(UUID studyNameUserIdUuid, String parameters) throws Exception {
mockMvc.perform(
post("/v1/studies/{studyUuid}/voltage-init/parameters", studyNameUserIdUuid)
.header("userId", "userId")
.contentType(MediaType.ALL)
.content(parameters)).andExpect(
status().isOk());

Message<byte[]> voltageInitStatusMessage = output.receive(TIMEOUT, studyUpdateDestination);
assertEquals(studyNameUserIdUuid, voltageInitStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID));
assertEquals(NotificationService.UPDATE_TYPE_VOLTAGE_INIT_STATUS, voltageInitStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE));

Message<byte[]> elementUpdateMessage = output.receive(TIMEOUT, elementUpdateDestination);
assertEquals(studyNameUserIdUuid, elementUpdateMessage.getHeaders().get(NotificationService.HEADER_ELEMENT_UUID));
}

@Test
public void testVoltageInitParameters() throws Exception {
//insert a study
Expand All @@ -302,13 +320,7 @@ public void testVoltageInitParameters() throws Exception {

JSONAssert.assertEquals(VOLTAGE_INIT_EMPTY_PARAMETERS, mvcResult.getResponse().getContentAsString(), JSONCompareMode.NON_EXTENSIBLE);

mockMvc.perform(
post("/v1/studies/{studyUuid}/voltage-init/parameters", studyNameUserIdUuid)
.header("userId", "userId")
.contentType(MediaType.ALL)
.content(VOLTAGE_INIT_PARAMETERS_JSON)).andExpect(
status().isOk());

createOrUpdateParametersAndDoChecks(studyNameUserIdUuid, VOLTAGE_INIT_PARAMETERS_JSON);
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/parameters")));

//checking update is registered
Expand All @@ -320,13 +332,7 @@ public void testVoltageInitParameters() throws Exception {
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/parameters/" + VOLTAGE_INIT_PARAMETERS_UUID)));

//update voltage init parameters
mockMvc.perform(
post("/v1/studies/{studyUuid}/voltage-init/parameters", studyNameUserIdUuid)
.header("userId", "userId")
.contentType(MediaType.ALL)
.content(VOLTAGE_INIT_PARAMETERS_JSON)).andExpect(
status().isOk());

createOrUpdateParametersAndDoChecks(studyNameUserIdUuid, VOLTAGE_INIT_PARAMETERS_JSON);
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/parameters/" + VOLTAGE_INIT_PARAMETERS_UUID)));

// insert a study with a wrong voltage init parameters uuid
Expand Down Expand Up @@ -397,6 +403,18 @@ public void testVoltageInit() throws Exception {

assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/results/" + VOLTAGE_INIT_RESULT_UUID + "/status")));

mockMvc.perform(
post("/v1/studies/{studyUuid}/voltage-init/parameters", studyNameUserIdUuid)
.header("userId", "userId")
.contentType(MediaType.ALL)
.content(VOLTAGE_INIT_PARAMETERS_JSON)).andExpect(
status().isOk());

assertTrue(TestUtils.getRequestsDone(2, server).stream().allMatch(r -> r.matches("/v1/parameters/" + VOLTAGE_INIT_PARAMETERS_UUID) || r.matches("/v1/results/invalidate-status.*")));
//remove notif about study updating due to parameters changes
output.receive(1000);
output.receive(1000);

// stop voltage init analysis
mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/voltage-init/stop", studyNameUserIdUuid, modificationNode3Uuid)).andExpect(status().isOk());

Expand Down

0 comments on commit 8d8e49c

Please sign in to comment.