Skip to content

Commit

Permalink
Added: Filter output formats for DataSHIELD
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Feb 22, 2024
1 parent 7e7c110 commit 030dc85
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions src/main/java/de/samply/app/ProjectManagerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,9 @@ public ResponseEntity<String> fetchQueryFormats(
@FrontendAction(action = ProjectManagerConst.FETCH_OUTPUT_FORMATS_ACTION)
@GetMapping(value = ProjectManagerConst.FETCH_OUTPUT_FORMATS)
public ResponseEntity<String> 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})
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/de/samply/project/ProjectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -291,4 +289,15 @@ private Page<Project> fetchResearcherProjects(String
}
}

public OutputFormat[] fetchOutputFormats(@NotNull String projectCode) throws ProjectServiceException {
Optional<Project> 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);
};
}

}

0 comments on commit 030dc85

Please sign in to comment.