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