generated from it-at-m/refarch-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
Send to Postkorb on request #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7cf9753
Updated version; now postkorb message is only sent when sende_nachric…
rowe42 06c5cbe
added handling of attachments
rowe42 58188b2
now resetting the field sende_nachricht_nach_extern in the ticket aft…
rowe42 e4acec7
now resetting the field sende_nachricht_nach_extern in the ticket aft…
rowe42 b56a22d
Merge branch 'main' into feature/send-to-postkorb-on-request
rowe42 ec83ee6
set dependency to api-client-internal 0.5.0-SNAPSHOT
rowe42 4efcb82
Merge branch 'main' into feature/send-to-postkorb-on-request
rowe42 fca1c64
now using ticketing-eai-internal 0.5.0 instead of Snapshot
rowe42 741ecbe
Merge branch 'main' into feature/send-to-postkorb-on-request
rowe42 14b66f2
now using dbs-handler-core v0.2.0 instead of SNAPSHOT
rowe42 e8db1cf
Merge branch 'main' into feature/send-to-postkorb-on-request
rowe42 6b04ba7
dependency to jupiter removed
rowe42 4bfcad2
fixed data model of sende_nachricht_nach_extern
rowe42 b67d46c
sensible config removed
rowe42 3ef5086
Fixes from review
rowe42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
40 changes: 34 additions & 6 deletions
40
...java/de/muenchen/oss/dbs/ticketing/eventing/mailhandler/adapter/out/mail/MailAdapter.java
This file contains hidden or 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,31 +1,59 @@ | ||
package de.muenchen.oss.dbs.ticketing.eventing.mailhandler.adapter.out.mail; | ||
|
||
import de.muenchen.oss.dbs.ticketing.eventing.mailhandler.application.port.out.SendMailOutPort; | ||
import jakarta.activation.DataSource; | ||
import jakarta.mail.MessagingException; | ||
import jakarta.mail.internet.MimeMessage; | ||
import jakarta.mail.util.ByteArrayDataSource; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.mail.javamail.MimeMessageHelper; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class MailAdapter implements SendMailOutPort { | ||
private final JavaMailSender mailSender; | ||
private final MailProperties mailProperties; | ||
|
||
@Override | ||
public void sendMail(final String recipient, final String subject, final String body) { | ||
public void sendMail(final MailMessage mailMessage) { | ||
final MimeMessage mimeMessage = mailSender.createMimeMessage(); | ||
final MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, "utf-8"); | ||
try { | ||
final MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "utf-8"); | ||
helper.setFrom(mailProperties.getFromAddress()); | ||
helper.setTo(recipient); | ||
helper.setSubject(subject); | ||
helper.setText(body, true); | ||
helper.setTo(mailMessage.getRecipient()); | ||
helper.setSubject(mailMessage.getSubject()); | ||
helper.setText(mailMessage.getBody(), true); | ||
for (final Map.Entry<String, InputStream> entry : mailMessage.getAttachments().entrySet()) { | ||
//TODO is there a way to do this with streaming? The following line loads the attachment into RAM... | ||
final DataSource dataSource = new ByteArrayDataSource(entry.getValue(), "application/octet-stream"); | ||
helper.addAttachment(entry.getKey(), dataSource); | ||
//maybe like this? | ||
//helper.addAttachment(e.getKey(), new InputStreamSourceImpl(e.getValue())); | ||
} | ||
mailSender.send(mimeMessage); | ||
} catch (MessagingException e) { | ||
} catch (final MessagingException | IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
// private class InputStreamSourceImpl implements InputStreamSource { | ||
// private final InputStream inputStream; | ||
// | ||
// public InputStreamSourceImpl(InputStream inputStream) { | ||
// this.inputStream = inputStream; | ||
// } | ||
// | ||
// @Override | ||
// public InputStream getInputStream() { | ||
// return inputStream; | ||
// } | ||
// } | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...java/de/muenchen/oss/dbs/ticketing/eventing/mailhandler/adapter/out/mail/MailMessage.java
This file contains hidden or 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,15 @@ | ||
package de.muenchen.oss.dbs.ticketing.eventing.mailhandler.adapter.out.mail; | ||
|
||
import java.io.InputStream; | ||
import java.util.Map; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class MailMessage { | ||
private String recipient; | ||
private String subject; | ||
private String body; | ||
private Map<String, InputStream> attachments; | ||
} |
4 changes: 3 additions & 1 deletion
4
...muenchen/oss/dbs/ticketing/eventing/mailhandler/application/port/out/SendMailOutPort.java
This file contains hidden or 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,5 +1,7 @@ | ||
package de.muenchen.oss.dbs.ticketing.eventing.mailhandler.application.port.out; | ||
|
||
import de.muenchen.oss.dbs.ticketing.eventing.mailhandler.adapter.out.mail.MailMessage; | ||
|
||
public interface SendMailOutPort { | ||
void sendMail(String recipient, String subject, String body); | ||
void sendMail(MailMessage mailMessage); | ||
} |
This file contains hidden or 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 hidden or 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
13 changes: 13 additions & 0 deletions
13
...e/muenchen/oss/dbs/ticketing/eventing/mailhandler/exceptions/NoValidArticleException.java
This file contains hidden or 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,13 @@ | ||
package de.muenchen.oss.dbs.ticketing.eventing.mailhandler.exceptions; | ||
|
||
import java.io.Serial; | ||
|
||
public class NoValidArticleException extends Exception { | ||
// Default access modifier is private | ||
@Serial | ||
private static final long serialVersionUID = 1L; | ||
|
||
public NoValidArticleException(final String s) { | ||
super(s); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.