| 1 | package fr.sii.ogham.spring.sms; | |
| 2 | ||
| 3 | import static fr.sii.ogham.core.util.ConfigurationValueUtils.firstValue; | |
| 4 | import static fr.sii.ogham.spring.util.PropertiesUtils.asArray; | |
| 5 | import static java.util.Optional.ofNullable; | |
| 6 | ||
| 7 | import org.slf4j.Logger; | |
| 8 | import org.slf4j.LoggerFactory; | |
| 9 | ||
| 10 | import fr.sii.ogham.core.builder.MessagingBuilder; | |
| 11 | import fr.sii.ogham.sms.CloudhopperConstants; | |
| 12 | import fr.sii.ogham.sms.builder.cloudhopper.CloudhopperBuilder; | |
| 13 | import fr.sii.ogham.sms.builder.cloudhopper.InterfaceVersion; | |
| 14 | import fr.sii.ogham.spring.common.SpringMessagingConfigurer; | |
| 15 | ||
| 16 | /** | |
| 17 | * This configurer is useful to support property naming variants (see | |
| 18 | * <a href= | |
| 19 | * "https://github.com/spring-projects/spring-boot/wiki/relaxed-binding-2.0">Relaxed | |
| 20 | * Binding</a>). | |
| 21 | * | |
| 22 | * @author Aurélien Baudet | |
| 23 | * | |
| 24 | */ | |
| 25 | public class SpringCloudhopperConfigurer implements SpringMessagingConfigurer { | |
| 26 | private static final Logger LOG = LoggerFactory.getLogger(SpringCloudhopperConfigurer.class); | |
| 27 | ||
| 28 | private final OghamSmsProperties smsProperties; | |
| 29 | private final OghamSmppProperties smppProperties; | |
| 30 | private final OghamCloudhopperProperties cloudhopperProperties; | |
| 31 | ||
| 32 | ||
| 33 | public SpringCloudhopperConfigurer(OghamSmsProperties smsProperties, OghamSmppProperties smppProperties, OghamCloudhopperProperties cloudhopperProperties) { | |
| 34 | super(); | |
| 35 |
1
1. <init> : negated conditional → SURVIVED |
this.smsProperties = smsProperties != null ? smsProperties : new OghamSmsProperties(); |
| 36 |
1
1. <init> : negated conditional → SURVIVED |
this.smppProperties = smppProperties != null ? smppProperties : new OghamSmppProperties(); |
| 37 |
1
1. <init> : negated conditional → SURVIVED |
this.cloudhopperProperties = cloudhopperProperties != null ? cloudhopperProperties : new OghamCloudhopperProperties(); |
| 38 | } | |
| 39 | ||
| 40 | @Override | |
| 41 | public void configure(MessagingBuilder builder) { | |
| 42 | LOG.debug("[{}] apply Cloudhopper configuration properties to {}", this, builder); | |
| 43 | // @formatter:off | |
| 44 | builder.sms() | |
| 45 | .sender(CloudhopperBuilder.class) | |
| 46 | .systemId().value(ofNullable(firstValue(cloudhopperProperties.getSystemId(), smppProperties.getSystemId()))).and() | |
| 47 | .password().value(ofNullable(firstValue(cloudhopperProperties.getPassword(), smppProperties.getPassword()))).and() | |
| 48 | .host().value(ofNullable(firstValue(cloudhopperProperties.getHost(), smppProperties.getHost()))).and() | |
| 49 | .port().value(ofNullable(firstValue(cloudhopperProperties.getPort(), smppProperties.getPort()))).and() | |
| 50 | .bindType().value(ofNullable(firstValue(cloudhopperProperties.getBindType(), smppProperties.getBindType()))).and() | |
| 51 | .systemType().value(ofNullable(firstValue(cloudhopperProperties.getSystemType(), smppProperties.getSystemType()))).and() | |
| 52 | .interfaceVersion().value(ofNullable(InterfaceVersion.of(cloudhopperProperties.getInterfaceVersion()))).and() | |
| 53 | .userData() | |
| 54 | .useShortMessage().value(ofNullable(firstValue(cloudhopperProperties.getUserData().getUseShortMessage(), smppProperties.getUserData().getUseShortMessage()))).and() | |
| 55 | .useTlvMessagePayload().value(ofNullable(firstValue(cloudhopperProperties.getUserData().getUseTlvMessagePayload(), smppProperties.getUserData().getUseTlvMessagePayload()))).and() | |
| 56 | .and() | |
| 57 | .encoder() | |
| 58 | .gsm7bitPacked().value(ofNullable(firstValue(cloudhopperProperties.getEncoder().getGsm7bitPacked().getPriority(), smppProperties.getEncoder().getGsm7bitPacked().getPriority()))).and() | |
| 59 | .gsm8bit().value(ofNullable(firstValue(cloudhopperProperties.getEncoder().getGsm8bit().getPriority(), smppProperties.getEncoder().getGsm8bit().getPriority()))).and() | |
| 60 | .latin1().value(ofNullable(firstValue(cloudhopperProperties.getEncoder().getLatin1().getPriority(), smppProperties.getEncoder().getLatin1().getPriority()))).and() | |
| 61 | .ucs2().value(ofNullable(firstValue(cloudhopperProperties.getEncoder().getUcs2().getPriority(), smppProperties.getEncoder().getUcs2().getPriority()))).and() | |
| 62 | .autoGuess().value(ofNullable(firstValue(cloudhopperProperties.getEncoder().getAutoGuess().getEnable(), smppProperties.getEncoder().getAutoGuess().getEnable()))).and() | |
| 63 | .fallback().value(ofNullable(firstValue(cloudhopperProperties.getEncoder().getDefaultCharset(), smppProperties.getEncoder().getDefaultCharset()))).and() | |
| 64 | .and() | |
| 65 | .splitter() | |
| 66 | .enable().value(ofNullable(firstValue(cloudhopperProperties.getSplit().getEnable(), smppProperties.getSplit().getEnable(), smsProperties.getSplit().getEnable()))).and() | |
| 67 | .and() | |
| 68 | .dataCodingScheme() | |
| 69 | .auto().value(ofNullable(firstValue(cloudhopperProperties.getDataCodingScheme().getAuto().getEnable(), smppProperties.getDataCodingScheme().getAuto().getEnable()))).and() | |
| 70 | .value().value(ofNullable(firstValue(cloudhopperProperties.getDataCodingScheme().getValue(), smppProperties.getDataCodingScheme().getValue()))).and() | |
| 71 | .and() | |
| 72 | .session() | |
| 73 | .sessionName().value(ofNullable(cloudhopperProperties.getSession().getName())).and() | |
| 74 | .bindTimeout().value(ofNullable(cloudhopperProperties.getSession().getBindTimeout())).and() | |
| 75 | .connectTimeout().value(ofNullable(cloudhopperProperties.getSession().getConnectTimeout())).and() | |
| 76 | .requestExpiryTimeout().value(ofNullable(cloudhopperProperties.getSession().getRequestExpiryTimeout())).and() | |
| 77 | .windowMonitorInterval().value(ofNullable(cloudhopperProperties.getSession().getWindowMonitorInterval())).and() | |
| 78 | .windowSize().value(ofNullable(cloudhopperProperties.getSession().getWindowSize())).and() | |
| 79 | .windowWait().value(ofNullable(cloudhopperProperties.getSession().getWindowWaitTimeout())).and() | |
| 80 | .writeTimeout().value(ofNullable(cloudhopperProperties.getSession().getWriteTimeout())).and() | |
| 81 | .responseTimeout().value(ofNullable(cloudhopperProperties.getSession().getResponseTimeout())).and() | |
| 82 | .unbindTimeout().value(ofNullable(cloudhopperProperties.getSession().getUnbindTimeout())).and() | |
| 83 | .reuseSession() | |
| 84 | .enable().value(ofNullable(cloudhopperProperties.getSession().getReuseSession().getEnable())).and() | |
| 85 | .lastInteractionExpiration().value(ofNullable(cloudhopperProperties.getSession().getReuseSession().getLastInteractionExpirationDelay())).and() | |
| 86 | .responseTimeout().value(ofNullable(cloudhopperProperties.getSession().getReuseSession().getResponseTimeout())).and() | |
| 87 | .and() | |
| 88 | .keepAlive() | |
| 89 | .enable().value(ofNullable(cloudhopperProperties.getSession().getKeepAlive().getEnable())).and() | |
| 90 | .interval().value(ofNullable(cloudhopperProperties.getSession().getKeepAlive().getRequestInterval())).and() | |
| 91 | .responseTimeout().value(ofNullable(cloudhopperProperties.getSession().getKeepAlive().getResponseTimeout())).and() | |
| 92 | .connectAtStartup().value(ofNullable(cloudhopperProperties.getSession().getKeepAlive().getConnectAtStartup())).and() | |
| 93 | .maxConsecutiveTimeouts().value(ofNullable(cloudhopperProperties.getSession().getKeepAlive().getMaxConsecutiveTimeouts())).and() | |
| 94 | .and() | |
| 95 | .connectRetry() | |
| 96 | .fixedDelay() | |
| 97 | .maxRetries().value(ofNullable(cloudhopperProperties.getSession().getConnectRetry().getMaxAttempts())).and() | |
| 98 | .delay().value(ofNullable(cloudhopperProperties.getSession().getConnectRetry().getDelayBetweenAttempts())).and() | |
| 99 | .and() | |
| 100 | .exponentialDelay() | |
| 101 | .maxRetries().value(ofNullable(cloudhopperProperties.getSession().getConnectRetry().getMaxAttempts())).and() | |
| 102 | .initialDelay().value(ofNullable(cloudhopperProperties.getSession().getConnectRetry().getExponentialInitialDelay())).and() | |
| 103 | .and() | |
| 104 | .perExecutionDelay() | |
| 105 | .maxRetries().value(ofNullable(cloudhopperProperties.getSession().getConnectRetry().getMaxAttempts())).and() | |
| 106 | .delays().value(ofNullable(asArray(cloudhopperProperties.getSession().getConnectRetry().getPerExecutionDelays(), Long.class))).and() | |
| 107 | .and() | |
| 108 | .fixedInterval() | |
| 109 | .maxRetries().value(ofNullable(cloudhopperProperties.getSession().getConnectRetry().getMaxAttempts())).and() | |
| 110 | .interval().value(ofNullable(cloudhopperProperties.getSession().getConnectRetry().getExecutionInterval())); | |
| 111 | // @formatter:on | |
| 112 | } | |
| 113 | ||
| 114 | @Override | |
| 115 | public int getOrder() { | |
| 116 |
1
1. getOrder : replaced int return with 0 for fr/sii/ogham/spring/sms/SpringCloudhopperConfigurer::getOrder → SURVIVED |
return CloudhopperConstants.DEFAULT_CLOUDHOPPER_CONFIGURER_PRIORITY + 1000; |
| 117 | } | |
| 118 | ||
| 119 | } | |
Mutations | ||
| 35 |
1.1 |
|
| 36 |
1.1 |
|
| 37 |
1.1 |
|
| 116 |
1.1 |