Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVEXP-:254 support undefined vs null detection for serialization #35

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.sinch.sdk.core.http.AuthManager;
import com.sinch.sdk.core.http.HttpClient;
import com.sinch.sdk.core.http.HttpMapper;
import com.sinch.sdk.core.models.OptionalValue;
import com.sinch.sdk.core.models.pagination.Page;
import com.sinch.sdk.core.models.pagination.TokenPageNavigator;
import com.sinch.sdk.core.utils.EnumDynamic;
Expand All @@ -24,7 +25,6 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

public class ActiveNumberService implements com.sinch.sdk.domains.numbers.ActiveNumberService {
Expand All @@ -49,10 +49,10 @@ private ActiveNumberApi getApi() {
public ActiveNumberListResponse list(ActiveNumberListRequestParameters parameters)
throws ApiException {

String regionCode = parameters.getRegionCode();
NumberType type = parameters.getType();
String regionCode = parameters.getRegionCode().get();
NumberType type = parameters.getType().get();

Optional<NumberPattern> pattern = parameters.getNumberPattern();
OptionalValue<NumberPattern> pattern = parameters.getNumberPattern();
String patternPattern = null;
SearchPattern searchPattern = null;
if (pattern.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.sinch.sdk.core.http.AuthManager;
import com.sinch.sdk.core.http.HttpClient;
import com.sinch.sdk.core.http.HttpMapper;
import com.sinch.sdk.core.models.OptionalValue;
import com.sinch.sdk.core.utils.EnumDynamic;
import com.sinch.sdk.domains.numbers.adapters.api.v1.AvailableNumberApi;
import com.sinch.sdk.domains.numbers.adapters.converters.ActiveNumberDtoConverter;
Expand All @@ -22,7 +23,6 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

public class AvailableNumberService
Expand All @@ -47,10 +47,10 @@ private AvailableNumberApi getApi() {

public AvailableNumberListResponse list(AvailableNumberListAllRequestParameters parameters)
throws ApiException {
String regionCode = parameters.getRegionCode();
NumberType type = parameters.getType();
String regionCode = parameters.getRegionCode().get();
NumberType type = parameters.getType().get();

Optional<NumberPattern> pattern = parameters.getNumberPattern();
OptionalValue<NumberPattern> pattern = parameters.getNumberPattern();
String patternPattern = null;
SearchPattern searchPattern = null;
if (pattern.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.sinch.sdk.domains.numbers.adapters.converters;

import com.sinch.sdk.core.models.OptionalValue;
import com.sinch.sdk.core.utils.EnumDynamic;
import com.sinch.sdk.domains.numbers.models.NumberPattern;
import com.sinch.sdk.domains.numbers.models.dto.v1.RentAnyNumberRequestDto;
import com.sinch.sdk.domains.numbers.models.dto.v1.RentAnyNumberRequestSmsConfigurationDto;
import com.sinch.sdk.domains.numbers.models.dto.v1.RentAnyNumberRequestVoiceConfigurationDto;
import com.sinch.sdk.domains.numbers.models.dto.v1.SearchPatternDto;
import com.sinch.sdk.domains.numbers.models.requests.AvailableNumberRentAnyRequestParameters;
import java.util.Optional;
import java.util.stream.Collectors;

public class AvailableRentAnyRequestParametersDtoConverter {
Expand All @@ -16,10 +16,10 @@ public static RentAnyNumberRequestDto convert(

RentAnyNumberRequestDto dto =
new RentAnyNumberRequestDto()
.regionCode(parameters.getRegionCode())
.type(parameters.getType().value());
.regionCode(parameters.getRegionCode().get())
.type(parameters.getType().get().value());

Optional<NumberPattern> pattern = parameters.getNumberPattern();
OptionalValue<NumberPattern> pattern = parameters.getNumberPattern();
if (pattern.isPresent()) {
NumberPattern p = pattern.get();
String patternPattern = p.getPattern();
Expand All @@ -36,22 +36,25 @@ public static RentAnyNumberRequestDto convert(
value ->
dto.capabilities(
value.stream().map(EnumDynamic::value).collect(Collectors.toList())));

parameters
.getSmsConfiguration()
.ifPresent(
value ->
dto.smsConfiguration(
new RentAnyNumberRequestSmsConfigurationDto()
.campaignId(value.getCampaignId().orElse(null))
.servicePlanId(value.getServicePlanId())));
value -> {
RentAnyNumberRequestSmsConfigurationDto config =
new RentAnyNumberRequestSmsConfigurationDto();
value.getServicePlanId().ifPresent(config::setServicePlanId);
value.getCampaignId().ifPresent(config::setCampaignId);
dto.smsConfiguration(config);
});
parameters
.getVoiceConfiguration()
.ifPresent(
value ->
dto.voiceConfiguration(
new RentAnyNumberRequestVoiceConfigurationDto().appId(value.getAppId())));

value -> {
RentAnyNumberRequestVoiceConfigurationDto config =
new RentAnyNumberRequestVoiceConfigurationDto();
value.getAppId().ifPresent(config::setAppId);
dto.voiceConfiguration(config);
});
parameters.getCallBackUrl().ifPresent(dto::callbackUrl);
return dto;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
package com.sinch.sdk.domains.numbers.adapters.converters;

import com.sinch.sdk.core.models.OptionalValue;
import com.sinch.sdk.domains.numbers.models.dto.v1.RentAnyNumberRequestSmsConfigurationDto;
import com.sinch.sdk.domains.numbers.models.dto.v1.RentAnyNumberRequestVoiceConfigurationDto;
import com.sinch.sdk.domains.numbers.models.dto.v1.RentNumberRequestDto;
import com.sinch.sdk.domains.numbers.models.requests.AvailableNumberRentRequestParameters;
import com.sinch.sdk.domains.numbers.models.requests.RentSMSConfigurationRequestParameters;
import com.sinch.sdk.domains.numbers.models.requests.RentVoiceConfigurationRequestParameters;
import java.util.Optional;

public class AvailableRentRequestParametersDtoConverter {

public static RentNumberRequestDto convert(AvailableNumberRentRequestParameters parameters) {

Optional<RentSMSConfigurationRequestParameters> sms = parameters.getSmsConfiguration();
Optional<RentVoiceConfigurationRequestParameters> voice = parameters.getVoiceConfiguration();
Optional<String> callbackUrl = parameters.getCallBackUrl();
OptionalValue<RentSMSConfigurationRequestParameters> sms = parameters.getSmsConfiguration();
OptionalValue<RentVoiceConfigurationRequestParameters> voice =
parameters.getVoiceConfiguration();
OptionalValue<String> callbackUrl = parameters.getCallBackUrl();

RentNumberRequestDto dto = new RentNumberRequestDto();

sms.ifPresent(
value ->
dto.smsConfiguration(
new RentAnyNumberRequestSmsConfigurationDto()
.campaignId(value.getCampaignId().orElse(null))
.servicePlanId(value.getServicePlanId())));
value -> {
RentAnyNumberRequestSmsConfigurationDto config =
new RentAnyNumberRequestSmsConfigurationDto();
value.getServicePlanId().ifPresent(config::setServicePlanId);
value.getCampaignId().ifPresent(config::setCampaignId);
dto.smsConfiguration(config);
});

voice.ifPresent(
value ->
dto.voiceConfiguration(
new RentAnyNumberRequestVoiceConfigurationDto().appId(value.getAppId())));
value -> {
RentAnyNumberRequestVoiceConfigurationDto config =
new RentAnyNumberRequestVoiceConfigurationDto();
value.getAppId().ifPresent(config::setAppId);
dto.voiceConfiguration(config);
});

callbackUrl.ifPresent(dto::callbackUrl);
return dto;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public static CallbackConfigurationUpdateDto convert(
if (null == parameters) {
return null;
}
return new CallbackConfigurationUpdateDto().hmacSecret(parameters.getHMACSecret());
CallbackConfigurationUpdateDto dto = new CallbackConfigurationUpdateDto();
parameters.getHMACSecret().ifPresent(dto::hmacSecret);
return dto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static SMSConfigurationDto convert(
return null;
}
SMSConfigurationDto dto = new SMSConfigurationDto();
dto.servicePlanId(configuration.getServicePlanId());
configuration.getServicePlanId().ifPresent(dto::servicePlanId);
configuration.getCampaignId().ifPresent(dto::campaignId);
return dto;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static VoiceConfigurationDto convert(
return null;
}

return new VoiceConfigurationDto().appId(configuration.getAppId());
VoiceConfigurationDto dto = new VoiceConfigurationDto();
configuration.getAppId().ifPresent(dto::appId);
return dto;
}
}
Loading
Loading