From 030dc85dffc39984056be3fae1b7a901a7452b30 Mon Sep 17 00:00:00 2001 From: juarez Date: Thu, 22 Feb 2024 18:41:37 +0100 Subject: [PATCH] Added: Filter output formats for DataSHIELD --- CHANGELOG.md | 1 + .../de/samply/app/ProjectManagerController.java | 3 +-- .../java/de/samply/project/ProjectService.java | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09bea94..91861d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,3 +102,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Decode redirect explorer URL - Fetch project users - rejectProject state constraints +- Filter output formats for DataSHIELD diff --git a/src/main/java/de/samply/app/ProjectManagerController.java b/src/main/java/de/samply/app/ProjectManagerController.java index b964b51..7aa3f8f 100644 --- a/src/main/java/de/samply/app/ProjectManagerController.java +++ b/src/main/java/de/samply/app/ProjectManagerController.java @@ -331,10 +331,9 @@ public ResponseEntity fetchQueryFormats( @FrontendAction(action = ProjectManagerConst.FETCH_OUTPUT_FORMATS_ACTION) @GetMapping(value = ProjectManagerConst.FETCH_OUTPUT_FORMATS) public ResponseEntity fetchOutputFormats( - // Project code needed for role constraints @ProjectCode @RequestParam(name = ProjectManagerConst.PROJECT_CODE) String projectCode ) { - return convertToResponseEntity(() -> OutputFormat.values()); + return convertToResponseEntity(() -> projectService.fetchOutputFormats(projectCode)); } @RoleConstraints(projectRoles = {ProjectRole.CREATOR}) diff --git a/src/main/java/de/samply/project/ProjectService.java b/src/main/java/de/samply/project/ProjectService.java index ce3d15f..9c91b9d 100644 --- a/src/main/java/de/samply/project/ProjectService.java +++ b/src/main/java/de/samply/project/ProjectService.java @@ -10,6 +10,7 @@ import de.samply.notification.OperationType; import de.samply.project.state.ProjectBridgeheadState; import de.samply.project.state.ProjectState; +import de.samply.query.OutputFormat; import de.samply.security.SessionUser; import de.samply.user.roles.OrganisationRole; import jakarta.validation.constraints.NotNull; @@ -18,10 +19,7 @@ import org.springframework.stereotype.Service; import java.time.Instant; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; @Service public class ProjectService { @@ -291,4 +289,15 @@ private Page fetchResearcherProjects(String } } + public OutputFormat[] fetchOutputFormats(@NotNull String projectCode) throws ProjectServiceException { + Optional projectOptional = this.projectRepository.findByCode(projectCode); + if (projectOptional.isEmpty()) { + throw new ProjectServiceException("Project " + projectCode + " not found"); + } + return switch (projectOptional.get().getType()){ + case DATASHIELD -> new OutputFormat[]{OutputFormat.OPAL}; + default -> Arrays.stream(OutputFormat.values()).filter(outputFormat -> outputFormat != OutputFormat.OPAL).toArray(OutputFormat[]::new); + }; + } + }