Skip to content

Commit

Permalink
Added: Provide also human readable by fetch all registered bridgeheads
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Nov 13, 2024
1 parent 4eae15b commit 866be56
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.0.1 - 2024-11-08]
## [0.0.1 - 2024-11-13]
### Added
- First version of the project
- Spring Application
Expand Down Expand Up @@ -149,3 +149,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Human Readable Bridgehead for frontend dto
- Http proxy configuration
- Email as HTML
- Provide also human readable by fetch all registered bridgeheads
11 changes: 8 additions & 3 deletions src/main/java/de/samply/app/ProjectManagerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import de.samply.email.EmailTemplateType;
import de.samply.exporter.ExporterService;
import de.samply.frontend.FrontendService;
import de.samply.frontend.dto.DtoFactory;
import de.samply.frontend.dto.configuration.ProjectConfigurations;
import de.samply.notification.NotificationService;
import de.samply.project.ProjectBridgeheadService;
Expand Down Expand Up @@ -50,6 +51,7 @@
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

@RestController
@Slf4j
Expand All @@ -70,6 +72,7 @@ public class ProjectManagerController {
private final NotificationService notificationService;
private final BridgeheadConfiguration bridgeheadConfiguration;
private final ProjectConfigurations frontendProjectConfigurations;
private final DtoFactory dtoFactory;

public ProjectManagerController(ProjectEventService projectEventService,
FrontendService frontendService,
Expand All @@ -82,7 +85,8 @@ public ProjectManagerController(ProjectEventService projectEventService,
ProjectBridgeheadService projectBridgeheadService,
NotificationService notificationService,
BridgeheadConfiguration bridgeheadConfiguration,
ProjectConfigurations frontendProjectConfigurations) {
ProjectConfigurations frontendProjectConfigurations,
DtoFactory dtoFactory) {
this.projectEventService = projectEventService;
this.frontendService = frontendService;
this.userService = userService;
Expand All @@ -95,6 +99,7 @@ public ProjectManagerController(ProjectEventService projectEventService,
this.notificationService = notificationService;
this.bridgeheadConfiguration = bridgeheadConfiguration;
this.frontendProjectConfigurations = frontendProjectConfigurations;
this.dtoFactory = dtoFactory;
}

@GetMapping(value = ProjectManagerConst.INFO)
Expand Down Expand Up @@ -1138,12 +1143,12 @@ public ResponseEntity<String> setNotificationAsRead(
return convertToResponseEntity(() -> this.notificationService.setNotificationAsRead(notificationId));
}

@RoleConstraints(organisationRoles = {OrganisationRole.RESEARCHER, OrganisationRole.PROJECT_MANAGER_ADMIN})
@RoleConstraints(organisationRoles = {OrganisationRole.RESEARCHER, OrganisationRole.BRIDGEHEAD_ADMIN, OrganisationRole.PROJECT_MANAGER_ADMIN})
@FrontendSiteModule(site = ProjectManagerConst.PROJECT_VIEW_SITE, module = ProjectManagerConst.PROJECT_BRIDGEHEAD_MODULE)
@FrontendAction(action = ProjectManagerConst.FETCH_ALL_REGISTERED_BRIDGEHEADS_ACTION)
@GetMapping(value = ProjectManagerConst.FETCH_ALL_REGISTERED_BRIDGEHEADS)
public ResponseEntity<Resource> fetchAllRegisteredBridgeheads() {
return convertToResponseEntity(() -> bridgeheadConfiguration.getRegisteredBridgeheads());
return convertToResponseEntity(() -> bridgeheadConfiguration.getRegisteredBridgeheads().stream().map(dtoFactory::convertToBridgehead).collect(Collectors.toSet()));
}

@RoleConstraints(organisationRoles = {OrganisationRole.PROJECT_MANAGER_ADMIN})
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/de/samply/frontend/dto/Bridgehead.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package de.samply.frontend.dto;

public record Bridgehead(
String bridgehead,
String humanReadable
) {
}
5 changes: 5 additions & 0 deletions src/main/java/de/samply/frontend/dto/DtoFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,9 @@ public User convertFilteringProjectRoleAndState(@NotNull de.samply.db.model.Proj
);
}

public Bridgehead convertToBridgehead(@NotNull String bridgehead) {
Optional<String> humanReadable = bridgeheadConfiguration.getHumanReadable(bridgehead);
return humanReadable.isPresent() ? new Bridgehead(bridgehead, humanReadable.get()) : new Bridgehead(bridgehead, null);
}

}

0 comments on commit 866be56

Please sign in to comment.