| 1 | package fr.sii.ogham.email.sendgrid.v4.builder.sendgrid; | |
| 2 | ||
| 3 | import static fr.sii.ogham.email.sendgrid.SendGridConstants.DEFAULT_SENDGRID_CONFIGURER_PRIORITY; | |
| 4 | ||
| 5 | import org.slf4j.Logger; | |
| 6 | import org.slf4j.LoggerFactory; | |
| 7 | ||
| 8 | import fr.sii.ogham.core.builder.MessagingBuilder; | |
| 9 | import fr.sii.ogham.core.builder.configurer.ConfigurerFor; | |
| 10 | import fr.sii.ogham.core.builder.configurer.MessagingConfigurer; | |
| 11 | import fr.sii.ogham.core.builder.context.BuildContext; | |
| 12 | import fr.sii.ogham.core.builder.mimetype.MimetypeDetectionBuilder; | |
| 13 | import fr.sii.ogham.core.util.ClasspathUtils; | |
| 14 | ||
| 15 | /** | |
| 16 | * Default SendGrid configurer that is automatically applied every time a | |
| 17 | * {@link MessagingBuilder} instance is created through | |
| 18 | * {@link MessagingBuilder#standard()}. | |
| 19 | * | |
| 20 | * <p> | |
| 21 | * The configurer has a priority of 30000 in order to be applied after | |
| 22 | * templating configurers and JavaMail configurer. | |
| 23 | * </p> | |
| 24 | * | |
| 25 | * This configurer is applied only if {@code com.sendgrid.SendGrid} is present | |
| 26 | * in the classpath. If not present, SendGrid implementation is not registered | |
| 27 | * at all. | |
| 28 | * | |
| 29 | * <p> | |
| 30 | * This configurer inherits environment configuration (see | |
| 31 | * {@link BuildContext}). | |
| 32 | * </p> | |
| 33 | * <p> | |
| 34 | * This configurer inherits mimetype configuration (see | |
| 35 | * {@link MimetypeDetectionBuilder} and | |
| 36 | * {@link SendGridV4Builder#mimetype(MimetypeDetectionBuilder)}). | |
| 37 | * </p> | |
| 38 | * | |
| 39 | * <p> | |
| 40 | * This configurer applies the following configuration: | |
| 41 | * <ul> | |
| 42 | * <li>Configures authentication by providing an <a href= | |
| 43 | * "https://sendgrid.com/docs/Classroom/Send/How_Emails_Are_Sent/api_keys.html">API | |
| 44 | * key</a>: using the property "ogham.email.sendgrid.api-key".<strong>WARNING: | |
| 45 | * SendGrid v4 doesn't allow username/password anymore. You must use API | |
| 46 | * keys</strong></li> | |
| 47 | * <li>Configures unit testing mode using the property | |
| 48 | * "ogham.email.sendgrid.unit-testing". | |
| 49 | * </ul> | |
| 50 | * | |
| 51 | * | |
| 52 | * | |
| 53 | * @author Aurélien Baudet | |
| 54 | * | |
| 55 | */ | |
| 56 | public final class DefaultSendGridV4Configurer { | |
| 57 | private static final Logger LOG = LoggerFactory.getLogger(DefaultSendGridV4Configurer.class); | |
| 58 | ||
| 59 | @ConfigurerFor(targetedBuilder = "standard", priority = DEFAULT_SENDGRID_CONFIGURER_PRIORITY) | |
| 60 | public static class SendGridV4Configurer implements MessagingConfigurer { | |
| 61 | @Override | |
| 62 | public void configure(MessagingBuilder msgBuilder) { | |
| 63 |
4
1. configure : negated conditional → KILLED 2. configure : negated conditional → KILLED 3. configure : negated conditional → KILLED 4. configure : negated conditional → KILLED |
if (!canUseSendGrid()) { |
| 64 | LOG.debug("[{}] skip configuration", this); | |
| 65 | return; | |
| 66 | } | |
| 67 | LOG.debug("[{}] apply configuration", this); | |
| 68 | // @formatter:off | |
| 69 | SendGridV4Builder builder = msgBuilder.email().sender(SendGridV4Builder.class); | |
| 70 | // inherit mimetype configuration as parent builder | |
| 71 | builder.mimetype(msgBuilder.mimetype()); | |
| 72 | builder | |
| 73 | .apiKey().properties("${ogham.email.sendgrid.api-key}").and() | |
| 74 | .unitTesting().properties("${ogham.email.sendgrid.unit-testing}").and() | |
| 75 | .url().properties("${ogham.email.sendgrid.url}"); | |
| 76 | // @formatter:on | |
| 77 | } | |
| 78 | ||
| 79 | private static boolean canUseSendGrid() { | |
| 80 |
10
1. canUseSendGrid : replaced boolean return with true for fr/sii/ogham/email/sendgrid/v4/builder/sendgrid/DefaultSendGridV4Configurer$SendGridV4Configurer::canUseSendGrid → SURVIVED 2. canUseSendGrid : negated conditional → SURVIVED 3. canUseSendGrid : negated conditional → TIMED_OUT 4. canUseSendGrid : replaced boolean return with true for fr/sii/ogham/email/sendgrid/v4/builder/sendgrid/DefaultSendGridV4Configurer$SendGridV4Configurer::canUseSendGrid → KILLED 5. canUseSendGrid : negated conditional → KILLED 6. canUseSendGrid : negated conditional → KILLED 7. canUseSendGrid : negated conditional → KILLED 8. canUseSendGrid : negated conditional → KILLED 9. canUseSendGrid : negated conditional → KILLED 10. canUseSendGrid : negated conditional → KILLED |
return ClasspathUtils.exists("com.sendgrid.SendGrid") && ClasspathUtils.exists("com.sendgrid.SendGridAPI"); |
| 81 | } | |
| 82 | } | |
| 83 | ||
| 84 | private DefaultSendGridV4Configurer() { | |
| 85 | super(); | |
| 86 | } | |
| 87 | } | |
Mutations | ||
| 63 |
1.1 2.2 3.3 4.4 |
|
| 80 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 |