-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce communication service (#369)
Introduces a new concept of communication service as a domain concept and the implementation is now part of the infrastructure.
- Loading branch information
Showing
85 changed files
with
466 additions
and
428 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
61 changes: 0 additions & 61 deletions
61
...cation/src/main/java/life/qbic/authentication/application/communication/EmailFactory.java
This file was deleted.
Oops, something went wrong.
74 changes: 0 additions & 74 deletions
74
.../src/main/java/life/qbic/authentication/application/communication/UserContactService.java
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
.../qbic/authentication/application/user/policy/WhenPasswordResetSendEmailWithResetLink.java
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
.../qbic/authentication/application/user/policy/WhenUserRegisteredSendConfirmationEmail.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
authorization/src/main/java/life/qbic/authorization/application/Messages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package life.qbic.authorization.application; | ||
|
||
/** | ||
* <b>Messages</b> | ||
* | ||
* <p>A collection of message templates to notify users.</p> | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public class Messages { | ||
|
||
private Messages() { | ||
|
||
} | ||
|
||
/** | ||
* A pre-formatted message that informs a user about their new access grant to a project in the | ||
* data manager. | ||
* | ||
* @param fullNameUser the name of the user to inform for addressing them politely | ||
* @param projectTitle the title of the project, will be in the message to inform the user about | ||
* which project they have been granted access with | ||
* @param projectUri a uniform resource identifier of the project, that the user can use to | ||
* access the project | ||
* @return the filled out template message | ||
* @since 1.0.0 | ||
*/ | ||
public static String projectAccessToUser(String fullNameUser, String projectTitle, | ||
String projectUri) { | ||
return String.format(""" | ||
Dear %s, | ||
you have been granted access to project: | ||
'%s' | ||
Please click the link below to access the project after login: | ||
%s | ||
""", fullNameUser, projectTitle, projectUri); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,13 @@ | |
import life.qbic.authentication.domain.user.concept.UserId; | ||
import life.qbic.authentication.domain.user.repository.UserRepository; | ||
import life.qbic.authorization.application.AppContextProvider; | ||
import life.qbic.authorization.application.Messages; | ||
import life.qbic.domain.concepts.DomainEvent; | ||
import life.qbic.domain.concepts.DomainEventSubscriber; | ||
import life.qbic.domain.concepts.communication.EmailService; | ||
import life.qbic.domain.concepts.communication.CommunicationService; | ||
import life.qbic.domain.concepts.communication.Content; | ||
import life.qbic.domain.concepts.communication.Recipient; | ||
import life.qbic.domain.concepts.communication.Subject; | ||
import life.qbic.projectmanagement.domain.project.service.event.ProjectAccessGranted; | ||
import org.jobrunr.jobs.annotations.Job; | ||
import org.jobrunr.scheduling.JobScheduler; | ||
|
@@ -23,38 +27,24 @@ | |
@Component | ||
public class InformUserAboutGrantedAccess implements DomainEventSubscriber<ProjectAccessGranted> { | ||
|
||
private final EmailService emailService; | ||
private final CommunicationService communicationService; | ||
|
||
private final JobScheduler jobScheduler; | ||
private final UserRepository userRepository; | ||
|
||
private final AppContextProvider appContextProvider; | ||
|
||
public InformUserAboutGrantedAccess(EmailService emailService, JobScheduler jobScheduler, | ||
public InformUserAboutGrantedAccess(CommunicationService communicationService, JobScheduler jobScheduler, | ||
UserRepository userRepository, AppContextProvider appContextProvider) { | ||
this.emailService = Objects.requireNonNull(emailService); | ||
this.communicationService = Objects.requireNonNull(communicationService); | ||
this.jobScheduler = Objects.requireNonNull(jobScheduler); | ||
this.userRepository = Objects.requireNonNull(userRepository); | ||
this.appContextProvider = Objects.requireNonNull(appContextProvider); | ||
} | ||
|
||
private String composeMessage(String projectId, User recipient, String projectTitle) { | ||
return String.format(""" | ||
Dear %s, | ||
you have been granted access to project: | ||
'%s' | ||
Please click the link below to access the project after login: | ||
%s | ||
Need help? Contact us for further questions at [email protected] | ||
Best regards,\ | ||
The QBiC team | ||
""", recipient.fullName(), projectTitle, appContextProvider.urlToProject(projectId)); | ||
return Messages.projectAccessToUser(recipient.fullName().get(), projectTitle, | ||
appContextProvider.urlToProject(projectId)); | ||
} | ||
|
||
@Override | ||
|
@@ -64,14 +54,15 @@ public Class<? extends DomainEvent> subscribedToEventType() { | |
|
||
@Override | ||
public void handleEvent(ProjectAccessGranted event) { | ||
jobScheduler.enqueue(() -> notifyUser(event.forUserId(), event.forProjectId(), event.forProjectTitle())); | ||
jobScheduler.enqueue( | ||
() -> notifyUser(event.forUserId(), event.forProjectId(), event.forProjectTitle())); | ||
} | ||
|
||
@Job(name = "Notify user about granted project access") | ||
public void notifyUser(String userId, String projectId, String projectTitle) | ||
throws RuntimeException { | ||
var recipient = userRepository.findById(UserId.from(userId)).get(); | ||
emailService.send(recipient.emailAddress().get(), recipient.fullName().get(), | ||
"Project access granted", composeMessage(projectId, recipient, projectTitle)); | ||
var message = Messages.projectAccessToUser(recipient.fullName().get(), projectTitle, projectId); | ||
communicationService.send(new Subject("Project access granted"), new Recipient(recipient.emailAddress().get(), recipient.fullName().get()), new Content(message)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...concept/src/main/java/life/qbic/domain/concepts/communication/CommunicationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package life.qbic.domain.concepts.communication; | ||
|
||
import java.io.Serial; | ||
|
||
/** | ||
* <b>Communication Exception</b> | ||
* | ||
* <p>Exception that shall be thrown to indicate issues during communication with the user</p> | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public class CommunicationException extends RuntimeException { | ||
|
||
@Serial | ||
private static final long serialVersionUID = 7816744418299591709L; | ||
|
||
public CommunicationException() { | ||
super(); | ||
} | ||
|
||
public CommunicationException(String message) { | ||
super(message); | ||
} | ||
|
||
public CommunicationException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
} |
Oops, something went wrong.