1 | package fr.sii.ogham.email.sender; | |
2 | ||
3 | import static fr.sii.ogham.core.util.LogUtils.logString; | |
4 | ||
5 | import org.slf4j.Logger; | |
6 | import org.slf4j.LoggerFactory; | |
7 | ||
8 | import fr.sii.ogham.core.exception.MessageException; | |
9 | import fr.sii.ogham.core.exception.MessageNotSentException; | |
10 | import fr.sii.ogham.core.message.Message; | |
11 | import fr.sii.ogham.core.resource.NamedResource; | |
12 | import fr.sii.ogham.core.resource.resolver.ResourceResolver; | |
13 | import fr.sii.ogham.core.sender.ConditionalSender; | |
14 | import fr.sii.ogham.core.sender.MessageSender; | |
15 | import fr.sii.ogham.core.translator.resource.AttachmentResourceTranslator; | |
16 | import fr.sii.ogham.email.attachment.Attachment; | |
17 | import fr.sii.ogham.email.exception.attachment.translator.ResourceTranslatorException; | |
18 | import fr.sii.ogham.email.message.Email; | |
19 | ||
20 | /** | |
21 | * Decorator sender that transforms the attachments of the message before really | |
22 | * sending it. This sender relies on {@link AttachmentResourceTranslator} to | |
23 | * transform attachments. Once the attachments are transformed, this sender | |
24 | * delegates to a real implementation the sending of the message. | |
25 | * | |
26 | * @author Aurélien Baudet | |
27 | * @see ResourceResolver | |
28 | * @see NamedResource | |
29 | */ | |
30 | public class AttachmentResourceTranslatorSender implements ConditionalSender { | |
31 | private static final Logger LOG = LoggerFactory.getLogger(AttachmentResourceTranslatorSender.class); | |
32 | ||
33 | /** | |
34 | * The translator used to transform attachments | |
35 | */ | |
36 | private AttachmentResourceTranslator translator; | |
37 | ||
38 | /** | |
39 | * The decorated sender that will really send the message | |
40 | */ | |
41 | private MessageSender delegate; | |
42 | ||
43 | /** | |
44 | * Initialize the sender with the provided translator and decorated sender. | |
45 | * The translator implementation will transform attachments of the message. | |
46 | * The decorated sender will really send the message. | |
47 | * | |
48 | * @param translator | |
49 | * the translator implementation that will transform the | |
50 | * attachments of the message | |
51 | * @param delegate | |
52 | * The decorated sender will really send the message | |
53 | */ | |
54 | public AttachmentResourceTranslatorSender(AttachmentResourceTranslator translator, MessageSender delegate) { | |
55 | super(); | |
56 | this.translator = translator; | |
57 | this.delegate = delegate; | |
58 | } | |
59 | ||
60 | @Override | |
61 | public boolean supports(Message message) { | |
62 |
6
1. supports : negated conditional → NO_COVERAGE 2. supports : negated conditional → SURVIVED 3. supports : negated conditional → TIMED_OUT 4. supports : negated conditional → KILLED 5. supports : negated conditional → KILLED 6. supports : negated conditional → KILLED |
if (delegate instanceof ConditionalSender) { |
63 |
12
1. supports : replaced boolean return with false for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::supports → NO_COVERAGE 2. supports : replaced boolean return with false for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::supports → SURVIVED 3. supports : replaced boolean return with true for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::supports → SURVIVED 4. supports : replaced boolean return with true for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::supports → NO_COVERAGE 5. supports : replaced boolean return with false for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::supports → TIMED_OUT 6. supports : replaced boolean return with true for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::supports → TIMED_OUT 7. supports : replaced boolean return with false for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::supports → KILLED 8. supports : replaced boolean return with false for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::supports → KILLED 9. supports : replaced boolean return with false for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::supports → KILLED 10. supports : replaced boolean return with true for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::supports → KILLED 11. supports : replaced boolean return with true for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::supports → KILLED 12. supports : replaced boolean return with true for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::supports → KILLED |
return ((ConditionalSender) delegate).supports(message); |
64 | } | |
65 |
1
1. supports : replaced boolean return with false for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::supports → NO_COVERAGE |
return true; |
66 | } | |
67 | ||
68 | @Override | |
69 | public void send(Message message) throws MessageException { | |
70 | try { | |
71 | for (Attachment attachment : ((Email) message).getAttachments()) { | |
72 | LOG.debug("Translate attachment {} for the message {} using {}", attachment, logString(message), translator); | |
73 |
3
1. send : removed call to fr/sii/ogham/email/attachment/Attachment::setResource → NO_COVERAGE 2. send : removed call to fr/sii/ogham/email/attachment/Attachment::setResource → SURVIVED 3. send : removed call to fr/sii/ogham/email/attachment/Attachment::setResource → KILLED |
attachment.setResource((NamedResource) translator.translate(attachment.getResource())); |
74 | } | |
75 | LOG.debug("Sending message {} using {}", logString(message), delegate); | |
76 |
5
1. send : removed call to fr/sii/ogham/core/sender/MessageSender::send → NO_COVERAGE 2. send : removed call to fr/sii/ogham/core/sender/MessageSender::send → TIMED_OUT 3. send : removed call to fr/sii/ogham/core/sender/MessageSender::send → KILLED 4. send : removed call to fr/sii/ogham/core/sender/MessageSender::send → KILLED 5. send : removed call to fr/sii/ogham/core/sender/MessageSender::send → KILLED |
delegate.send(message); |
77 | } catch (ResourceTranslatorException e) { | |
78 | throw new MessageNotSentException("Failed to send message due to attachment translation", message, e); | |
79 | } | |
80 | } | |
81 | ||
82 | @Override | |
83 | public String toString() { | |
84 | StringBuilder builder = new StringBuilder(); | |
85 | builder.append("AttachmentResourceResolverSender [translator=").append(translator).append(", delegate=").append(delegate).append("]"); | |
86 |
3
1. toString : replaced return value with "" for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::toString → SURVIVED 2. toString : replaced return value with "" for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::toString → NO_COVERAGE 3. toString : replaced return value with "" for fr/sii/ogham/email/sender/AttachmentResourceTranslatorSender::toString → TIMED_OUT |
return builder.toString(); |
87 | } | |
88 | } | |
Mutations | ||
62 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
63 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 12.12 |
|
65 |
1.1 |
|
73 |
1.1 2.2 3.3 |
|
76 |
1.1 2.2 3.3 4.4 5.5 |
|
86 |
1.1 2.2 3.3 |