| 1 | package fr.sii.ogham.spring.general; | |
| 2 | ||
| 3 | import static fr.sii.ogham.spring.util.PropertiesUtils.asArray; | |
| 4 | import static java.util.Optional.ofNullable; | |
| 5 | ||
| 6 | import org.slf4j.Logger; | |
| 7 | import org.slf4j.LoggerFactory; | |
| 8 | ||
| 9 | import fr.sii.ogham.core.CoreConstants; | |
| 10 | import fr.sii.ogham.core.builder.MessagingBuilder; | |
| 11 | import fr.sii.ogham.core.builder.mimetype.MimetypeDetectionBuilder; | |
| 12 | import fr.sii.ogham.email.builder.EmailBuilder; | |
| 13 | import fr.sii.ogham.sms.builder.SmsBuilder; | |
| 14 | import fr.sii.ogham.spring.common.OghamMimetypeProperties; | |
| 15 | import fr.sii.ogham.spring.common.SpringMessagingConfigurer; | |
| 16 | import fr.sii.ogham.spring.email.OghamEmailProperties; | |
| 17 | import fr.sii.ogham.spring.sms.OghamSmsProperties; | |
| 18 | ||
| 19 | /** | |
| 20 | * This configurer is useful to support property naming variants (see <a href= | |
| 21 | * "https://github.com/spring-projects/spring-boot/wiki/relaxed-binding-2.0">Relaxed | |
| 22 | * Binding</a>). | |
| 23 | * | |
| 24 | * @author Aurélien Baudet | |
| 25 | * | |
| 26 | */ | |
| 27 | public class SpringGeneralMessagingConfigurer implements SpringMessagingConfigurer { | |
| 28 | private static final Logger LOG = LoggerFactory.getLogger(SpringGeneralMessagingConfigurer.class); | |
| 29 | | |
| 30 | private final MessagingProperties messagingProperties; | |
| 31 | private final OghamEmailProperties emailProperties; | |
| 32 | private final OghamSmsProperties smsProperties; | |
| 33 | private final OghamMimetypeProperties mimetypeProperties; | |
| 34 | ||
| 35 | public SpringGeneralMessagingConfigurer(MessagingProperties messagingProperties, OghamEmailProperties emailProperties, OghamSmsProperties smsProperties, | |
| 36 | OghamMimetypeProperties mimetypeProperties) { | |
| 37 | super(); | |
| 38 | this.messagingProperties = messagingProperties; | |
| 39 | this.emailProperties = emailProperties; | |
| 40 | this.smsProperties = smsProperties; | |
| 41 | this.mimetypeProperties = mimetypeProperties; | |
| 42 | } | |
| 43 | ||
| 44 | @Override | |
| 45 | public void configure(MessagingBuilder builder) { | |
| 46 | LOG.debug("[{}] apply general configuration properties to {}", this, builder); | |
| 47 | // @formatter:off | |
| 48 | builder | |
| 49 | .wrapUncaught().value(ofNullable(messagingProperties.getWrapUncaughtExceptions().isEnable())); | |
| 50 | // @formatter:on | |
| 51 |
1
1. configure : removed call to fr/sii/ogham/spring/general/SpringGeneralMessagingConfigurer::configure → SURVIVED |
configure(builder.email()); |
| 52 |
1
1. configure : removed call to fr/sii/ogham/spring/general/SpringGeneralMessagingConfigurer::configure → SURVIVED |
configure(builder.sms()); |
| 53 |
1
1. configure : removed call to fr/sii/ogham/spring/general/SpringGeneralMessagingConfigurer::configure → SURVIVED |
configure(builder.mimetype()); |
| 54 | } | |
| 55 | ||
| 56 | private void configure(EmailBuilder builder) { | |
| 57 | // configure mimetype detection for images | |
| 58 |
1
1. configure : removed call to fr/sii/ogham/spring/general/SpringGeneralMessagingConfigurer::configureImageInliningMimetype → SURVIVED |
configureImageInliningMimetype(builder.images().inline().mimetype()); |
| 59 | // @formatter:off | |
| 60 | builder | |
| 61 | .autofill() | |
| 62 | .subject() | |
| 63 | .defaultValue().value(ofNullable(emailProperties.getSubject().getDefaultValue())).and() | |
| 64 | .htmlTitle().value(ofNullable(emailProperties.getSubject().getExtractHtmlTitle().isEnable())).and() | |
| 65 | .text().value(ofNullable(emailProperties.getSubject().getExtractFromText().getFirstLinePrefix())).and() | |
| 66 | .and() | |
| 67 | .from() | |
| 68 | .defaultValue().value(ofNullable(emailProperties.getFrom().getDefaultValue())).and() | |
| 69 | .and() | |
| 70 | .to() | |
| 71 | .defaultValue().value(ofNullable(asArray(emailProperties.getTo().getDefaultValue(), String.class))).and() | |
| 72 | .and() | |
| 73 | .cc() | |
| 74 | .defaultValue().value(ofNullable(asArray(emailProperties.getCc().getDefaultValue(), String.class))).and() | |
| 75 | .and() | |
| 76 | .bcc() | |
| 77 | .defaultValue().value(ofNullable(asArray(emailProperties.getBcc().getDefaultValue(), String.class))).and() | |
| 78 | .and() | |
| 79 | .and() | |
| 80 | .autoRetry() | |
| 81 | .fixedDelay() | |
| 82 | .maxRetries().value(ofNullable(emailProperties.getSendRetry().getMaxAttempts())).and() | |
| 83 | .delay().value(ofNullable(emailProperties.getSendRetry().getDelayBetweenAttempts())).and() | |
| 84 | .and() | |
| 85 | .exponentialDelay() | |
| 86 | .maxRetries().value(ofNullable(emailProperties.getSendRetry().getMaxAttempts())).and() | |
| 87 | .initialDelay().value(ofNullable(emailProperties.getSendRetry().getExponentialInitialDelay())).and() | |
| 88 | .and() | |
| 89 | .perExecutionDelay() | |
| 90 | .maxRetries().value(ofNullable(emailProperties.getSendRetry().getMaxAttempts())).and() | |
| 91 | .delays().value(ofNullable(asArray(emailProperties.getSendRetry().getPerExecutionDelays(), Long.class))).and() | |
| 92 | .and() | |
| 93 | .fixedInterval() | |
| 94 | .maxRetries().value(ofNullable(emailProperties.getSendRetry().getMaxAttempts())).and() | |
| 95 | .interval().value(ofNullable(emailProperties.getSendRetry().getExecutionInterval())); | |
| 96 | // @formatter:on | |
| 97 | } | |
| 98 | ||
| 99 | private void configure(SmsBuilder builder) { | |
| 100 | // @formatter:off | |
| 101 | builder | |
| 102 | .autofill() | |
| 103 | .from() | |
| 104 | .defaultValue().value(ofNullable(smsProperties.getFrom().getDefaultValue())).and() | |
| 105 | .and() | |
| 106 | .to() | |
| 107 | .defaultValue().value(ofNullable(asArray(smsProperties.getTo().getDefaultValue(), String.class))).and() | |
| 108 | .and() | |
| 109 | .and() | |
| 110 | .numbers() | |
| 111 | .from() | |
| 112 | .format() | |
| 113 | .alphanumericCode().value(ofNullable(smsProperties.getFrom().getAlphanumericCodeFormat().getEnable())).and() | |
| 114 | .shortCode().value(ofNullable(smsProperties.getFrom().getShortCodeFormat().getEnable())).and() | |
| 115 | .internationalNumber().value(ofNullable(smsProperties.getFrom().getInternationalFormat().getEnable())).and() | |
| 116 | .and() | |
| 117 | .and() | |
| 118 | .to() | |
| 119 | .format() | |
| 120 | .internationalNumber().value(ofNullable(smsProperties.getTo().getInternationalFormat().getEnable())).and() | |
| 121 | .and() | |
| 122 | .and() | |
| 123 | .and() | |
| 124 | .autoRetry() | |
| 125 | .fixedDelay() | |
| 126 | .maxRetries().value(ofNullable(smsProperties.getSendRetry().getMaxAttempts())).and() | |
| 127 | .delay().value(ofNullable(smsProperties.getSendRetry().getDelayBetweenAttempts())).and() | |
| 128 | .and() | |
| 129 | .exponentialDelay() | |
| 130 | .maxRetries().value(ofNullable(smsProperties.getSendRetry().getMaxAttempts())).and() | |
| 131 | .initialDelay().value(ofNullable(smsProperties.getSendRetry().getExponentialInitialDelay())).and() | |
| 132 | .and() | |
| 133 | .perExecutionDelay() | |
| 134 | .maxRetries().value(ofNullable(smsProperties.getSendRetry().getMaxAttempts())).and() | |
| 135 | .delays().value(ofNullable(asArray(smsProperties.getSendRetry().getPerExecutionDelays(), Long.class))).and() | |
| 136 | .and() | |
| 137 | .fixedInterval() | |
| 138 | .maxRetries().value(ofNullable(smsProperties.getSendRetry().getMaxAttempts())).and() | |
| 139 | .interval().value(ofNullable(smsProperties.getSendRetry().getExecutionInterval())); | |
| 140 | // @formatter:on | |
| 141 | } | |
| 142 | ||
| 143 | private void configure(MimetypeDetectionBuilder<?> builder) { | |
| 144 | // @formatter:off | |
| 145 | builder | |
| 146 | .tika() | |
| 147 | .failIfOctetStream().value(ofNullable(mimetypeProperties.getTika().isFailIfOctetStream())).and() | |
| 148 | .and() | |
| 149 | .defaultMimetype().value(ofNullable(mimetypeProperties.getDefaultMimetype())); | |
| 150 | // @formatter:on | |
| 151 | } | |
| 152 | ||
| 153 | private void configureImageInliningMimetype(MimetypeDetectionBuilder<?> builder) { | |
| 154 | // @formatter:off | |
| 155 | builder | |
| 156 | .allowed().value(ofNullable(asArray(emailProperties.getImageInlining().getMimetype().getAllowedMimetypes(), String.class))); | |
| 157 | // @formatter:on | |
| 158 | } | |
| 159 | ||
| 160 | @Override | |
| 161 | public int getOrder() { | |
| 162 |
1
1. getOrder : replaced int return with 0 for fr/sii/ogham/spring/general/SpringGeneralMessagingConfigurer::getOrder → SURVIVED |
return CoreConstants.DEFAULT_MESSAGING_CONFIGURER_PRIORITY + 1000; |
| 163 | } | |
| 164 | ||
| 165 | } | |
Mutations | ||
| 51 |
1.1 |
|
| 52 |
1.1 |
|
| 53 |
1.1 |
|
| 58 |
1.1 |
|
| 162 |
1.1 |