-
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.
Merge pull request #402 from qbicsoftware/release/2023-10-17
Release 2023 10 17
- Loading branch information
Showing
32 changed files
with
987 additions
and
62 deletions.
There are no files selected for viewing
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
12 changes: 12 additions & 0 deletions
12
domain-concept/src/main/java/life/qbic/domain/concepts/communication/Attachment.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,12 @@ | ||
package life.qbic.domain.concepts.communication; | ||
|
||
/** | ||
* <b>MailAttachment</b> | ||
* | ||
* <p>Encapsulates information about an attachment, e.g. a file added to an email</p> | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public record Attachment(String content, String name) { | ||
|
||
} |
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
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 |
---|---|---|
@@ -1,11 +1,20 @@ | ||
package life.qbic.newshandler.usermanagement.email; | ||
|
||
import jakarta.activation.DataHandler; | ||
import jakarta.activation.DataSource; | ||
import jakarta.mail.BodyPart; | ||
import jakarta.mail.Message.RecipientType; | ||
import jakarta.mail.MessagingException; | ||
import jakarta.mail.Multipart; | ||
import jakarta.mail.Transport; | ||
import jakarta.mail.internet.InternetAddress; | ||
import jakarta.mail.internet.MimeBodyPart; | ||
import jakarta.mail.internet.MimeMessage; | ||
import jakarta.mail.internet.MimeMultipart; | ||
import jakarta.mail.util.ByteArrayDataSource; | ||
import java.io.UnsupportedEncodingException; | ||
import java.util.Objects; | ||
import life.qbic.domain.concepts.communication.Attachment; | ||
import life.qbic.domain.concepts.communication.CommunicationException; | ||
import life.qbic.domain.concepts.communication.CommunicationService; | ||
import life.qbic.domain.concepts.communication.Content; | ||
|
@@ -27,7 +36,7 @@ public class EmailCommunicationService implements CommunicationService { | |
private static final Logger log = LoggerFactory.logger( | ||
EmailCommunicationService.class); | ||
private static final String NO_REPLY_ADDRESS = "[email protected]"; | ||
|
||
private static final String NOTIFICATION_FAILED = "Notification of recipient failed!"; | ||
private static final String SIGNATURE = """ | ||
With kind regards, | ||
|
@@ -54,17 +63,63 @@ public void send(Subject subject, Recipient recipient, Content content) { | |
"Sending email with subject %s to %s".formatted(subject.content(), recipient.address())); | ||
} catch (MessagingException e) { | ||
log.error("Could not send email to " + recipient.address(), e); | ||
throw new CommunicationException("Notification of recipient failed!"); | ||
throw new CommunicationException(NOTIFICATION_FAILED); | ||
} | ||
} | ||
|
||
private MimeMessage setupMessage(Subject subject, Recipient recipient, Content content) | ||
@Override | ||
public void send(Subject subject, Recipient recipient, Content content, Attachment attachment) { | ||
try { | ||
var message = setupMessageWithAttachment(subject, recipient, content, attachment); | ||
Transport.send(message); | ||
log.debug( | ||
"Sending email with subject %s to %s".formatted(subject.content(), recipient.address())); | ||
} catch (MessagingException e) { | ||
log.error("Could not send email to " + recipient.address(), e); | ||
throw new CommunicationException(NOTIFICATION_FAILED); | ||
} catch (UnsupportedEncodingException e) { | ||
log.error("Could not create attachment for email to " + recipient.address(), e); | ||
throw new CommunicationException(NOTIFICATION_FAILED); | ||
} | ||
} | ||
|
||
private MimeMessage setupMessageWithoutContent(Subject subject, Recipient recipient) | ||
throws MessagingException { | ||
var message = this.mailServerConfiguration.mimeMessage(); | ||
message.setFrom(new InternetAddress(NO_REPLY_ADDRESS)); | ||
message.setContent(combineMessageWithRegards(content).content(), "text/plain"); | ||
message.setRecipient(RecipientType.TO, new InternetAddress(recipient.address())); | ||
message.setSubject(subject.content()); | ||
return message; | ||
} | ||
|
||
private MimeMessage setupMessage(Subject subject, Recipient recipient, Content content) | ||
throws MessagingException { | ||
var message = setupMessageWithoutContent(subject, recipient); | ||
message.setContent(combineMessageWithRegards(content).content(), "text/plain"); | ||
return message; | ||
} | ||
|
||
private MimeMessage setupMessageWithAttachment(Subject subject, Recipient recipient, | ||
Content content, Attachment attachment) | ||
throws MessagingException, UnsupportedEncodingException { | ||
|
||
var message = setupMessageWithoutContent(subject, recipient); | ||
|
||
BodyPart messageBodyPart = new MimeBodyPart(); | ||
messageBodyPart.setContent(combineMessageWithRegards(content).content(), "text/plain"); | ||
|
||
Multipart multipart = new MimeMultipart(); | ||
multipart.addBodyPart(messageBodyPart); | ||
|
||
BodyPart attachmentPart = new MimeBodyPart(); | ||
DataSource dataSource = new ByteArrayDataSource(attachment.content().getBytes("UTF-8"), | ||
"application/octet-stream"); | ||
attachmentPart.setDataHandler(new DataHandler(dataSource)); | ||
attachmentPart.setFileName(attachment.name()); | ||
multipart.addBodyPart(attachmentPart); | ||
|
||
message.setContent(multipart); | ||
return 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
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
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
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
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
35 changes: 35 additions & 0 deletions
35
...n/src/main/java/life/qbic/projectmanagement/application/policy/BatchRegisteredPolicy.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,35 @@ | ||
package life.qbic.projectmanagement.application.policy; | ||
|
||
import life.qbic.domain.concepts.DomainEventDispatcher; | ||
import life.qbic.projectmanagement.application.policy.directive.InformUsersAboutBatchRegistration; | ||
|
||
/** | ||
* <b>Policy: Batch Registered</b> | ||
* <p> | ||
* A collection of all directives that need to be executed after a new batch of | ||
* samples has been registered for measurement. | ||
* <p> | ||
* The policy subscribes to events of type | ||
* {@link life.qbic.projectmanagement.domain.project.sample.event.BatchRegistered} and ensures the | ||
* registration of all business required directives. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public class BatchRegisteredPolicy { | ||
|
||
private final InformUsersAboutBatchRegistration informUsers; | ||
|
||
/** | ||
* Creates an instance of a {@link BatchRegisteredPolicy} object. | ||
* <p> | ||
* All directives will be created and subscribed upon instantiation. | ||
* | ||
* @param informUsers directive to inform users of a project about the new samples of a batch | ||
* {@link life.qbic.projectmanagement.domain.project.sample.Batch} | ||
* @since 1.0.0 | ||
*/ | ||
public BatchRegisteredPolicy(InformUsersAboutBatchRegistration informUsers) { | ||
this.informUsers = informUsers; | ||
DomainEventDispatcher.instance().subscribe(this.informUsers); | ||
} | ||
} |
Oops, something went wrong.