From bef75bfe94590ce5e9bcdabfdfb4c8452b72b09e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 8 Jul 2024 12:00:00 +0200 Subject: [PATCH] Search with AQL --- .../numportal/domain/dto/QueryDto.java | 11 ++++++ .../properties/FeatureProperties.java | 2 + .../web/controller/QueryController.java | 39 +++++++++++++++++++ src/main/resources/application-local.yml | 1 + 4 files changed, 53 insertions(+) create mode 100644 src/main/java/org/highmed/numportal/domain/dto/QueryDto.java create mode 100644 src/main/java/org/highmed/numportal/web/controller/QueryController.java diff --git a/src/main/java/org/highmed/numportal/domain/dto/QueryDto.java b/src/main/java/org/highmed/numportal/domain/dto/QueryDto.java new file mode 100644 index 00000000..4e502ccd --- /dev/null +++ b/src/main/java/org/highmed/numportal/domain/dto/QueryDto.java @@ -0,0 +1,11 @@ +package org.highmed.numportal.domain.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@Data +@Schema +public class QueryDto { + @NotNull private String aql; +} diff --git a/src/main/java/org/highmed/numportal/properties/FeatureProperties.java b/src/main/java/org/highmed/numportal/properties/FeatureProperties.java index 1cb9144b..f9e3eb5a 100644 --- a/src/main/java/org/highmed/numportal/properties/FeatureProperties.java +++ b/src/main/java/org/highmed/numportal/properties/FeatureProperties.java @@ -6,4 +6,6 @@ @Data @ConfigurationProperties(prefix = "feature") public class FeatureProperties { + + private boolean searchWithAql = false; } diff --git a/src/main/java/org/highmed/numportal/web/controller/QueryController.java b/src/main/java/org/highmed/numportal/web/controller/QueryController.java new file mode 100644 index 00000000..5109cb85 --- /dev/null +++ b/src/main/java/org/highmed/numportal/web/controller/QueryController.java @@ -0,0 +1,39 @@ +package org.highmed.numportal.web.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import jakarta.validation.Valid; +import lombok.AllArgsConstructor; +import org.ehrbase.openehr.sdk.response.dto.QueryResponseData; +import org.highmed.numportal.domain.dto.QueryDto; +import org.highmed.numportal.service.ehrbase.EhrBaseService; +import org.highmed.numportal.service.logger.AuditLog; +import org.highmed.numportal.web.config.Role; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +@RequestMapping(value = "/query", produces = "application/json") +@SecurityRequirement(name = "security_auth") +@ConditionalOnProperty(value = "feature.search-with-aql", havingValue = "true") +public class QueryController { + + private final EhrBaseService ehrBaseService; + + @AuditLog + @PostMapping("execute") + @Operation(description = "Executes an AQL query") + @PreAuthorize(Role.MANAGER) + public ResponseEntity executeManagerProject( + @RequestBody @Valid QueryDto queryDto) { + return ResponseEntity.ok( + ehrBaseService.executePlainQuery(queryDto.getAql()) + ); + } +} diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index a3075bdf..43be1276 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -107,3 +107,4 @@ user-service: delete-users-cron: 0 0 5 * * * feature: + search-with-aql: off