Skip to content

Implement global filter #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jul 11, 2025
Merged
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
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-filter</artifactId>
</dependency>

<!-- Runtime dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.sensitivity.SensitivityAnalysisResult;
import com.powsybl.sensitivity.SensitivityFunctionType;
import com.powsybl.ws.commons.computation.ComputationException;
import com.powsybl.ws.commons.computation.dto.GlobalFilter;
import com.powsybl.ws.commons.computation.dto.ReportInfos;
import com.powsybl.ws.commons.computation.dto.ResourceFilterDTO;
import com.powsybl.ws.commons.computation.utils.FilterUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
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 com.powsybl.ws.commons.computation.dto.ReportInfos;
import org.gridsuite.sensitivityanalysis.server.dto.*;
import org.gridsuite.sensitivityanalysis.server.dto.nonevacuatedenergy.NonEvacuatedEnergyInputData;
import org.gridsuite.sensitivityanalysis.server.dto.nonevacuatedenergy.NonEvacuatedEnergyStatus;
Expand All @@ -30,6 +34,7 @@
import org.gridsuite.sensitivityanalysis.server.service.nonevacuatedenergy.NonEvacuatedEnergyRunContext;
import org.gridsuite.sensitivityanalysis.server.service.nonevacuatedenergy.NonEvacuatedEnergyService;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -40,7 +45,6 @@
import java.util.UUID;

import static com.powsybl.ws.commons.computation.service.NotificationService.HEADER_USER_ID;
import static com.powsybl.ws.commons.computation.utils.FilterUtils.fromStringFiltersToDTO;
import static org.springframework.http.MediaType.*;

/**
Expand Down Expand Up @@ -139,20 +143,30 @@ public ResponseEntity<Long> getFactorsCount(@Parameter(description = "Network UU
@GetMapping(value = "/results/{resultUuid}", produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Get a sensitivity analysis result from the database")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The sensitivity analysis result"),
@ApiResponse(responseCode = "404", description = "Sensitivity analysis result has not been found")})
@ApiResponse(responseCode = "404", description = "Sensitivity analysis result has not been found"),
@ApiResponse(responseCode = "400", description = "Invalid filter format")})
public ResponseEntity<SensitivityRunQueryResult> getResult(
@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid,
@RequestParam(name = "selector", required = false) String selectorJson,
@Parameter(description = "JSON array of filters") @RequestParam(name = "filters", required = false) String filters
@Parameter(description = "JSON array of filters") @RequestParam(name = "filters", required = false) String filters,
@Parameter(description = "Global Filters") @RequestParam(name = "globalFilters", required = false) String globalFilters,
@Parameter(description = "network Uuid") @RequestParam(name = "networkUuid", required = false) UUID networkUuid,
@Parameter(description = "variant Id") @RequestParam(name = "variantId", required = false) String variantId
) {
String decodedStringFilters = filters != null ? URLDecoder.decode(filters, StandardCharsets.UTF_8) : null;
try {
String decodedStringFilters = filters != null ? URLDecoder.decode(filters, StandardCharsets.UTF_8) : null;
String decodedStringGlobalFilters = globalFilters != null ? URLDecoder.decode(globalFilters, StandardCharsets.UTF_8) : null;
List<ResourceFilterDTO> resourceFilters = FilterUtils.fromStringFiltersToDTO(decodedStringFilters, objectMapper);
GlobalFilter globalFilter = FilterUtils.fromStringGlobalFiltersToDTO(decodedStringGlobalFilters, objectMapper);
ResultsSelector selector = getSelector(selectorJson);
SensitivityRunQueryResult result = service.getRunResult(resultUuid, selector, fromStringFiltersToDTO(decodedStringFilters, objectMapper));
return result != null ? ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(result)
: ResponseEntity.notFound().build();
} catch (JsonProcessingException e) {
SensitivityRunQueryResult result = service.getRunResult(resultUuid, networkUuid, variantId, selector, resourceFilters, globalFilter);
return result != null ? ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(result) : ResponseEntity.status(HttpStatus.NOT_FOUND).build();
} catch (ComputationException e) {
// Handle JSON processing errors with bad request status
return ResponseEntity.badRequest().build();
} catch (Exception e) {
// Handle all other exceptions with internal server error status
return ResponseEntity.internalServerError().build();
}
}

Expand All @@ -166,7 +180,7 @@ public ResponseEntity<SensitivityResultFilterOptions> getResultFilerOptions(@Par
ResultsSelector selector = getSelector(selectorJson);
SensitivityResultFilterOptions result = service.getSensitivityResultOptions(resultUuid, selector);
return result != null ? ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(result)
: ResponseEntity.notFound().build();
: ResponseEntity.status(HttpStatus.NOT_FOUND).build();
} catch (JsonProcessingException e) {
return ResponseEntity.badRequest().build();
}
Expand Down
Loading