diff --git a/src/main/java/org/gridsuite/filter/server/FilterController.java b/src/main/java/org/gridsuite/filter/server/FilterController.java index cf9eb1ec..c6f41fd3 100644 --- a/src/main/java/org/gridsuite/filter/server/FilterController.java +++ b/src/main/java/org/gridsuite/filter/server/FilterController.java @@ -17,9 +17,11 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import jakarta.persistence.EntityNotFoundException; + import java.util.List; import java.util.Optional; import java.util.UUID; @@ -158,4 +160,20 @@ public ResponseEntity> exportFilters(@RequestParam("ids") .contentType(MediaType.APPLICATION_JSON) .body(ret); } + + @PostMapping(value = "/filters/evaluate", produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Export matched elements to JSON format") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "The list of matched elements"), + @ApiResponse(responseCode = "204", description = "No matched element found") + }) + public ResponseEntity> evaluateFilter(@RequestParam(value = "networkUuid") UUID networkUuid, + @RequestParam(value = "variantId", required = false) String variantId, + @RequestBody AbstractFilter filter) { + List identifiableAttributes = service.evaluateFilter(filter, networkUuid, variantId); + return CollectionUtils.isEmpty(identifiableAttributes) ? ResponseEntity.noContent().build() : + ResponseEntity.ok() + .contentType(MediaType.APPLICATION_JSON) + .body(identifiableAttributes); + } } diff --git a/src/main/java/org/gridsuite/filter/server/FilterService.java b/src/main/java/org/gridsuite/filter/server/FilterService.java index 47da3c76..8b3bbb4e 100644 --- a/src/main/java/org/gridsuite/filter/server/FilterService.java +++ b/src/main/java/org/gridsuite/filter/server/FilterService.java @@ -685,6 +685,11 @@ private List getIdentifiableAttributes(AbstractFilter fi } } + public List evaluateFilter(AbstractFilter filter, UUID networkUuid, String variantId) { + Objects.requireNonNull(filter); + return getIdentifiableAttributes(filter, networkUuid, variantId); + } + public Optional> exportFilter(UUID id, UUID networkUuid, String variantId) { Objects.requireNonNull(id); return getFilter(id).map(filter -> getIdentifiableAttributes(filter, networkUuid, variantId));