Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into move_shortcircuit_par…
Browse files Browse the repository at this point in the history
…ameters
  • Loading branch information
Tristan-WorkGH committed Jun 19, 2024
2 parents 43b122d + 2227bf2 commit d36509d
Show file tree
Hide file tree
Showing 41 changed files with 1,012 additions and 162 deletions.
22 changes: 1 addition & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@
</developers>

<properties>
<gridsuite-dependencies.version>29</gridsuite-dependencies.version>
<gridsuite-dependencies.version>30</gridsuite-dependencies.version>
<log4j2-mock-version>0.0.2</log4j2-mock-version>
<testcontainers.version>1.18.3</testcontainers.version>
<liquibase-hibernate-package>org.gridsuite.study.server</liquibase-hibernate-package>
<apache.httpclient.version>5.3</apache.httpclient.version>
<!-- FIXME: powsybl-network-store modules'version is overloaded in the dependencies section.The overloads and this property below have to be removed at next powsybl-ws-dependencies.version upgrade -->
<powsybl-network-store.version>1.11.1</powsybl-network-store.version>
</properties>

<build>
Expand Down Expand Up @@ -84,24 +82,6 @@
<dependencyManagement>
<dependencies>
<!-- overrides of imports -->
<!-- FIXME: to be removed at next powsybl-ws-dependencies upgrade -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-iidm-impl</artifactId>
<version>${powsybl-network-store.version}</version>
</dependency>
<!-- FIXME: to be removed at next powsybl-ws-dependencies upgrade -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-client</artifactId>
<version>${powsybl-network-store.version}</version>
</dependency>
<!-- FIXME: to be removed at next powsybl-ws-dependencies upgrade -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-model</artifactId>
<version>${powsybl-network-store.version}</version>
</dependency>

<!-- imports -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ protected ResponseEntity<Object> handleStudyException(StudyException exception)
VOLTAGE_INIT_PARAMETERS_NOT_FOUND,
SECURITY_ANALYSIS_PARAMETERS_NOT_FOUND,
LOADFLOW_PARAMETERS_NOT_FOUND,
SENSITIVITY_ANALYSIS_PARAMETERS_NOT_FOUND
SENSITIVITY_ANALYSIS_PARAMETERS_NOT_FOUND,
STATE_ESTIMATION_NOT_FOUND
-> ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getType());
case CASE_NOT_FOUND -> ResponseEntity.status(HttpStatus.FAILED_DEPENDENCY).body(exception.getMessage());
case STUDY_ALREADY_EXISTS -> ResponseEntity.status(HttpStatus.CONFLICT).body(type);
Expand All @@ -54,7 +55,8 @@ protected ResponseEntity<Object> handleStudyException(StudyException exception)
NON_EVACUATED_ENERGY_RUNNING,
DYNAMIC_SIMULATION_RUNNING,
SHORT_CIRCUIT_ANALYSIS_RUNNING,
VOLTAGE_INIT_RUNNING
VOLTAGE_INIT_RUNNING,
STATE_ESTIMATION_RUNNING
-> ResponseEntity.status(HttpStatus.FORBIDDEN).body(type);
case NOT_ALLOWED,
BAD_NODE_TYPE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private StudyConstants() {
public static final String TIME_SERIES_API_VERSION = "v1";
public static final String DYNAMIC_MAPPING_API_VERSION = ""; // mapping server is now without version, must be v1 in the next time
public static final String FILTER_API_VERSION = "v1";
public static final String STATE_ESTIMATION_API_VERSION = "v1";

public static final String NETWORK_UUID = "networkUuid";
public static final String CASE_UUID = "caseUuid";
Expand Down
55 changes: 50 additions & 5 deletions src/main/java/org/gridsuite/study/server/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class StudyController {
private final LoadFlowService loadflowService;
private final CaseService caseService;
private final RemoteServicesInspector remoteServicesInspector;
private final StateEstimationService stateEstimationService;

public StudyController(StudyService studyService,
NetworkService networkStoreService,
Expand All @@ -91,7 +92,8 @@ public StudyController(StudyService studyService,
VoltageInitService voltageInitService,
LoadFlowService loadflowService,
CaseService caseService,
RemoteServicesInspector remoteServicesInspector) {
RemoteServicesInspector remoteServicesInspector,
StateEstimationService stateEstimationService) {
this.studyService = studyService;
this.networkModificationTreeService = networkModificationTreeService;
this.networkStoreService = networkStoreService;
Expand All @@ -105,6 +107,7 @@ public StudyController(StudyService studyService,
this.loadflowService = loadflowService;
this.caseService = caseService;
this.remoteServicesInspector = remoteServicesInspector;
this.stateEstimationService = stateEstimationService;
}

@InitBinder
Expand Down Expand Up @@ -449,18 +452,17 @@ public ResponseEntity<String> getSubstationMapData(
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getSubstationMapData(studyUuid, nodeUuid, substationId, inUpstreamBuiltParentNode));
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/network/elements")
@PostMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/network/elements")
@Operation(summary = "Get network elements infos")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The list of network elements infos")})
public ResponseEntity<String> getNetworkElementsInfos(
@PathVariable("studyUuid") UUID studyUuid,
@PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "Substations id") @RequestParam(name = "substationsIds", required = false) List<String> substationsIds,
@Parameter(description = "Element type") @RequestParam(name = "elementType") String elementType,
@RequestBody String equipmentInfos,
@Parameter(description = "Info type") @RequestParam(name = "infoType") String infoType,
@Parameter(description = "Should get in upstream built node ?") @RequestParam(value = "inUpstreamBuiltParentNode", required = false, defaultValue = "false") boolean inUpstreamBuiltParentNode) {

return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getNetworkElementsInfos(studyUuid, nodeUuid, substationsIds, elementType, infoType, inUpstreamBuiltParentNode));
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getNetworkElementsInfos(studyUuid, nodeUuid, equipmentInfos, infoType, inUpstreamBuiltParentNode));
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/network/elements/{elementId}")
Expand Down Expand Up @@ -1902,4 +1904,47 @@ public ResponseEntity<String> exportFilter(
@Parameter(description = "Filter uuid to be applied") @PathVariable("filterUuid") UUID filterUuid) {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.exportFilter(studyUuid, filterUuid));
}

@PostMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/state-estimation/run")
@Operation(summary = "run state estimation on study")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The state estimation has started")})
public ResponseEntity<Void> runStateEstimation(@Parameter(description = "studyUuid") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid,
@RequestHeader(HEADER_USER_ID) String userId) {
studyService.assertIsNodeNotReadOnly(nodeUuid);
studyService.runStateEstimation(studyUuid, nodeUuid, userId);
return ResponseEntity.ok().build();
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/state-estimation/result")
@Operation(summary = "Get a state estimation result on study")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The state estimation result"),
@ApiResponse(responseCode = "204", description = "No state estimation has been done yet"),
@ApiResponse(responseCode = "404", description = "The state estimation has not been found")})
public ResponseEntity<String> getStateEstimationResult(@Parameter(description = "study UUID") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid) {
String result = stateEstimationService.getStateEstimationResult(nodeUuid);
return result != null ? ResponseEntity.ok().body(result) :
ResponseEntity.noContent().build();
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/state-estimation/status")
@Operation(summary = "Get the state estimation status on study")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The state estimation status"),
@ApiResponse(responseCode = "204", description = "No state estimation has been done yet"),
@ApiResponse(responseCode = "404", description = "The state estimation status has not been found")})
public ResponseEntity<String> getStateEstimationStatus(@Parameter(description = "Study UUID") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid) {
String status = stateEstimationService.getStateEstimationStatus(nodeUuid);
return status != null ? ResponseEntity.ok().body(status) : ResponseEntity.noContent().build();
}

@PutMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/state-estimation/stop")
@Operation(summary = "stop state estimation on study")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The state estimation has been stopped")})
public ResponseEntity<Void> stopStateEstimation(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid) {
stateEstimationService.stopStateEstimation(studyUuid, nodeUuid);
return ResponseEntity.ok().build();
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/gridsuite/study/server/StudyException.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public enum Type {
NOT_IMPLEMENTED,
EVALUATE_FILTER_FAILED,
GET_USER_PROFILE_FAILED,
STATE_ESTIMATION_RUNNING,
STATE_ESTIMATION_NOT_FOUND,
STATE_ESTIMATION_ERROR,
}

private final Type type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public SupervisionController(SupervisionService supervisionService, StudyService

@DeleteMapping(value = "/computation/results")
@Operation(summary = "delete all results of a given computation")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "all loadflow results have been deleted")})
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "all computation results have been deleted")})
public ResponseEntity<Integer> deleteComputationResults(@Parameter(description = "Computation type") @RequestParam("type") ComputationType computationType,
@Parameter(description = "Dry run") @RequestParam("dryRun") boolean dryRun) {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(supervisionService.deleteComputationResults(computationType, dryRun));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public enum ComputationType {
NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_FAILED),
SHORT_CIRCUIT_ONE_BUS("One bus Short circuit analysis", "oneBusShortCircuitAnalysisResultUuid",
NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_STATUS, NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_RESULT,
NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_FAILED);
NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_FAILED),
STATE_ESTIMATION("State estimation", "stateEstimationResultUuid",
NotificationService.UPDATE_TYPE_STATE_ESTIMATION_STATUS, NotificationService.UPDATE_TYPE_STATE_ESTIMATION_RESULT,
NotificationService.UPDATE_TYPE_STATE_ESTIMATION_FAILED);

private final String label; // used for logs
private final String resultUuidLabel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class DeleteNodeInfos {
private List<UUID> voltageInitResultUuids = new ArrayList<>();
private List<UUID> dynamicSimulationResultUuids = new ArrayList<>();

private List<UUID> stateEstimationResultUuids = new ArrayList<>();

public void addModificationGroupUuid(UUID modificationGroupUuid) {
modificationGroupUuids.add(modificationGroupUuid);
}
Expand Down Expand Up @@ -86,4 +88,8 @@ public void addOneBusShortCircuitAnalysisResultUuid(UUID oneBusShortCircuitAnaly
public void addVoltageInitResultUuid(UUID voltageInitResultUuid) {
voltageInitResultUuids.add(voltageInitResultUuid);
}

public void addStateEstimationResultUuid(UUID stateEstimationResultUuid) {
stateEstimationResultUuids.add(stateEstimationResultUuid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class InvalidateNodeInfos {
private List<UUID> voltageInitResultUuids = new ArrayList<>();
private List<UUID> dynamicSimulationResultUuids = new ArrayList<>();

private List<UUID> stateEstimationResultUuids = new ArrayList<>();

public void addReportUuid(UUID reportUuid) {
reportUuids.add(reportUuid);
}
Expand Down Expand Up @@ -92,4 +94,8 @@ public void addVoltageInitResultUuid(UUID voltageInitResultUuid) {
public void addDynamicSimulationResultUuid(UUID dynamicSimulationResultUuid) {
dynamicSimulationResultUuids.add(dynamicSimulationResultUuid);
}

public void addStateEstimationResultUuid(UUID stateEstimationResultUuid) {
stateEstimationResultUuids.add(stateEstimationResultUuid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ public class NodeModificationInfos {
private UUID voltageInitUuid;

private UUID dynamicSimulationUuid;

private UUID stateEstimationUuid;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.study.server.dto;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
public enum StateEstimationStatus {
NOT_DONE,
RUNNING,
COMPLETED,
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,14 @@ private String buildTombstonedEquipmentSearchQuery(UUID networkUuid, String vari
return String.format(NETWORK_UUID + ":(%s) AND " + VARIANT_ID + ":(%s)", networkUuid, variantId);
}

private BoolQuery buildSearchEquipmentsQuery(String userInput, EquipmentInfosService.FieldSelector fieldSelector, UUID networkUuid, String initialVariantId, String variantId, String equipmentType) {
private BoolQuery buildSearchEquipmentsQuery(String userInput, EquipmentInfosService.FieldSelector fieldSelector, UUID networkUuid, String variantId, String equipmentType) {
// If search requires boolean logic or advanced text analysis, then use queryStringQuery.
// Otherwise, use wildcardQuery for simple text search.
WildcardQuery equipmentSearchQuery = Queries.wildcardQuery(fieldSelector == EquipmentInfosService.FieldSelector.NAME ? EQUIPMENT_NAME : EQUIPMENT_ID, "*" + escapeLucene(userInput) + "*");
TermQuery networkUuidSearchQuery = Queries.termQuery(NETWORK_UUID, networkUuid.toString());
TermsQuery variantIdSearchQuery = variantId.equals(VariantManagerConstants.INITIAL_VARIANT_ID) ?
new TermsQuery.Builder().field(VARIANT_ID).terms(new TermsQueryField.Builder().value(List.of(FieldValue.of(initialVariantId))).build()).build() :
new TermsQuery.Builder().field(VARIANT_ID).terms(new TermsQueryField.Builder().value(List.of(FieldValue.of(initialVariantId), FieldValue.of(variantId))).build()).build();
new TermsQuery.Builder().field(VARIANT_ID).terms(new TermsQueryField.Builder().value(List.of(FieldValue.of(VariantManagerConstants.INITIAL_VARIANT_ID))).build()).build() :
new TermsQuery.Builder().field(VARIANT_ID).terms(new TermsQueryField.Builder().value(List.of(FieldValue.of(VariantManagerConstants.INITIAL_VARIANT_ID), FieldValue.of(variantId))).build()).build();

BoolQuery.Builder boolQueryBuilder = new BoolQuery.Builder()
.filter(
Expand Down Expand Up @@ -341,7 +341,9 @@ private List<EquipmentInfos> cleanRemovedEquipments(UUID networkUuid, String var

return equipmentInfos
.stream()
.filter(ei -> !removedEquipmentIdsInVariant.contains(ei.getId()))
.filter(ei -> !removedEquipmentIdsInVariant.contains(ei.getId()) ||
// If the equipment has been recreated after the creation of a deletion hypothesis
!ei.getVariantId().equals(VariantManagerConstants.INITIAL_VARIANT_ID))
.collect(Collectors.toList());
}

Expand All @@ -354,7 +356,7 @@ public List<EquipmentInfos> searchEquipments(@lombok.NonNull UUID networkUuid, @
String effectiveVariantId = variantId.isEmpty() ? VariantManagerConstants.INITIAL_VARIANT_ID : variantId;

BoolQuery query = buildSearchEquipmentsQuery(userInput, fieldSelector, networkUuid,
VariantManagerConstants.INITIAL_VARIANT_ID, variantId, equipmentType);
variantId, equipmentType);
List<EquipmentInfos> equipmentInfos = searchEquipments(query);
return variantId.equals(VariantManagerConstants.INITIAL_VARIANT_ID) ? equipmentInfos : cleanModifiedAndRemovedEquipments(networkUuid, effectiveVariantId, equipmentInfos);
}
Expand Down
Loading

0 comments on commit d36509d

Please sign in to comment.