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
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<gridsuite-dependencies.version>43.0.0</gridsuite-dependencies.version>
<liquibase-hibernate-package>org.gridsuite.study.server</liquibase-hibernate-package>
<mockwebserver3.version>5.0.0-alpha.14</mockwebserver3.version>
<db-util.version>1.0.5</db-util.version>
<db-util.version>1.0.5</db-util.version>
<sonar.organization>gridsuite</sonar.organization>
<sonar.projectKey>org.gridsuite:study-server</sonar.projectKey>
</properties>
Expand Down Expand Up @@ -144,6 +144,11 @@
<groupId>com.powsybl</groupId>
<artifactId>powsybl-ws-commons</artifactId>
</dependency>
<dependency>
<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-filter</artifactId>
<version>1.10.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.gridsuite.filter.globalfilter.GlobalFilter;
import org.gridsuite.filter.utils.EquipmentType;
import org.gridsuite.study.server.StudyApi;
import org.gridsuite.study.server.StudyException;
import org.gridsuite.study.server.StudyException.Type;
Expand Down Expand Up @@ -53,6 +55,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -2344,6 +2347,20 @@ public ResponseEntity<String> evaluateFilter(
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.evaluateFilter(nodeUuid, rootNetworkUuid, inUpstreamBuiltParentNode, filter));
}

@PostMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/global-filter/evaluate",
produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Evaluate a filter to get matched elements")
@ApiResponse(responseCode = "200", description = "The list of matched elements")
public ResponseEntity<List<String>> evaluateGlobalFilter(
@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "Root network uuid") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid,
@Parameter(description = "Node uuid") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "The equipments types to filter and return") @RequestParam(name = "equipmentTypes") @NonNull final List<EquipmentType> equipmentTypes,
@RequestBody @NonNull GlobalFilter filter) {
this.studyService.assertIsRootNetworkAndNodeInStudy(studyUuid, rootNetworkUuid, nodeUuid);
return ResponseEntity.ok(studyService.evaluateGlobalFilter(nodeUuid, rootNetworkUuid, equipmentTypes, filter));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing unit test for this new endpoint


@GetMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/filters/{filterUuid}/elements")
@Operation(summary = "Evaluate a filter on root node to get matched elements")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The list of matched elements")})
Expand Down
42 changes: 31 additions & 11 deletions src/main/java/org/gridsuite/study/server/service/FilterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@

package org.gridsuite.study.server.service;

import lombok.Getter;
import lombok.NonNull;
import org.gridsuite.filter.globalfilter.GlobalFilter;
import org.gridsuite.filter.utils.EquipmentType;
import org.gridsuite.study.server.RemoteServicesProperties;
import org.gridsuite.study.server.StudyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

import java.util.List;
Expand All @@ -42,13 +45,9 @@ public class FilterService {

private final RestTemplate restTemplate;

@Getter // getter to facilitate to mock
private final String baseUri;

// getter to facilitate to mock
public String getBaseUri() {
return baseUri;
}

@Autowired
public FilterService(RemoteServicesProperties remoteServicesProperties, RestTemplate restTemplate) {
this.baseUri = remoteServicesProperties.getServiceUri("filter-server");
Expand All @@ -64,8 +63,7 @@ public String evaluateFilter(UUID networkUuid, String variantId, String filter)
if (variantId != null && !variantId.isBlank()) {
uriComponentsBuilder.queryParam("variantId", variantId);
}
var uriComponent = uriComponentsBuilder
.build();
var uriComponent = uriComponentsBuilder.build();

var headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
Expand All @@ -83,6 +81,28 @@ public String evaluateFilter(UUID networkUuid, String variantId, String filter)
}
}

public List<String> evaluateGlobalFilter(@NonNull final UUID networkUuid, @NonNull final String variantId,
@NonNull final List<EquipmentType> equipmentTypes, @NonNull final GlobalFilter filter) {
final UriComponents uriComponent = UriComponentsBuilder.fromHttpUrl(getBaseUri())
.pathSegment(FILTER_API_VERSION, "global-filter")
.queryParam("networkUuid", networkUuid)
.queryParam("variantId", variantId)
.queryParam("equipmentTypes", equipmentTypes)
.build();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
try {
return restTemplate.exchange(uriComponent.toUri(), HttpMethod.POST, new HttpEntity<>(filter, headers), new ParameterizedTypeReference<List<String>>() { })
.getBody();
} catch (final HttpStatusCodeException ex) {
if (HttpStatus.NOT_FOUND.equals(ex.getStatusCode())) {
throw new StudyException(NETWORK_NOT_FOUND);
} else {
throw handleHttpError(ex, EVALUATE_FILTER_FAILED);
}
}
}

public String exportFilter(UUID networkUuid, UUID filterUuid) {
Objects.requireNonNull(networkUuid);
Objects.requireNonNull(filterUuid);
Expand Down
21 changes: 21 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 @@ -15,6 +15,8 @@
import jakarta.servlet.http.HttpServletResponse;
import lombok.NonNull;
import org.apache.commons.collections4.CollectionUtils;
import org.gridsuite.filter.globalfilter.GlobalFilter;
import org.gridsuite.filter.utils.EquipmentType;
import org.gridsuite.study.server.StudyConstants;
import org.gridsuite.study.server.StudyException;
import org.gridsuite.study.server.dto.*;
Expand Down Expand Up @@ -307,6 +309,14 @@ public BasicStudyInfos createStudy(UUID caseUuid, String userId, UUID studyUuid,
return basicStudyInfos;
}

@Transactional(readOnly = true)
public void assertIsRootNetworkAndNodeInStudy(@NonNull final UUID studyUuid, @NonNull final UUID rootNetworkId, @NonNull final UUID nodeUuid) {
this.rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkId);
if (!studyUuid.equals(this.networkModificationTreeService.getStudyUuidForNodeId(nodeUuid))) {
throw new StudyException(NODE_NOT_FOUND);
}
}

@Transactional
public void deleteRootNetworks(UUID studyUuid, List<UUID> rootNetworksUuids) {
assertIsStudyExist(studyUuid);
Expand Down Expand Up @@ -3364,6 +3374,17 @@ public String evaluateFilter(UUID nodeUuid, UUID rootNetworkUuid, boolean inUpst
return filterService.evaluateFilter(rootNetworkService.getNetworkUuid(rootNetworkUuid), networkModificationTreeService.getVariantId(nodeUuidToSearchIn, rootNetworkUuid), filter);
}

@Transactional(readOnly = true)
public List<String> evaluateGlobalFilter(@NonNull final UUID nodeUuid, @NonNull final UUID rootNetworkUuid,
@NonNull final List<EquipmentType> equipmentTypes, @NonNull final GlobalFilter filter) {
return filterService.evaluateGlobalFilter(
rootNetworkService.getNetworkUuid(rootNetworkUuid),
networkModificationTreeService.getVariantId(getNodeUuidToSearchIn(nodeUuid, rootNetworkUuid, true), rootNetworkUuid),
equipmentTypes,
filter
);
}

@Transactional(readOnly = true)
public String exportFilter(UUID rootNetworkUuid, UUID filterUuid) {
return filterService.exportFilter(rootNetworkService.getNetworkUuid(rootNetworkUuid), filterUuid);
Expand Down
Loading