Skip to content

Commit

Permalink
Added: Fetch Project States
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Jan 30, 2024
1 parent ff66a89 commit ab104cc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Set notification as read
- Fetch User Visible Projects and User Visible Notifications without constraints
- Fetch Project
- Fetch Project States
2 changes: 2 additions & 0 deletions src/main/java/de/samply/app/ProjectManagerConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class ProjectManagerConst {
public final static String FETCH_NOTIFICATIONS_ACTION = "FETCH_NOTIFICATIONS";
public final static String SET_NOTIFICATION_AS_READ_ACTION = "SET_NOTIFICATION_AS_READ";
public final static String FETCH_PROJECT_ACTION = "FETCH_PROJECT_ACTION";
public final static String FETCH_PROJECT_STATES_ACTION = "FETCH_PROJECT_STATES";


// REST Services
Expand Down Expand Up @@ -99,6 +100,7 @@ public class ProjectManagerConst {
public final static String REQUEST_CHANGES_IN_PROJECT = "/request-changes-in-project";
public final static String FETCH_PROJECT_BRIDGEHEADS = "/project-bridgeheads";
public final static String FETCH_PROJECT = "/project";
public final static String FETCH_PROJECT_STATES = "/project-states";
public final static String ARCHIVE_PROJECT = "/archive-project";
public final static String START_DEVELOP_STAGE = "/start-develop-project";
public final static String START_PILOT_STAGE = "/start-pilot-project";
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/de/samply/app/ProjectManagerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ public ResponseEntity<String> fetchProject(
return convertToResponseEntity(() -> projectService.fetchProject(projectCode));
}

@FrontendSiteModule(site = ProjectManagerConst.PROJECT_VIEW_SITE, module = ProjectManagerConst.PROJECT_BRIDGEHEAD_MODULE)
@FrontendAction(action = ProjectManagerConst.FETCH_PROJECT_STATES_ACTION)
@GetMapping(value = ProjectManagerConst.FETCH_PROJECT_STATES, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> fetchProjectStates(
) {
return convertToResponseEntity(() -> ProjectState.values());
}

@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_PROJECT_BRIDGEHEADS_ACTION)
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/de/samply/project/event/ProjectEventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,23 @@ private ProjectBridgehead createProjectBridgehead(String bridgehead, Project pro
}

private void createProjectBridgeheadUser(String projectCode) throws ProjectEventActionsException {
Optional<Project> project = this.projectRepository.findByCode(projectCode);
if (project.isEmpty()) {
throw new ProjectEventActionsException("Project not found");
}
Project project = fetchProject(projectCode);
sessionUser.getBridgeheads().stream().forEach(bridgehead -> {
Optional<ProjectBridgehead> projectBridgehead = this.projectBridgeheadRepository.findFirstByBridgeheadAndProject(bridgehead, project.get());
Optional<ProjectBridgehead> projectBridgehead = this.projectBridgeheadRepository.findFirstByBridgeheadAndProject(bridgehead, project);
if (projectBridgehead.isPresent()) {
this.userService.createProjectBridgeheadUserIfNotExists(sessionUser.getEmail(), projectBridgehead.get(), ProjectRole.CREATOR);
}
});
}

private Project fetchProject(String projectCode) throws ProjectEventActionsException {
Optional<Project> project = this.projectRepository.findByCode(projectCode);
if (project.isEmpty()) {
throw new ProjectEventActionsException("Project not found");
}
return project.get();
}

@Override
public void create(String projectCode) throws ProjectEventActionsException {
changeEvent(projectCode, ProjectEvent.CREATE);
Expand Down

0 comments on commit ab104cc

Please sign in to comment.