From ab104ccf8dd7884475f9a4c6f67c25f3be07ee8c Mon Sep 17 00:00:00 2001 From: juarez Date: Tue, 30 Jan 2024 18:29:19 +0100 Subject: [PATCH] Added: Fetch Project States --- CHANGELOG.md | 1 + .../java/de/samply/app/ProjectManagerConst.java | 2 ++ .../de/samply/app/ProjectManagerController.java | 8 ++++++++ .../samply/project/event/ProjectEventService.java | 15 ++++++++++----- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a78217..82caf6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/java/de/samply/app/ProjectManagerConst.java b/src/main/java/de/samply/app/ProjectManagerConst.java index 166661a..33dcab4 100644 --- a/src/main/java/de/samply/app/ProjectManagerConst.java +++ b/src/main/java/de/samply/app/ProjectManagerConst.java @@ -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 @@ -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"; diff --git a/src/main/java/de/samply/app/ProjectManagerController.java b/src/main/java/de/samply/app/ProjectManagerController.java index 084adc3..b6fed4d 100644 --- a/src/main/java/de/samply/app/ProjectManagerController.java +++ b/src/main/java/de/samply/app/ProjectManagerController.java @@ -144,6 +144,14 @@ public ResponseEntity 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 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) diff --git a/src/main/java/de/samply/project/event/ProjectEventService.java b/src/main/java/de/samply/project/event/ProjectEventService.java index bd8a7fc..5b63f42 100644 --- a/src/main/java/de/samply/project/event/ProjectEventService.java +++ b/src/main/java/de/samply/project/event/ProjectEventService.java @@ -168,18 +168,23 @@ private ProjectBridgehead createProjectBridgehead(String bridgehead, Project pro } private void createProjectBridgeheadUser(String projectCode) throws ProjectEventActionsException { - Optional 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 = this.projectBridgeheadRepository.findFirstByBridgeheadAndProject(bridgehead, project.get()); + Optional 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 = 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);