Skip to content

Commit

Permalink
Introduce end point to evaluate a non persisted filter
Browse files Browse the repository at this point in the history
  • Loading branch information
thangqp committed Nov 17, 2023
1 parent 807207c commit eeb112e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/java/org/gridsuite/filter/server/FilterController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -158,4 +160,20 @@ public ResponseEntity<List<FilterEquipments>> 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<List<IdentifiableAttributes>> evaluateFilter(@RequestParam(value = "networkUuid") UUID networkUuid,
@RequestParam(value = "variantId", required = false) String variantId,
@RequestBody AbstractFilter filter) {
List<IdentifiableAttributes> identifiableAttributes = service.evaluateFilter(filter, networkUuid, variantId);
return CollectionUtils.isEmpty(identifiableAttributes) ? ResponseEntity.noContent().build() :
ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(identifiableAttributes);
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/gridsuite/filter/server/FilterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,11 @@ private List<IdentifiableAttributes> getIdentifiableAttributes(AbstractFilter fi
}
}

public List<IdentifiableAttributes> evaluateFilter(AbstractFilter filter, UUID networkUuid, String variantId) {
Objects.requireNonNull(filter);
return getIdentifiableAttributes(filter, networkUuid, variantId);
}

public Optional<List<IdentifiableAttributes>> exportFilter(UUID id, UUID networkUuid, String variantId) {
Objects.requireNonNull(id);
return getFilter(id).map(filter -> getIdentifiableAttributes(filter, networkUuid, variantId));
Expand Down

0 comments on commit eeb112e

Please sign in to comment.