Skip to content

Commit

Permalink
Added: Email Sender: ALL_DEVELOP, ALL_PILOT, ALL_FINAL
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Apr 15, 2024
1 parent fdc36c0 commit cedc2c5
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 13 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-04-14]
## [0.0.1 - 2024-04-15]
### Added
- First version of the project
- Spring Application
Expand Down Expand Up @@ -124,3 +124,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fetch label of application form, label and script
- Service exist invited users
- R-Studio Group Manager
- Email Sender: ALL_DEVELOP, ALL_PILOT, ALL_FINAL
26 changes: 26 additions & 0 deletions src/main/java/de/samply/aop/EmailSenderAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ private Set<EmailRecipient> fetchEmailRecipients(Supplier<EmailRecipientType[]>
case CREATOR -> fetchEmailRecipientsForCreator(projectCode);
case EMAIL_ANNOTATION -> fetchEmailRecipientsForEmailAnnotation(projectCode, bridgehead, email);
case ALL_BRIDGEHEAD_ADMINS -> fetchEmailRecipientsForAllBridgeheadAdminsOfTheProject(projectCode);
case ALL_DEVELOPERS -> fetchEmailRecipientsForAllDeveloperUsersOfTheProject(projectCode);
case ALL_PILOTS -> fetchEmailRecipientsForAllPilotUsersOfTheProject(projectCode);
case ALL_FINALS -> fetchEmailRecipientsForAllFinalUsersOfTheProject(projectCode);
case BRIDGEHEAD_ADMIN -> fetchEmailRecipientsForBridgeheadAdmin(projectCode, bridgehead);
case BRIDGHEAD_ADMINS_WHO_HAVE_NOT_ACCEPTED_NOR_REJECTED_THE_PROJECT ->
fetchEmailRecipientsForBridgeheadAdminsWhoHaveNotAcceptedNorRejectedTheProject(projectCode);
Expand All @@ -202,6 +205,29 @@ private Set<EmailRecipient> fetchEmailRecipientsForCreator(Optional<String> proj
return result;
}

private Set<EmailRecipient> fetchEmailRecipientsForAllDeveloperUsersOfTheProject(Optional<String> projectCode) {
return fetchEmailRecipientsForAllDeveloperUsersOfTheProject(projectCode, ProjectRole.DEVELOPER);
}

private Set<EmailRecipient> fetchEmailRecipientsForAllPilotUsersOfTheProject(Optional<String> projectCode) {
return fetchEmailRecipientsForAllDeveloperUsersOfTheProject(projectCode, ProjectRole.PILOT);
}

private Set<EmailRecipient> fetchEmailRecipientsForAllFinalUsersOfTheProject(Optional<String> projectCode) {
return fetchEmailRecipientsForAllDeveloperUsersOfTheProject(projectCode, ProjectRole.FINAL);
}

private Set<EmailRecipient> fetchEmailRecipientsForAllDeveloperUsersOfTheProject(Optional<String> projectCode, ProjectRole projectRole) {
Set<EmailRecipient> result = new HashSet<>();
if (projectCode.isPresent()) {
projectBridgeheadUserRepository.getDistinctByProjectRoleAndProjectCode(projectRole, projectCode.get()).stream()
.filter(projectBridgeheadUser -> !projectBridgeheadUser.getEmail().equals(sessionUser.getEmail())).forEach(projectBridgeheadUser ->
result.add(new EmailRecipient(projectBridgeheadUser.getEmail(), Optional.of(projectBridgeheadUser.getProjectBridgehead().getBridgehead()), projectRole)));
}
return result;
}


private Set<EmailRecipient> fetchEmailRecipientsForAllBridgeheadAdminsOfTheProject(Optional<String> projectCode) {
Set<EmailRecipient> result = new HashSet<>();
if (projectCode.isPresent()) {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/de/samply/app/ProjectManagerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public ResponseEntity<String> rejectBridgeheadProject(
@RoleConstraints(projectRoles = {ProjectRole.DEVELOPER, ProjectRole.PILOT})
@StateConstraints(projectStates = {ProjectState.DEVELOP, ProjectState.PILOT})
@ProjectConstraints(projectTypes = {ProjectType.DATASHIELD})
@EmailSender(templateType = EmailTemplateType.SCRIPT_ACCEPTED, recipients = {EmailRecipientType.PROJECT_MANAGER_ADMIN})
@EmailSender(templateType = EmailTemplateType.SCRIPT_ACCEPTED, recipients = {EmailRecipientType.PROJECT_MANAGER_ADMIN, EmailRecipientType.ALL_DEVELOPERS, EmailRecipientType.ALL_PILOTS})
@FrontendSiteModule(site = ProjectManagerConst.PROJECT_VIEW_SITE, module = ProjectManagerConst.PROJECT_STATE_MODULE)
@FrontendAction(action = ProjectManagerConst.ACCEPT_SCRIPT_ACTION)
@PostMapping(value = ProjectManagerConst.ACCEPT_SCRIPT)
Expand All @@ -532,7 +532,7 @@ public ResponseEntity<String> acceptScript(
@RoleConstraints(projectRoles = {ProjectRole.DEVELOPER, ProjectRole.PILOT})
@StateConstraints(projectStates = {ProjectState.DEVELOP, ProjectState.PILOT})
@ProjectConstraints(projectTypes = {ProjectType.DATASHIELD})
@EmailSender(templateType = EmailTemplateType.SCRIPT_REJECTED, recipients = {EmailRecipientType.PROJECT_MANAGER_ADMIN})
@EmailSender(templateType = EmailTemplateType.SCRIPT_REJECTED, recipients = {EmailRecipientType.PROJECT_MANAGER_ADMIN, EmailRecipientType.ALL_DEVELOPERS, EmailRecipientType.ALL_PILOTS})
@FrontendSiteModule(site = ProjectManagerConst.PROJECT_VIEW_SITE, module = ProjectManagerConst.PROJECT_STATE_MODULE)
@FrontendAction(action = ProjectManagerConst.REJECT_SCRIPT_ACTION)
@PostMapping(value = ProjectManagerConst.REJECT_SCRIPT)
Expand All @@ -546,7 +546,7 @@ public ResponseEntity<String> rejectScript(
@RoleConstraints(projectRoles = {ProjectRole.DEVELOPER, ProjectRole.PILOT})
@StateConstraints(projectStates = {ProjectState.DEVELOP, ProjectState.PILOT})
@ProjectConstraints(projectTypes = {ProjectType.DATASHIELD})
@EmailSender(templateType = EmailTemplateType.REQUEST_CHANGES_IN_SCRIPT, recipients = {EmailRecipientType.PROJECT_MANAGER_ADMIN})
@EmailSender(templateType = EmailTemplateType.REQUEST_CHANGES_IN_SCRIPT, recipients = {EmailRecipientType.PROJECT_MANAGER_ADMIN, EmailRecipientType.ALL_DEVELOPERS, EmailRecipientType.ALL_PILOTS})
@FrontendSiteModule(site = ProjectManagerConst.PROJECT_VIEW_SITE, module = ProjectManagerConst.PROJECT_STATE_MODULE)
@FrontendAction(action = ProjectManagerConst.REQUEST_SCRIPT_CHANGES_ACTION)
@PostMapping(value = ProjectManagerConst.REQUEST_SCRIPT_CHANGES)
Expand All @@ -559,7 +559,7 @@ public ResponseEntity<String> requestChangesInScript(

@RoleConstraints(projectRoles = {ProjectRole.FINAL})
@StateConstraints(projectStates = {ProjectState.FINAL})
@EmailSender(templateType = EmailTemplateType.RESULTS_ACCEPTED, recipients = {EmailRecipientType.PROJECT_MANAGER_ADMIN})
@EmailSender(templateType = EmailTemplateType.RESULTS_ACCEPTED, recipients = {EmailRecipientType.PROJECT_MANAGER_ADMIN, EmailRecipientType.ALL_FINALS})
@FrontendSiteModule(site = ProjectManagerConst.PROJECT_VIEW_SITE, module = ProjectManagerConst.PROJECT_STATE_MODULE)
@FrontendAction(action = ProjectManagerConst.ACCEPT_PROJECT_RESULTS_ACTION)
@PostMapping(value = ProjectManagerConst.ACCEPT_PROJECT_RESULTS)
Expand All @@ -572,7 +572,7 @@ public ResponseEntity<String> acceptProjectResults(

@RoleConstraints(projectRoles = {ProjectRole.FINAL})
@StateConstraints(projectStates = {ProjectState.FINAL})
@EmailSender(templateType = EmailTemplateType.RESULTS_REJECTED, recipients = {EmailRecipientType.PROJECT_MANAGER_ADMIN})
@EmailSender(templateType = EmailTemplateType.RESULTS_REJECTED, recipients = {EmailRecipientType.PROJECT_MANAGER_ADMIN, EmailRecipientType.ALL_FINALS})
@FrontendSiteModule(site = ProjectManagerConst.PROJECT_VIEW_SITE, module = ProjectManagerConst.PROJECT_STATE_MODULE)
@FrontendAction(action = ProjectManagerConst.REJECT_PROJECT_RESULTS_ACTION)
@PostMapping(value = ProjectManagerConst.REJECT_PROJECT_RESULTS)
Expand All @@ -585,7 +585,7 @@ public ResponseEntity<String> rejectProjectResults(

@RoleConstraints(projectRoles = {ProjectRole.FINAL})
@StateConstraints(projectStates = {ProjectState.FINAL})
@EmailSender(templateType = EmailTemplateType.REQUEST_CHANGES_IN_PROJECT, recipients = {EmailRecipientType.PROJECT_MANAGER_ADMIN})
@EmailSender(templateType = EmailTemplateType.REQUEST_CHANGES_IN_PROJECT, recipients = {EmailRecipientType.PROJECT_MANAGER_ADMIN, EmailRecipientType.ALL_FINALS})
@FrontendSiteModule(site = ProjectManagerConst.PROJECT_VIEW_SITE, module = ProjectManagerConst.PROJECT_STATE_MODULE)
@FrontendAction(action = ProjectManagerConst.REQUEST_CHANGES_IN_PROJECT_ACTION)
@PostMapping(value = ProjectManagerConst.REQUEST_CHANGES_IN_PROJECT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ public interface ProjectBridgeheadUserRepository extends JpaRepository<ProjectBr

List<ProjectBridgeheadUser> getDistinctByProjectRoleAndProjectBridgehead(ProjectRole role, ProjectBridgehead projectBridgehead);

@Query("SELECT DISTINCT pbu FROM ProjectBridgeheadUser pbu WHERE pbu.projectBridgehead.project.code = :projectCode AND pbu.projectRole = :projectRole")
Set<ProjectBridgeheadUser> getDistinctByProjectRoleAndProjectCode(ProjectRole projectRole, String projectCode);

}
3 changes: 3 additions & 0 deletions src/main/java/de/samply/email/EmailRecipientType.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ public enum EmailRecipientType {
EMAIL_ANNOTATION,
CREATOR,
PROJECT_MANAGER_ADMIN,
ALL_DEVELOPERS,
ALL_PILOTS,
ALL_FINALS,
ALL_BRIDGEHEAD_ADMINS,
BRIDGEHEAD_ADMIN,
BRIDGHEAD_ADMINS_WHO_HAVE_NOT_ACCEPTED_NOR_REJECTED_THE_PROJECT,
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/email-templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,37 @@
"SCRIPT_ACCEPTED": {
"subject": "Script accepted",
"files": {
"PROJECT_MANAGER_ADMIN": "project-manager-admin-script-accepted.html"
"DEFAULT": "default-script-accepted.html"
}
},
"SCRIPT_REJECTED": {
"subject": "Script rejected",
"files": {
"PROJECT_MANAGER_ADMIN": "project-manager-admin-script-rejected.html"
"DEFAULT": "default-script-rejected.html"
}
},
"REQUEST_CHANGES_IN_SCRIPT": {
"subject": "Changes in script requested",
"files": {
"PROJECT_MANAGER_ADMIN": "project-manager-admin-script-changes-requested.html"
"DEFAULT": "default-script-changes-requested.html"
}
},
"RESULTS_ACCEPTED": {
"subject": "Results accepted",
"files": {
"PROJECT_MANAGER_ADMIN": "project-manager-admin-results-accepted.html"
"DEFAULT": "default-admin-results-accepted.html"
}
},
"RESULTS_REJECTED": {
"subject": "Results rejected",
"files": {
"PROJECT_MANAGER_ADMIN": "project-manager-admin-results-rejected.html"
"DEFAULT": "default-admin-results-rejected.html"
}
},
"REQUEST_CHANGES_IN_PROJECT": {
"subject": "Changes in project requested",
"files": {
"PROJECT_MANAGER_ADMIN": "project-manager-admin-results-changes-requested.html"
"DEFAULT": "default-results-changes-requested.html"
}
},
"NEW_TOKEN_FOR_AUTHENTICATION_SCRIPT": {
Expand Down

0 comments on commit cedc2c5

Please sign in to comment.