Skip to content

Commit

Permalink
Merge branch 'hotfix/0.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Xie committed Dec 28, 2018
2 parents 3b68833 + fcfb4cc commit 1a7543c
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.57blocks</groupId>
<artifactId>sms-spring-boot</artifactId>
<version>0.1.1</version>
<version>0.1.2</version>
<packaging>pom</packaging>

<name>sms-spring-boot</name>
Expand Down
2 changes: 1 addition & 1 deletion sms-spring-boot-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>io.57blocks</groupId>
<artifactId>sms-spring-boot</artifactId>
<version>0.1.1</version>
<version>0.1.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions sms-spring-boot-example/twilio-sms-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>io.57blocks</groupId>
<artifactId>sms-spring-boot-example</artifactId>
<version>0.1.1</version>
<version>0.1.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand All @@ -23,7 +23,7 @@
<dependency>
<groupId>io.57blocks</groupId>
<artifactId>sms-spring-boot-starter</artifactId>
<version>0.1.1</version>
<version>0.1.2</version>
</dependency>
<dependency>
<groupId>io.57blocks</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public GreetingService(SmsService smsService) {
}

public void sendMessage() {
this.smsService.send("+12056357762", "+13882201684", "greeting", Locale.ENGLISH,
this.smsService.send("+1234567890", "+987654321", "greeting", Locale.ENGLISH,
new Object[]{"Mr. Smith"});
}

Expand Down
2 changes: 1 addition & 1 deletion sms-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>io.57blocks</groupId>
<version>0.1.1</version>
<version>0.1.2</version>
<artifactId>sms-spring-boot-starter</artifactId>
<packaging>jar</packaging>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,19 @@
package io._57blocks.sms.config;

import io._57blocks.sms.DummySmsService;
import io._57blocks.sms.SmsService;
import io._57blocks.sms.config.properties.SmsServiceProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;

@Configuration
@ConditionalOnClass(SmsService.class)
@EnableConfigurationProperties(SmsServiceProperties.class)
public abstract class AbstractSmsServiceAutoConfig {
abstract class AbstractSmsServiceAutoConfig {

@Autowired
private SmsServiceProperties properties;

protected ResourceBundleMessageSource smsMessageSource() {
ResourceBundleMessageSource smsMessageSource() {
final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename(properties.getMessageBaseName());

return messageSource;
}

@Bean
@ConditionalOnMissingBean
public SmsService smsService() {
if (properties.getEnabled()) {
return createSmsService();
} else {
return new DummySmsService();
}
}

protected abstract SmsService createSmsService();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io._57blocks.sms.config;

import io._57blocks.sms.DummySmsService;
import io._57blocks.sms.SmsService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(SmsService.class)
@ConditionalOnProperty(prefix = "io.57blocks.sms", value = "enabled", havingValue = "false")
public class DummySmsServiceAutoConfig {

@Bean
@ConditionalOnMissingBean
public SmsService smsService() {
return new DummySmsService();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

import io._57blocks.sms.SmsService;
import io._57blocks.sms.SmsServiceTwilioImpl;
import io._57blocks.sms.config.properties.SmsServiceProperties;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(SmsServiceProperties.class)
@ConditionalOnMissingBean(SmsService.class)
@ConditionalOnBean(type = "com.twilio.http.TwilioRestClient")
@AutoConfigureAfter(name = "io._57blocks.twilio.config.TwilioAutoConfig")
@AutoConfigureAfter(name = "io._57blocks.twilio.config.TwilioAutoConfig", value = DummySmsServiceAutoConfig.class)
public class SmsServiceTwilioAutoConfig extends AbstractSmsServiceAutoConfig {

@Override
protected SmsService createSmsService() {
@Bean
public SmsService smsService() {
return new SmsServiceTwilioImpl(smsMessageSource());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ public class SmsServiceProperties {

private Boolean enabled = Boolean.TRUE;
private String messageBaseName = "/sms/messages";

public String getMessageBaseName() {
if (messageBaseName.startsWith("/")) {
messageBaseName = messageBaseName.substring(1);
}

return messageBaseName;
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=io._57blocks.sms.config.SmsServiceTwilioAutoConfig
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
io._57blocks.sms.config.DummySmsServiceAutoConfig,\
io._57blocks.sms.config.SmsServiceTwilioAutoConfig

0 comments on commit 1a7543c

Please sign in to comment.