1 | package fr.sii.ogham.sms.builder.ovh; | |
2 | ||
3 | import static fr.sii.ogham.core.builder.configuration.MayOverride.overrideIfNotSet; | |
4 | import static fr.sii.ogham.sms.OvhSmsConstants.DEFAULT_OVHSMS_CONFIGURER_PRIORITY; | |
5 | ||
6 | import java.net.MalformedURLException; | |
7 | import java.net.URL; | |
8 | ||
9 | import org.slf4j.Logger; | |
10 | import org.slf4j.LoggerFactory; | |
11 | ||
12 | import fr.sii.ogham.core.builder.MessagingBuilder; | |
13 | import fr.sii.ogham.core.builder.configurer.ConfigurerFor; | |
14 | import fr.sii.ogham.core.builder.configurer.MessagingConfigurer; | |
15 | import fr.sii.ogham.core.builder.context.BuildContext; | |
16 | import fr.sii.ogham.sms.sender.impl.ovh.SmsCoding; | |
17 | ||
18 | /** | |
19 | * Default configurer that configures sending of SMS through OVH HTTP API .The | |
20 | * configurer is automatically applied every time a {@link MessagingBuilder} | |
21 | * instance is created through {@link MessagingBuilder#standard()}. | |
22 | * | |
23 | * <p> | |
24 | * The configurer has a priority of 20000 in order to be applied after | |
25 | * templating configurers, email configurers and SMPP configurer. | |
26 | * </p> | |
27 | * | |
28 | * This configurer is always applied but sender is only used if OVH URL, | |
29 | * account, username and password are defined. | |
30 | * | |
31 | * <p> | |
32 | * This configurer inherits environment configuration (see | |
33 | * {@link BuildContext}). | |
34 | * </p> | |
35 | * | |
36 | * <p> | |
37 | * This configurer applies the following configuration: | |
38 | * <ul> | |
39 | * <li>Configures OVH URL: | |
40 | * <ul> | |
41 | * <li>It uses the property "ogham.sms.ovh.url" if defined. By default URL is | |
42 | * "https://www.ovh.com/cgi-bin/sms/http2sms.cgi"</li> | |
43 | * </ul> | |
44 | * </li> | |
45 | * <li>Configures authentication: | |
46 | * <ul> | |
47 | * <li>It uses properties "ogham.sms.ovh.account", "ogham.sms.ovh.login" and | |
48 | * "ogham.sms.ovh.password" (these properties are mandatory to be able to send | |
49 | * SMS through OVH)</li> | |
50 | * </ul> | |
51 | * </li> | |
52 | * <li>Configures extra options: | |
53 | * <ul> | |
54 | * <li>It uses "ogham.sms.ovh.options.no-stop" property value to enable/disable | |
55 | * "STOP" indication at the end of the message (useful to disable for | |
56 | * non-commercial SMS). Default to true (disabled)</li> | |
57 | * <li>It uses "ogham.sms.ovh.options.sms-coding" property value to define | |
58 | * message encoding (see {@link SmsCoding}): 1 for 7bit encoding, 2 for 16bit | |
59 | * encoding (Unicode). If you use Unicode, your SMS will have a maximum size of | |
60 | * 70 characters instead of 160. If nothing specified, auto-detection is used. | |
61 | * Set this property if you want to force {@link SmsCoding} value.</li> | |
62 | * <li>It uses "ogham.sms.ovh.options.tag" to mark sent messages with a 20 | |
63 | * maximum character string</li> | |
64 | * </ul> | |
65 | * </li> | |
66 | * </ul> | |
67 | * | |
68 | * @author Aurélien Baudet | |
69 | * | |
70 | */ | |
71 | public final class DefaultOvhSmsConfigurer { | |
72 | private static final Logger LOG = LoggerFactory.getLogger(DefaultOvhSmsConfigurer.class); | |
73 | ||
74 | @ConfigurerFor(targetedBuilder = "standard", priority = DEFAULT_OVHSMS_CONFIGURER_PRIORITY) | |
75 | public static class OvhSmsConfigurer implements MessagingConfigurer { | |
76 | @Override | |
77 | public void configure(MessagingBuilder msgBuilder) { | |
78 | LOG.debug("[{}] apply configuration", this); | |
79 | OvhSmsBuilder builder = msgBuilder.sms().sender(OvhSmsBuilder.class); | |
80 | // @formatter:off | |
81 | builder | |
82 | .url().properties("${ogham.sms.ovh.url}").defaultValue(overrideIfNotSet(defaultUrl())).and() | |
83 | .account().properties("${ogham.sms.ovh.account}").and() | |
84 | .login().properties("${ogham.sms.ovh.login}").and() | |
85 | .password().properties("${ogham.sms.ovh.password}").and() | |
86 | .options() | |
87 | .noStop().properties("${ogham.sms.ovh.options.no-stop}").defaultValue(overrideIfNotSet(true)).and() | |
88 | .smsCoding().properties("${ogham.sms.ovh.options.sms-coding}").and() | |
89 | .tag().properties("${ogham.sms.ovh.options.tag}"); | |
90 | // @formatter:on | |
91 | } | |
92 | ||
93 | private static URL defaultUrl() { | |
94 | try { | |
95 |
2
1. defaultUrl : replaced return value with null for fr/sii/ogham/sms/builder/ovh/DefaultOvhSmsConfigurer$OvhSmsConfigurer::defaultUrl → SURVIVED 2. defaultUrl : replaced return value with null for fr/sii/ogham/sms/builder/ovh/DefaultOvhSmsConfigurer$OvhSmsConfigurer::defaultUrl → NO_COVERAGE |
return new URL("https://www.ovh.com/cgi-bin/sms/http2sms.cgi"); |
96 | } catch (MalformedURLException e) { | |
97 | // can never be thrown | |
98 | return null; | |
99 | } | |
100 | } | |
101 | } | |
102 | ||
103 | private DefaultOvhSmsConfigurer() { | |
104 | super(); | |
105 | } | |
106 | } | |
Mutations | ||
95 |
1.1 2.2 |