1 | package fr.sii.ogham.sms.builder.smsglobal; | |
2 | ||
3 | import static fr.sii.ogham.core.util.BuilderUtils.evaluate; | |
4 | import static fr.sii.ogham.sms.CloudhopperConstants.DEFAULT_CLOUDHOPPER_CONFIGURER_PRIORITY; | |
5 | import static fr.sii.ogham.sms.CloudhopperConstants.DEFAULT_GSM8_ENCODING_PRIORITY; | |
6 | import static fr.sii.ogham.sms.CloudhopperConstants.DEFAULT_UCS2_ENCODING_PRIORITY; | |
7 | import static fr.sii.ogham.sms.builder.cloudhopper.InterfaceVersion.VERSION_3_4; | |
8 | import static java.util.Arrays.asList; | |
9 | ||
10 | import org.slf4j.Logger; | |
11 | import org.slf4j.LoggerFactory; | |
12 | ||
13 | import fr.sii.ogham.core.builder.MessagingBuilder; | |
14 | import fr.sii.ogham.core.builder.configurer.ConfigurerFor; | |
15 | import fr.sii.ogham.core.builder.configurer.MessagingConfigurer; | |
16 | import fr.sii.ogham.core.builder.context.BuildContext; | |
17 | import fr.sii.ogham.core.env.PropertyResolver; | |
18 | import fr.sii.ogham.core.util.ClasspathUtils; | |
19 | import fr.sii.ogham.sms.builder.cloudhopper.CloudhopperBuilder; | |
20 | import fr.sii.ogham.sms.builder.cloudhopper.DefaultCloudhopperConfigurer; | |
21 | ||
22 | /** | |
23 | * Default configurer for Cloudhoppder that is automatically applied every time | |
24 | * a {@link MessagingBuilder} instance is created through | |
25 | * {@link MessagingBuilder#standard()}. | |
26 | * | |
27 | * <p> | |
28 | * The configurer has a priority of 40001 in order to be applied before | |
29 | * {@link DefaultCloudhopperConfigurer}. | |
30 | * </p> | |
31 | * | |
32 | * This configurer is applied only if: | |
33 | * <ul> | |
34 | * <li>{@code com.cloudhopper.smpp.SmppClient} is present in the classpath</li> | |
35 | * <li>and the property | |
36 | * "ogham.sms.automatic-service-provider-configuration.enable" is true (default | |
37 | * value)</li> | |
38 | * <li>and the property "ogham.sms.cloudhopper.host" or "ogham.sms.smpp.host" | |
39 | * equals "smpp.smsglobal.com"</li> | |
40 | * </ul> | |
41 | * | |
42 | * <p> | |
43 | * This configurer inherits environment configuration (see | |
44 | * {@link BuildContext}). | |
45 | * </p> | |
46 | * | |
47 | * <p> | |
48 | * This configurer applies the following configuration: | |
49 | * <ul> | |
50 | * <li>Configures SMSGlobal service info: | |
51 | * <ul> | |
52 | * <li>Set "ogham.sms.cloudhopper.port" property value to 1175</li> | |
53 | * <li>Set "ogham.sms.cloudhopper.interface-version" property value to | |
54 | * "3.4"</li> | |
55 | * </ul> | |
56 | * </li> | |
57 | * <li>Configures encoding: | |
58 | * <ul> | |
59 | * <li>Set "ogham.sms.cloudhopper.encoder.gsm7bit-packed.priority" property to 0 | |
60 | * to disable GSM 7-bit encoding (not supported by SMSGlobal)</li> | |
61 | * <li>Let default value for "ogham.sms.cloudhopper.encoder.gsm8bit.priority" to | |
62 | * enable GSM 8-bit data encoding if the message contains only characters that | |
63 | * can be encoded on one octet.</li> | |
64 | * <li>Let default value for "ogham.sms.cloudhopper.encoder.ucs2.priority" to | |
65 | * enable UCS-2 encoding if the message contains special characters that can't | |
66 | * be encoded on one octet. Each character is encoded on two octets.</li> | |
67 | * </ul> | |
68 | * </li> | |
69 | * <li>Configures message splitting: | |
70 | * <ul> | |
71 | * <li>Split is not done by Ogham but directly by Smsglobal instead. The message | |
72 | * is transmitted using "message_payload" TLV parameter.</li> | |
73 | * </ul> | |
74 | * </li> | |
75 | * </ul> | |
76 | * | |
77 | * @author Aurélien Baudet | |
78 | * | |
79 | */ | |
80 | public final class SmsglobalServiceProviderConfigurer { | |
81 | private static final Logger LOG = LoggerFactory.getLogger(SmsglobalServiceProviderConfigurer.class); | |
82 | private static final String SMSGLOBAL_HOST = "smpp.smsglobal.com"; | |
83 | private static final int SMSGLOBAL_PORT = 1775; | |
84 | ||
85 | @ConfigurerFor(targetedBuilder = "standard", priority = DEFAULT_CLOUDHOPPER_CONFIGURER_PRIORITY + 1) | |
86 | public static class SmsglobalConfigurer implements MessagingConfigurer { | |
87 | ||
88 | @Override | |
89 | public void configure(MessagingBuilder msgBuilder) { | |
90 |
6
1. configure : negated conditional → SURVIVED 2. configure : negated conditional → TIMED_OUT 3. configure : negated conditional → KILLED 4. configure : negated conditional → KILLED 5. configure : negated conditional → KILLED 6. configure : negated conditional → KILLED |
if (!canUseCloudhopper() || !usingSmsGlobal(msgBuilder.environment().build())) { |
91 | LOG.debug("[{}] skip service provider configuration", this); | |
92 | return; | |
93 | } | |
94 | LOG.debug("[{}] apply service provider configuration", this); | |
95 | CloudhopperBuilder builder = msgBuilder.sms().sender(CloudhopperBuilder.class); | |
96 | // @formatter:off | |
97 | builder | |
98 | .userData() | |
99 | // both supported but to benefit from 160 characters messages, we have to use Tlv message_payload because GSM 7-bit is not supported | |
100 | .useShortMessage().defaultValue(false).and() | |
101 | .useTlvMessagePayload().defaultValue(true).and() | |
102 | .and() | |
103 | .encoder() | |
104 | .gsm7bitPacked().defaultValue(0).and() // not supported by SmsGlobal | |
105 | .latin1().defaultValue(0).and() // not supported by SmsGlobal | |
106 | .gsm8bit().defaultValue(DEFAULT_GSM8_ENCODING_PRIORITY).and() | |
107 | .ucs2().defaultValue(DEFAULT_UCS2_ENCODING_PRIORITY).and() | |
108 | .and() | |
109 | .dataCodingScheme() | |
110 | .custom(new SmsGlobalDataCodingProvider()) | |
111 | .and() | |
112 | .splitter() | |
113 | .enable().defaultValue(false).and() // do not split when using Tlv message_payload | |
114 | .and() | |
115 | .port().defaultValue(SMSGLOBAL_PORT).and() | |
116 | .interfaceVersion().defaultValue(VERSION_3_4); | |
117 | // @formatter:on | |
118 | } | |
119 | ||
120 | private static boolean usingSmsGlobal(PropertyResolver propertyResolver) { | |
121 | Boolean skip = evaluate(asList("${ogham.sms.smsglobal.service-provider.auto-conf.skip}"), propertyResolver, Boolean.class); | |
122 |
5
1. usingSmsGlobal : negated conditional → NO_COVERAGE 2. usingSmsGlobal : negated conditional → KILLED 3. usingSmsGlobal : negated conditional → KILLED 4. usingSmsGlobal : negated conditional → KILLED 5. usingSmsGlobal : negated conditional → KILLED |
if (skip != null && !skip) { |
123 |
1
1. usingSmsGlobal : replaced boolean return with true for fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::usingSmsGlobal → NO_COVERAGE |
return false; |
124 | } | |
125 | String host = evaluate(asList("${ogham.sms.cloudhopper.host}", "${ogham.sms.smpp.host}"), propertyResolver, String.class); | |
126 |
4
1. usingSmsGlobal : negated conditional → KILLED 2. usingSmsGlobal : negated conditional → KILLED 3. usingSmsGlobal : negated conditional → KILLED 4. usingSmsGlobal : negated conditional → KILLED |
if (SMSGLOBAL_HOST.equals(host)) { |
127 |
2
1. usingSmsGlobal : replaced boolean return with false for fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::usingSmsGlobal → NO_COVERAGE 2. usingSmsGlobal : replaced boolean return with false for fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::usingSmsGlobal → KILLED |
return true; |
128 | } | |
129 | Boolean force = evaluate("${ogham.sms.smsglobal.service-provider.auto-conf.force}", propertyResolver, Boolean.class); | |
130 |
10
1. usingSmsGlobal : negated conditional → NO_COVERAGE 2. usingSmsGlobal : replaced boolean return with true for fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::usingSmsGlobal → KILLED 3. usingSmsGlobal : replaced boolean return with true for fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::usingSmsGlobal → KILLED 4. usingSmsGlobal : replaced boolean return with true for fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::usingSmsGlobal → KILLED 5. usingSmsGlobal : replaced boolean return with true for fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::usingSmsGlobal → KILLED 6. usingSmsGlobal : negated conditional → KILLED 7. usingSmsGlobal : negated conditional → KILLED 8. usingSmsGlobal : negated conditional → KILLED 9. usingSmsGlobal : negated conditional → KILLED 10. usingSmsGlobal : negated conditional → KILLED |
return force != null && force; |
131 | } | |
132 | ||
133 | private static boolean canUseCloudhopper() { | |
134 |
3
1. canUseCloudhopper : replaced boolean return with false for fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::canUseCloudhopper → SURVIVED 2. canUseCloudhopper : replaced boolean return with true for fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::canUseCloudhopper → SURVIVED 3. canUseCloudhopper : replaced boolean return with false for fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::canUseCloudhopper → KILLED |
return ClasspathUtils.exists("com.cloudhopper.smpp.SmppClient"); |
135 | } | |
136 | } | |
137 | ||
138 | private SmsglobalServiceProviderConfigurer() { | |
139 | super(); | |
140 | } | |
141 | } | |
Mutations | ||
90 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
122 |
1.1 2.2 3.3 4.4 5.5 |
|
123 |
1.1 |
|
126 |
1.1 2.2 3.3 4.4 |
|
127 |
1.1 2.2 |
|
130 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 |
|
134 |
1.1 2.2 3.3 |