Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2025, 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.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.gridsuite.study.server.StudyApi;
import org.gridsuite.study.server.service.StudyService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;
/**
* @author Rehili Ghazwa <ghazwa.rehili at rte-france.com>
*/

@RestController
@RequestMapping(value = "/" + StudyApi.API_VERSION + "/studies/{studyUuid}/computation-result-filters")
@Tag(name = "Study server - Computation result filters")
public class ComputationResultFiltersController {
private final StudyService studyService;

public ComputationResultFiltersController(StudyService studyService) {
this.studyService = studyService;
}

@GetMapping()
@Operation(summary = "Get study's computation result filters")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The computation result filters")})
public ResponseEntity<String> getComputationResultFilters(
@PathVariable("studyUuid") UUID studyUuid) {
return ResponseEntity.ok().body(studyService.getComputationResultFilters(studyUuid));
}

@PostMapping("/{id}/global-filters")
@Operation(summary = "Set global filters",
description = "Replaces all existing global filters with the provided list for a computation result")
@ApiResponse(responseCode = "204", description = "Global filters set successfully")
@ApiResponse(responseCode = "404", description = "computation result global filters not found")
public ResponseEntity<Void> setGlobalFiltersForComputationResult(
@PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "ID of the global filters") @PathVariable UUID id,
@RequestBody String filters) {
studyService.setGlobalFiltersForComputationResult(studyUuid, id, filters);
return ResponseEntity.noContent().build();
}

@PutMapping("/{id}/columns/{columnUuid}")
@Operation(summary = "Update a column", description = "Updates an existing column")
@ApiResponse(responseCode = "204", description = "Column updated")
public ResponseEntity<Void> updateColumns(
@PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "ID of the spreadsheet config") @PathVariable UUID id,
@Parameter(description = "ID of the column to update") @PathVariable UUID columnUuid,
@Valid @RequestBody String columnInfos) {
studyService.updateColumns(studyUuid, id, columnUuid, columnInfos);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public class StudyEntity extends AbstractManuallyAssignedIdentifierEntity<UUID>
@Column(name = "spreadsheetConfigCollectionUuid")
private UUID spreadsheetConfigCollectionUuid;

@Column(name = "computationResultFiltersUuid")
private UUID computationResultFiltersUuid;

@Column(name = "diagramGridLayoutUuid")
private UUID diagramGridLayoutUuid;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
private static final String DIAGRAM_GRID_LAYOUT_URI = "/diagram-grid-layout";
private static final String DIAGRAM_GRID_LAYOUT_WITH_ID_URI = DIAGRAM_GRID_LAYOUT_URI + UUID_PARAM;

private static final String COMPUTATION_RESULT_FILTERS_URI = "/computation-result-filters";
private static final String COMPUTATION_RESULT_FILTERS_WITH_ID_URI = COMPUTATION_RESULT_FILTERS_URI + UUID_PARAM;

private static final DiagramPosition DEFAULT_DIAGRAM_POSITION = new DiagramPosition(2, 2, 0, 0);

private final RestTemplate restTemplate;
Expand Down Expand Up @@ -102,7 +105,7 @@

public UUID createDefaultNetworkVisualizationParameters() {
var path = UriComponentsBuilder
.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + NETWORK_VISU_PARAMETERS_URI + "/default")

Check failure on line 108 in src/main/java/org/gridsuite/study/server/service/StudyConfigService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "/default" 3 times.

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Astudy-server&issues=AZq2c4RqmeQGQm5JNhPO&open=AZq2c4RqmeQGQm5JNhPO&pullRequest=884
.buildAndExpand()
.toUriString();
return restTemplate.exchange(studyConfigServerBaseUri + path, HttpMethod.POST, null, UUID.class).getBody();
Expand Down Expand Up @@ -242,7 +245,7 @@
}

public void updateColumn(UUID configUuid, UUID columnUuid, String columnInfos) {
var uriBuilder = UriComponentsBuilder.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + SPREADSHEET_CONFIG_WITH_ID_URI + "/columns/{colId}");

Check failure on line 248 in src/main/java/org/gridsuite/study/server/service/StudyConfigService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "/columns/{colId}" 3 times.

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Astudy-server&issues=AZsIwlUpnByX-KFm0FMo&open=AZsIwlUpnByX-KFm0FMo&pullRequest=884
String path = uriBuilder.buildAndExpand(configUuid, columnUuid).toUriString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
Expand Down Expand Up @@ -360,4 +363,42 @@
HttpEntity<DiagramGridLayout> httpEntity = new HttpEntity<>(diagramGridLayout, headers);
return restTemplate.exchange(studyConfigServerBaseUri + path, HttpMethod.POST, httpEntity, UUID.class).getBody();
}

public UUID createDefaultComputationResultFilters() {
var path = UriComponentsBuilder.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + COMPUTATION_RESULT_FILTERS_URI + "/default")
.buildAndExpand().toUriString();
return restTemplate.exchange(studyConfigServerBaseUri + path, HttpMethod.POST, null, UUID.class).getBody();
}

public UUID getComputationResultFiltersUuidOrElseCreateDefaults(StudyEntity studyEntity) {
Copy link
Contributor

@etiennehomer etiennehomer Dec 3, 2025

Choose a reason for hiding this comment

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

For the spreadsheet, they made the choice to define the default tabs and columns of the spreadsheet for a new study in the back. That's the why the spreadsheet is not empty for a new study.

But here, we don't set default computations filters. It's all empty. So you can delete this endpoint and just manage the null in the front

if (studyEntity.getComputationResultFiltersUuid() == null) {
studyEntity.setComputationResultFiltersUuid(createDefaultComputationResultFilters());
}
return studyEntity.getComputationResultFiltersUuid();
}

public String getComputationResultFilters(UUID uuid) {
Objects.requireNonNull(uuid);
String path = UriComponentsBuilder.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + COMPUTATION_RESULT_FILTERS_WITH_ID_URI)
.buildAndExpand(uuid).toUriString();
return restTemplate.getForObject(studyConfigServerBaseUri + path, String.class);
}

public void setGlobalFiltersForComputationResult(UUID studyUuid, UUID configUuid, String globalFilters) {

Check warning on line 387 in src/main/java/org/gridsuite/study/server/service/StudyConfigService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused method parameter "studyUuid".

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Astudy-server&issues=AZq2c4RqmeQGQm5JNhPP&open=AZq2c4RqmeQGQm5JNhPP&pullRequest=884
var uriBuilder = UriComponentsBuilder.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + COMPUTATION_RESULT_FILTERS_WITH_ID_URI + "/global-filters");
String path = uriBuilder.buildAndExpand(configUuid).toUriString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> httpEntity = new HttpEntity<>(globalFilters, headers);
restTemplate.exchange(studyConfigServerBaseUri + path, HttpMethod.POST, httpEntity, Void.class);
}

public void updateColumns(UUID configUuid, UUID columnUuid, String columnInfos) {
var uriBuilder = UriComponentsBuilder.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + COMPUTATION_RESULT_FILTERS_WITH_ID_URI + "/columns/{colId}");
String path = uriBuilder.buildAndExpand(configUuid, columnUuid).toUriString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> httpEntity = new HttpEntity<>(columnInfos, headers);
restTemplate.put(studyConfigServerBaseUri + path, httpEntity);
}
}
14 changes: 14 additions & 0 deletions src/main/java/org/gridsuite/study/server/service/StudyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2737,6 +2737,12 @@
return studyConfigService.getSpreadsheetConfigCollection(studyConfigService.getSpreadsheetConfigCollectionUuidOrElseCreateDefaults(studyEntity));
}

@Transactional
public String getComputationResultFilters(UUID studyUuid) {
StudyEntity studyEntity = getStudy(studyUuid);
return studyConfigService.getComputationResultFilters(studyConfigService.getComputationResultFiltersUuidOrElseCreateDefaults(studyEntity));
}

/**
* Set spreadsheet config collection on study or reset to default one if empty body.
* Default is the user profile one, or system default if no profile is available.
Expand Down Expand Up @@ -3559,6 +3565,14 @@
notificationService.emitSpreadsheetConfigChanged(studyUuid, configUuid);
}

public void setGlobalFiltersForComputationResult(UUID studyUuid, UUID configUuid, String globalFilters) {
studyConfigService.setGlobalFiltersForComputationResult(studyUuid, configUuid, globalFilters);
}

public void updateColumns(UUID studyUuid, UUID configUuid, UUID columnUuid, String columnInfos) {

Check warning on line 3572 in src/main/java/org/gridsuite/study/server/service/StudyService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused method parameter "studyUuid".

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Astudy-server&issues=AZsIwlQtnByX-KFm0FMn&open=AZsIwlQtnByX-KFm0FMn&pullRequest=884
studyConfigService.updateColumns(configUuid, columnUuid, columnInfos);
}

public void renameSpreadsheetConfig(UUID studyUuid, UUID configUuid, String newName) {
studyConfigService.renameSpreadsheetConfig(configUuid, newName);
notificationService.emitSpreadsheetConfigChanged(studyUuid, configUuid);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="rehiligha (generated)" id="1763373405443-18">
<addColumn tableName="study">
<column name="computation_result_filters_uuid" type="uuid"/>
</addColumn>
</changeSet>
</databaseChangeLog>
3 changes: 3 additions & 0 deletions src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,6 @@ databaseChangeLog:
- include:
file: changesets/changelog_20251113T131808Z.xml
relativeToChangelogFile: true
- include:
file: changesets/changelog_20251117T095627Z.xml
relativeToChangelogFile: true