use of com.azure.android.communication.common.PhoneNumberIdentifier in project azure-sdk-for-android by Azure.
the class CommunicationIdentifierConverter method convert.
/**
* Convert CommunicationIdentifierModel into CommunicationIdentifier
* @param identifier CommunicationIdentifierModel to be converted
* @return CommunicationIdentifier
*/
public static CommunicationIdentifier convert(CommunicationIdentifierModel identifier, ClientLogger logger) {
assertSingleType(identifier);
String rawId = identifier.getRawId();
if (identifier.getCommunicationUser() != null) {
final String userId = identifier.getCommunicationUser().getId();
if (userId == null) {
throw logger.logExceptionAsError(new NullPointerException("CommunicationIdentifierModel.CommunicationUserIdentifierModel.id"));
}
return new CommunicationUserIdentifier(userId);
}
if (identifier.getPhoneNumber() != null) {
PhoneNumberIdentifierModel phoneNumberModel = identifier.getPhoneNumber();
if (phoneNumberModel.getValue() == null) {
throw logger.logExceptionAsError(new NullPointerException("CommunicationIdentifierModel.PhoneNumberIdentifierModel.value"));
}
return new PhoneNumberIdentifier(phoneNumberModel.getValue()).setRawId(rawId);
}
if (identifier.getMicrosoftTeamsUser() != null) {
MicrosoftTeamsUserIdentifierModel teamsUserIdentifierModel = identifier.getMicrosoftTeamsUser();
final String userId = teamsUserIdentifierModel.getUserId();
if (userId == null) {
throw logger.logExceptionAsError(new NullPointerException("CommunicationIdentifierModel.MicrosoftTeamsUserIdentifierModel.userId"));
}
final CommunicationCloudEnvironmentModel cloud = teamsUserIdentifierModel.getCloud();
if (cloud == null) {
throw logger.logExceptionAsError(new NullPointerException("CommunicationIdentifierModel.MicrosoftTeamsUserIdentifierModel.cloud"));
}
if (rawId == null) {
throw logger.logExceptionAsError(new NullPointerException("CommunicationIdentifierModel.rawId"));
}
return new MicrosoftTeamsUserIdentifier(userId, teamsUserIdentifierModel.isAnonymous()).setRawId(rawId).setCloudEnvironment(CommunicationCloudEnvironment.fromString(cloud.toString()));
}
if (rawId == null) {
throw logger.logExceptionAsError(new NullPointerException("CommunicationIdentifierModel.rawId"));
}
return new UnknownIdentifier(rawId);
}
use of com.azure.android.communication.common.PhoneNumberIdentifier in project azure-sdk-for-android by Azure.
the class CommunicationIdentifierConverterTests method serializePhoneNumber.
@Test
public void serializePhoneNumber() {
final String phoneNumber = "+12223334444";
CommunicationIdentifierModel model = CommunicationIdentifierConverter.convert(new PhoneNumberIdentifier(phoneNumber).setRawId(rawId), logger);
assertNotNull(model.getPhoneNumber());
assertEquals(phoneNumber, model.getPhoneNumber().getValue());
assertEquals(rawId, model.getRawId());
}
use of com.azure.android.communication.common.PhoneNumberIdentifier in project azure-sdk-for-android by Azure.
the class NotificationUtilsTest method canParsePhoneNumberRawId.
@Test
public void canParsePhoneNumberRawId() {
final String phoneNumber = "+1234567890";
final String phoneNumberRawId = "4:" + phoneNumber;
CommunicationIdentifier communicationIdentifier = NotificationUtils.getCommunicationIdentifier(phoneNumberRawId);
assertNotNull(communicationIdentifier);
assertTrue(communicationIdentifier instanceof PhoneNumberIdentifier);
PhoneNumberIdentifier phoneNumberIdentifier = (PhoneNumberIdentifier) communicationIdentifier;
assertEquals(phoneNumber, phoneNumberIdentifier.getPhoneNumber());
assertEquals(phoneNumberRawId, phoneNumberIdentifier.getRawId());
}
Aggregations