Skip to content

Commit

Permalink
Merge pull request #6 from sinch/code-formatter
Browse files Browse the repository at this point in the history
style: back to google code formatter style
JPPortier authored Jun 18, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 0e8eba7 + bff8c59 commit 6122c85
Showing 16 changed files with 349 additions and 363 deletions.
1 change: 0 additions & 1 deletion pom-ci.xml
Original file line number Diff line number Diff line change
@@ -36,7 +36,6 @@

<googleJavaFormat>
<version>1.22.0</version>
<style>AOSP</style>
<reflowLongStrings>true</reflowLongStrings>
</googleJavaFormat>
<endWithNewline />
96 changes: 47 additions & 49 deletions templates/client/src/main/java/Application.java
Original file line number Diff line number Diff line change
@@ -10,65 +10,63 @@

public abstract class Application {

private static final String LOGGING_PROPERTIES_FILE = "logging.properties";
private static final Logger LOGGER = initializeLogger();
private static final String LOGGING_PROPERTIES_FILE = "logging.properties";
private static final Logger LOGGER = initializeLogger();

public static void main(String[] args) {
try {
public static void main(String[] args) {
try {

SinchClient client = SinchClientHelper.initSinchClient();
LOGGER.info("Application initiated. SinchClient ready.");
SinchClient client = SinchClientHelper.initSinchClient();
LOGGER.info("Application initiated. SinchClient ready.");

// Numbers service dedicated business logic processing
// (see https://developers.sinch.com/categories/numbersandconnectivity)
// comment if unused
if (client.getConfiguration().getUnifiedCredentials().isPresent()) {
NumbersQuickStart numbers = new NumbersQuickStart(client.numbers());
}
// Numbers service dedicated business logic processing
// (see https://developers.sinch.com/categories/numbersandconnectivity)
// comment if unused
if (client.getConfiguration().getUnifiedCredentials().isPresent()) {
NumbersQuickStart numbers = new NumbersQuickStart(client.numbers());
}

// SMS service dedicated business logic processing
// (see https://developers.sinch.com/docs/sms)
// comment if unused
if (client.getConfiguration().getSmsServicePlanCredentials().isPresent()
|| client.getConfiguration().getUnifiedCredentials().isPresent()) {
SmsQuickStart sms = new SmsQuickStart(client.sms());
}
// SMS service dedicated business logic processing
// (see https://developers.sinch.com/docs/sms)
// comment if unused
if (client.getConfiguration().getSmsServicePlanCredentials().isPresent()
|| client.getConfiguration().getUnifiedCredentials().isPresent()) {
SmsQuickStart sms = new SmsQuickStart(client.sms());
}

// Verification service dedicated business logic processing
// (see https://developers.sinch.com/docs/verification)
// comment if unused
if (client.getConfiguration().getApplicationCredentials().isPresent()) {
VerificationQuickStart verification =
new VerificationQuickStart(client.verification());
}
// Verification service dedicated business logic processing
// (see https://developers.sinch.com/docs/verification)
// comment if unused
if (client.getConfiguration().getApplicationCredentials().isPresent()) {
VerificationQuickStart verification = new VerificationQuickStart(client.verification());
}

// Voice service dedicated business logic processing
// (see https://developers.sinch.com/docs/voice)
// comment if unused
if (client.getConfiguration().getApplicationCredentials().isPresent()) {
VoiceQuickStart voice = new VoiceQuickStart(client.voice());
}
// Voice service dedicated business logic processing
// (see https://developers.sinch.com/docs/voice)
// comment if unused
if (client.getConfiguration().getApplicationCredentials().isPresent()) {
VoiceQuickStart voice = new VoiceQuickStart(client.voice());
}

} catch (Exception e) {
LOGGER.severe(String.format("Application failure: %s", e.getMessage()));
}
} catch (Exception e) {
LOGGER.severe(String.format("Application failure: %s", e.getMessage()));
}
}

static Logger initializeLogger() {
try (InputStream logConfigInputStream =
Application.class.getClassLoader().getResourceAsStream(LOGGING_PROPERTIES_FILE)) {
static Logger initializeLogger() {
try (InputStream logConfigInputStream =
Application.class.getClassLoader().getResourceAsStream(LOGGING_PROPERTIES_FILE)) {

if (logConfigInputStream != null) {
LogManager.getLogManager().readConfiguration(logConfigInputStream);
} else {
throw new RuntimeException(
String.format(
"The file '%s' couldn't be loaded.", LOGGING_PROPERTIES_FILE));
}
if (logConfigInputStream != null) {
LogManager.getLogManager().readConfiguration(logConfigInputStream);
} else {
throw new RuntimeException(
String.format("The file '%s' couldn't be loaded.", LOGGING_PROPERTIES_FILE));
}

} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
return Logger.getLogger(Application.class.getName());
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
return Logger.getLogger(Application.class.getName());
}
}
136 changes: 67 additions & 69 deletions templates/client/src/main/java/SinchClientHelper.java
Original file line number Diff line number Diff line change
@@ -9,103 +9,101 @@

public class SinchClientHelper {

private static final Logger LOGGER = Logger.getLogger(SinchClientHelper.class.getName());
private static final Logger LOGGER = Logger.getLogger(SinchClientHelper.class.getName());

private static final String SINCH_PROJECT_ID = "SINCH_PROJECT_ID";
private static final String SINCH_KEY_ID = "SINCH_KEY_ID";
private static final String SINCH_KEY_SECRET = "SINCH_KEY_SECRET";
private static final String SINCH_PROJECT_ID = "SINCH_PROJECT_ID";
private static final String SINCH_KEY_ID = "SINCH_KEY_ID";
private static final String SINCH_KEY_SECRET = "SINCH_KEY_SECRET";

private static final String APPLICATION_API_KEY = "APPLICATION_API_KEY";
private static final String APPLICATION_API_SECRET = "APPLICATION_API_SECRET";
private static final String APPLICATION_API_KEY = "APPLICATION_API_KEY";
private static final String APPLICATION_API_SECRET = "APPLICATION_API_SECRET";

private static final String SMS_SERVICE_PLAN_ID = "SMS_SERVICE_PLAN_ID";
private static final String SMS_SERVICE_PLAN_TOKEN = "SMS_SERVICE_PLAN_TOKEN";
private static final String SMS_REGION = "SMS_REGION";
private static final String SMS_SERVICE_PLAN_ID = "SMS_SERVICE_PLAN_ID";
private static final String SMS_SERVICE_PLAN_TOKEN = "SMS_SERVICE_PLAN_TOKEN";
private static final String SMS_REGION = "SMS_REGION";

private static final String CONFIG_FILE = "config.properties";
private static final String CONFIG_FILE = "config.properties";

public static SinchClient initSinchClient() {
public static SinchClient initSinchClient() {

LOGGER.info("Initializing client");
LOGGER.info("Initializing client");

Configuration configuration = getConfiguration();
Configuration configuration = getConfiguration();

return new SinchClient(configuration);
}

private static Configuration getConfiguration() {
return new SinchClient(configuration);
}

Properties properties = loadProperties();
private static Configuration getConfiguration() {

Configuration.Builder builder = Configuration.builder();
Properties properties = loadProperties();

manageUnifiedCredentials(properties, builder);
manageApplicationCredentials(properties, builder);
manageSmsConfiguration(properties, builder);
Configuration.Builder builder = Configuration.builder();

return builder.build();
}
manageUnifiedCredentials(properties, builder);
manageApplicationCredentials(properties, builder);
manageSmsConfiguration(properties, builder);

private static Properties loadProperties() {
return builder.build();
}

Properties properties = new Properties();
private static Properties loadProperties() {

try (InputStream input =
SinchClientHelper.class.getClassLoader().getResourceAsStream(CONFIG_FILE)) {
if (input != null) {
properties.load(input);
} else {
LOGGER.severe(String.format("'%s' file could not be loaded", CONFIG_FILE));
}
} catch (IOException e) {
LOGGER.severe(String.format("Error loading properties from '%s'", CONFIG_FILE));
}
Properties properties = new Properties();

return properties;
try (InputStream input =
SinchClientHelper.class.getClassLoader().getResourceAsStream(CONFIG_FILE)) {
if (input != null) {
properties.load(input);
} else {
LOGGER.severe(String.format("'%s' file could not be loaded", CONFIG_FILE));
}
} catch (IOException e) {
LOGGER.severe(String.format("Error loading properties from '%s'", CONFIG_FILE));
}

static void manageUnifiedCredentials(Properties properties, Configuration.Builder builder) {
return properties;
}

Optional<String> projectId = getConfigValue(properties, SINCH_PROJECT_ID);
Optional<String> keyId = getConfigValue(properties, SINCH_KEY_ID);
Optional<String> keySecret = getConfigValue(properties, SINCH_KEY_SECRET);
static void manageUnifiedCredentials(Properties properties, Configuration.Builder builder) {

projectId.ifPresent(builder::setProjectId);
keyId.ifPresent(builder::setKeyId);
keySecret.ifPresent(builder::setKeySecret);
}
Optional<String> projectId = getConfigValue(properties, SINCH_PROJECT_ID);
Optional<String> keyId = getConfigValue(properties, SINCH_KEY_ID);
Optional<String> keySecret = getConfigValue(properties, SINCH_KEY_SECRET);

private static void manageApplicationCredentials(
Properties properties, Configuration.Builder builder) {
projectId.ifPresent(builder::setProjectId);
keyId.ifPresent(builder::setKeyId);
keySecret.ifPresent(builder::setKeySecret);
}

Optional<String> verificationApiKey = getConfigValue(properties, APPLICATION_API_KEY);
Optional<String> verificationApiSecret = getConfigValue(properties, APPLICATION_API_SECRET);
private static void manageApplicationCredentials(
Properties properties, Configuration.Builder builder) {

verificationApiKey.ifPresent(builder::setApplicationKey);
verificationApiSecret.ifPresent(builder::setApplicationSecret);
}
Optional<String> verificationApiKey = getConfigValue(properties, APPLICATION_API_KEY);
Optional<String> verificationApiSecret = getConfigValue(properties, APPLICATION_API_SECRET);

private static void manageSmsConfiguration(
Properties properties, Configuration.Builder builder) {
verificationApiKey.ifPresent(builder::setApplicationKey);
verificationApiSecret.ifPresent(builder::setApplicationSecret);
}

Optional<String> servicePlanId = getConfigValue(properties, SMS_SERVICE_PLAN_ID);
Optional<String> servicePlanToken = getConfigValue(properties, SMS_SERVICE_PLAN_TOKEN);
Optional<String> region = getConfigValue(properties, SMS_REGION);
private static void manageSmsConfiguration(Properties properties, Configuration.Builder builder) {

servicePlanId.ifPresent(builder::setSmsServicePlanId);
servicePlanToken.ifPresent(builder::setSmsApiToken);
region.ifPresent(value -> builder.setSmsRegion(SMSRegion.from(value)));
}
Optional<String> servicePlanId = getConfigValue(properties, SMS_SERVICE_PLAN_ID);
Optional<String> servicePlanToken = getConfigValue(properties, SMS_SERVICE_PLAN_TOKEN);
Optional<String> region = getConfigValue(properties, SMS_REGION);

private static Optional<String> getConfigValue(Properties properties, String key) {
String value =
null != System.getenv(key) ? System.getenv(key) : properties.getProperty(key);
servicePlanId.ifPresent(builder::setSmsServicePlanId);
servicePlanToken.ifPresent(builder::setSmsApiToken);
region.ifPresent(value -> builder.setSmsRegion(SMSRegion.from(value)));
}

// empty value means setting not set
if (null != value && value.trim().isEmpty()) {
return Optional.empty();
}
private static Optional<String> getConfigValue(Properties properties, String key) {
String value = null != System.getenv(key) ? System.getenv(key) : properties.getProperty(key);

return Optional.ofNullable(value);
// empty value means setting not set
if (null != value && value.trim().isEmpty()) {
return Optional.empty();
}

return Optional.ofNullable(value);
}
}
12 changes: 6 additions & 6 deletions templates/client/src/main/java/numbers/NumbersQuickStart.java
Original file line number Diff line number Diff line change
@@ -4,12 +4,12 @@

public class NumbersQuickStart {

private final NumbersService numbersService;
private final NumbersService numbersService;

public NumbersQuickStart(NumbersService numbersService) {
this.numbersService = numbersService;
public NumbersQuickStart(NumbersService numbersService) {
this.numbersService = numbersService;

// replace by your code and business logic
Snippet.execute(this.numbersService);
}
// replace by your code and business logic
Snippet.execute(this.numbersService);
}
}
8 changes: 4 additions & 4 deletions templates/client/src/main/java/numbers/Snippet.java
Original file line number Diff line number Diff line change
@@ -5,10 +5,10 @@

public class Snippet {

private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName());
private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName());

static void execute(NumbersService numbersService) {
static void execute(NumbersService numbersService) {

LOGGER.info("Snippet execution");
}
LOGGER.info("Snippet execution");
}
}
12 changes: 6 additions & 6 deletions templates/client/src/main/java/sms/SmsQuickStart.java
Original file line number Diff line number Diff line change
@@ -4,12 +4,12 @@

public class SmsQuickStart {

private final SMSService smsService;
private final SMSService smsService;

public SmsQuickStart(SMSService smsService) {
this.smsService = smsService;
public SmsQuickStart(SMSService smsService) {
this.smsService = smsService;

// replace by your code and business logic
Snippet.execute(this.smsService);
}
// replace by your code and business logic
Snippet.execute(this.smsService);
}
}
8 changes: 4 additions & 4 deletions templates/client/src/main/java/sms/Snippet.java
Original file line number Diff line number Diff line change
@@ -5,10 +5,10 @@

public class Snippet {

private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName());
private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName());

static void execute(SMSService smsService) {
static void execute(SMSService smsService) {

LOGGER.info("Snippet execution");
}
LOGGER.info("Snippet execution");
}
}
8 changes: 4 additions & 4 deletions templates/client/src/main/java/verification/Snippet.java
Original file line number Diff line number Diff line change
@@ -5,10 +5,10 @@

public class Snippet {

private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName());
private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName());

static void execute(VerificationService verificationService) {
static void execute(VerificationService verificationService) {

LOGGER.info("Snippet execution");
}
LOGGER.info("Snippet execution");
}
}
Original file line number Diff line number Diff line change
@@ -4,12 +4,12 @@

public class VerificationQuickStart {

private final VerificationService verificationService;
private final VerificationService verificationService;

public VerificationQuickStart(VerificationService verificationService) {
this.verificationService = verificationService;
public VerificationQuickStart(VerificationService verificationService) {
this.verificationService = verificationService;

// replace by your code and business logic
Snippet.execute(this.verificationService);
}
// replace by your code and business logic
Snippet.execute(this.verificationService);
}
}
Loading

0 comments on commit 6122c85

Please sign in to comment.