use of com.azure.android.communication.chat.implementation.models.MicrosoftTeamsUserIdentifierModel in project azure-sdk-for-android by Azure.
the class CommunicationIdentifierConverter method assertSingleType.
private static void assertSingleType(CommunicationIdentifierModel identifier) {
CommunicationUserIdentifierModel communicationUser = identifier.getCommunicationUser();
PhoneNumberIdentifierModel phoneNumber = identifier.getPhoneNumber();
MicrosoftTeamsUserIdentifierModel microsoftTeamsUser = identifier.getMicrosoftTeamsUser();
ArrayList<String> presentProperties = new ArrayList<String>();
if (communicationUser != null) {
presentProperties.add(communicationUser.getClass().getName());
}
if (phoneNumber != null) {
presentProperties.add(phoneNumber.getClass().getName());
}
if (microsoftTeamsUser != null) {
presentProperties.add(microsoftTeamsUser.getClass().getName());
}
if (presentProperties.size() > 1) {
throw new IllegalArgumentException(String.format("Only one of the identifier models in %s should be present.", TextUtils.join(", ", presentProperties)));
}
}
use of com.azure.android.communication.chat.implementation.models.MicrosoftTeamsUserIdentifierModel 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.chat.implementation.models.MicrosoftTeamsUserIdentifierModel in project azure-sdk-for-android by Azure.
the class CommunicationIdentifierConverterTests method deserializerMicrosoftTeamsUser.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void deserializerMicrosoftTeamsUser(boolean isAnonymous) {
MicrosoftTeamsUserIdentifier identifier = (MicrosoftTeamsUserIdentifier) CommunicationIdentifierConverter.convert(new CommunicationIdentifierModel().setRawId(rawId).setMicrosoftTeamsUser(new MicrosoftTeamsUserIdentifierModel().setUserId(teamsUserId).setIsAnonymous(isAnonymous).setCloud(CommunicationCloudEnvironmentModel.GCCH)), logger);
assertEquals(MicrosoftTeamsUserIdentifier.class, identifier.getClass());
assertEquals(teamsUserId, identifier.getUserId());
assertEquals(rawId, identifier.getRawId());
assertEquals(CommunicationCloudEnvironment.GCCH, identifier.getCloudEnvironment());
assertEquals(isAnonymous, identifier.isAnonymous());
}
use of com.azure.android.communication.chat.implementation.models.MicrosoftTeamsUserIdentifierModel in project azure-sdk-for-android by Azure.
the class CommunicationIdentifierConverterTests method deserializerThrowsWhenMissingProperty.
@Test
public void deserializerThrowsWhenMissingProperty() {
CommunicationIdentifierModel[] modelsWithMissingMandatoryProperty = new CommunicationIdentifierModel[] { // Missing RawId
new CommunicationIdentifierModel(), // Missing Id
new CommunicationIdentifierModel().setRawId(rawId).setCommunicationUser(new CommunicationUserIdentifierModel()), // Missing PhoneNumber
new CommunicationIdentifierModel().setRawId(rawId).setPhoneNumber(new PhoneNumberIdentifierModel()), new CommunicationIdentifierModel().setRawId(rawId).setMicrosoftTeamsUser(// Missing userId
new MicrosoftTeamsUserIdentifierModel().setCloud(CommunicationCloudEnvironmentModel.PUBLIC)), new CommunicationIdentifierModel().setRawId(rawId).setMicrosoftTeamsUser(// Missing UserId
new MicrosoftTeamsUserIdentifierModel().setIsAnonymous(true).setCloud(CommunicationCloudEnvironmentModel.DOD)), new CommunicationIdentifierModel().setRawId(rawId).setMicrosoftTeamsUser(new MicrosoftTeamsUserIdentifierModel().setUserId(teamsUserId).setIsAnonymous(true)) };
Arrays.stream(modelsWithMissingMandatoryProperty).forEach(identifierModel -> {
assertThrows(NullPointerException.class, () -> {
CommunicationIdentifierConverter.convert(identifierModel, logger);
});
});
}
use of com.azure.android.communication.chat.implementation.models.MicrosoftTeamsUserIdentifierModel in project azure-sdk-for-android by Azure.
the class CommunicationIdentifierConverterTests method deserializerThrowsWhenMoreThanOneNestedObjectsSet.
@Test
public void deserializerThrowsWhenMoreThanOneNestedObjectsSet() {
CommunicationIdentifierModel[] modelsWithTooManyNestedObjects = new CommunicationIdentifierModel[] { new CommunicationIdentifierModel().setRawId(rawId).setCommunicationUser(new CommunicationUserIdentifierModel().setId(someId)).setPhoneNumber(new PhoneNumberIdentifierModel().setValue(testPhoneNumber)), new CommunicationIdentifierModel().setRawId(rawId).setCommunicationUser(new CommunicationUserIdentifierModel().setId(someId)).setMicrosoftTeamsUser(new MicrosoftTeamsUserIdentifierModel().setUserId(teamsUserId).setIsAnonymous(true).setCloud(CommunicationCloudEnvironmentModel.PUBLIC)), new CommunicationIdentifierModel().setRawId(rawId).setPhoneNumber(new PhoneNumberIdentifierModel().setValue(testPhoneNumber)).setMicrosoftTeamsUser(new MicrosoftTeamsUserIdentifierModel().setUserId(teamsUserId).setIsAnonymous(true).setCloud(CommunicationCloudEnvironmentModel.PUBLIC)) };
Arrays.stream(modelsWithTooManyNestedObjects).forEach(identifierModel -> {
assertThrows(IllegalArgumentException.class, () -> {
CommunicationIdentifierConverter.convert(identifierModel, logger);
});
});
}
Aggregations