Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JPPortier committed Jan 31, 2024
1 parent 80dbefc commit 71f5bb2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.sinch.sdk.domains.voice.models.Destination;
import com.sinch.sdk.domains.voice.models.DestinationNumber;
import com.sinch.sdk.domains.voice.models.DestinationNumber.TYPE;
import com.sinch.sdk.domains.voice.models.DestinationNumberType;
import com.sinch.sdk.domains.voice.models.DestinationSip;
import com.sinch.sdk.domains.voice.models.DestinationUser;
import com.sinch.sdk.domains.voice.models.dto.v1.DestinationDto;
Expand All @@ -12,6 +12,7 @@
import java.util.logging.Logger;

public class DestinationDtoConverter {

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

public static DestinationDto convert(Destination client) {
Expand All @@ -23,16 +24,14 @@ public static DestinationDto convert(Destination client) {
String endpoint = null;
if (client instanceof DestinationNumber) {
DestinationNumber destination = (DestinationNumber) client;
switch (destination.getType()) {
case DID:
type = DestinationTypeDto.DID;
break;
case PSTN:
type = DestinationTypeDto.NUMBER;
break;
default:
LOGGER.severe(String.format("Unexpected type '%s'", destination.getType()));
return dto;
DestinationNumberType clientType = destination.getType();
if (clientType == DestinationNumberType.DID) {
type = DestinationTypeDto.DID;
} else if (clientType == DestinationNumberType.PSTN) {
type = DestinationTypeDto.NUMBER;
} else {
LOGGER.severe(String.format("Unexpected type '%s'", destination.getType()));
return dto;
}
endpoint = destination.getPhoneNumber().stringValue();
} else if (client instanceof DestinationUser) {
Expand All @@ -59,14 +58,18 @@ public static Destination convert(DestinationDto dto) {
Destination destination = null;
if (Objects.equals(dto.getType(), DestinationTypeDto.NUMBER)
|| Objects.equals(dto.getType(), DestinationTypeDto.NUMBER2)) {
destination = new DestinationNumber(E164PhoneNumber.valueOf(dto.getEndpoint()), TYPE.PSTN);
destination =
new DestinationNumber(
E164PhoneNumber.valueOf(dto.getEndpoint()), DestinationNumberType.PSTN);
} else if (Objects.equals(dto.getType(), DestinationTypeDto.USERNAME)
|| Objects.equals(dto.getType(), DestinationTypeDto.USERNAME2)) {
destination = new DestinationUser(dto.getEndpoint());
} else if (Objects.equals(dto.getType(), DestinationTypeDto.SIP)) {
destination = new DestinationSip(dto.getEndpoint());
} else if (Objects.equals(dto.getType(), DestinationTypeDto.DID)) {
destination = new DestinationNumber(E164PhoneNumber.valueOf(dto.getEndpoint()), TYPE.DID);
destination =
new DestinationNumber(
E164PhoneNumber.valueOf(dto.getEndpoint()), DestinationNumberType.DID);
} else {
LOGGER.severe(String.format("Unexpected type value '%s'", dto.getType()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
import com.sinch.sdk.models.E164PhoneNumber;
import java.util.Objects;

/** Destination of type numbers for PSTN endpoints */
/** Destination of numbers type */
public class DestinationNumber extends Destination {

private final E164PhoneNumber phoneNumber;
private final TYPE type;
private final DestinationNumberType type;

/**
* Create e destination instance of type PSTN
* Create a destination instance of type PSTN
*
* @param phoneNumber Valid E164 phone number
*/
public DestinationNumber(E164PhoneNumber phoneNumber) {
this(phoneNumber, TYPE.PSTN);
this(phoneNumber, DestinationNumberType.PSTN);
}

/**
* Create e destination instance of specified type
* Create a destination instance of specified type
*
* @param phoneNumber Valid E164 phone number
* @param type Phone number type
*/
public DestinationNumber(E164PhoneNumber phoneNumber, TYPE type) {
public DestinationNumber(E164PhoneNumber phoneNumber, DestinationNumberType type) {
Objects.requireNonNull(phoneNumber);
this.phoneNumber = phoneNumber;
this.type = type;
Expand All @@ -34,7 +34,7 @@ public E164PhoneNumber getPhoneNumber() {
return phoneNumber;
}

public TYPE getType() {
public DestinationNumberType getType() {
return type;
}

Expand All @@ -53,13 +53,6 @@ public static DestinationNumber valueOf(String e164PhoneNumber) {
return new DestinationNumber(E164PhoneNumber.valueOf(e164PhoneNumber));
}

public enum TYPE {
/** * Public Switched Telephone Network */
PSTN,
/** * Direct inward dialing */
DID
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down

0 comments on commit 71f5bb2

Please sign in to comment.