Search in sources :

Example 1 with MicrosoftTeamsUserIdentifier

use of com.azure.android.communication.common.MicrosoftTeamsUserIdentifier 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);
}
Also used : MicrosoftTeamsUserIdentifier(com.azure.android.communication.common.MicrosoftTeamsUserIdentifier) CommunicationCloudEnvironmentModel(com.azure.android.communication.chat.implementation.models.CommunicationCloudEnvironmentModel) PhoneNumberIdentifierModel(com.azure.android.communication.chat.implementation.models.PhoneNumberIdentifierModel) PhoneNumberIdentifier(com.azure.android.communication.common.PhoneNumberIdentifier) MicrosoftTeamsUserIdentifierModel(com.azure.android.communication.chat.implementation.models.MicrosoftTeamsUserIdentifierModel) UnknownIdentifier(com.azure.android.communication.common.UnknownIdentifier) CommunicationUserIdentifier(com.azure.android.communication.common.CommunicationUserIdentifier)

Example 2 with MicrosoftTeamsUserIdentifier

use of com.azure.android.communication.common.MicrosoftTeamsUserIdentifier 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());
}
Also used : MicrosoftTeamsUserIdentifier(com.azure.android.communication.common.MicrosoftTeamsUserIdentifier) MicrosoftTeamsUserIdentifierModel(com.azure.android.communication.chat.implementation.models.MicrosoftTeamsUserIdentifierModel) CommunicationIdentifierModel(com.azure.android.communication.chat.implementation.models.CommunicationIdentifierModel) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with MicrosoftTeamsUserIdentifier

use of com.azure.android.communication.common.MicrosoftTeamsUserIdentifier in project azure-sdk-for-android by Azure.

the class NotificationUtilsTest method canParseTeamsPublicUserRawId.

@Test
public void canParseTeamsPublicUserRawId() {
    final String teamsPublicUserRawId = "8:orgid:" + USER_ID;
    CommunicationIdentifier communicationIdentifier = NotificationUtils.getCommunicationIdentifier(teamsPublicUserRawId);
    assertNotNull(communicationIdentifier);
    assertTrue(communicationIdentifier instanceof MicrosoftTeamsUserIdentifier);
    MicrosoftTeamsUserIdentifier microsoftTeamsUserIdentifier = (MicrosoftTeamsUserIdentifier) communicationIdentifier;
    assertEquals(CommunicationCloudEnvironment.PUBLIC, microsoftTeamsUserIdentifier.getCloudEnvironment());
    assertEquals(false, microsoftTeamsUserIdentifier.isAnonymous());
    assertEquals(USER_ID, microsoftTeamsUserIdentifier.getUserId());
    assertEquals(teamsPublicUserRawId, microsoftTeamsUserIdentifier.getRawId());
}
Also used : MicrosoftTeamsUserIdentifier(com.azure.android.communication.common.MicrosoftTeamsUserIdentifier) CommunicationIdentifier(com.azure.android.communication.common.CommunicationIdentifier) Test(org.junit.jupiter.api.Test)

Example 4 with MicrosoftTeamsUserIdentifier

use of com.azure.android.communication.common.MicrosoftTeamsUserIdentifier in project azure-sdk-for-android by Azure.

the class NotificationUtilsTest method canParseTeamsVisitorUserRawId.

@Test
public void canParseTeamsVisitorUserRawId() {
    final String teamsVisitorUserRawId = "8:teamsvisitor:" + USER_ID;
    CommunicationIdentifier communicationIdentifier = NotificationUtils.getCommunicationIdentifier(teamsVisitorUserRawId);
    assertNotNull(communicationIdentifier);
    assertTrue(communicationIdentifier instanceof MicrosoftTeamsUserIdentifier);
    MicrosoftTeamsUserIdentifier microsoftTeamsUserIdentifier = (MicrosoftTeamsUserIdentifier) communicationIdentifier;
    assertEquals(CommunicationCloudEnvironment.PUBLIC, microsoftTeamsUserIdentifier.getCloudEnvironment());
    assertTrue(microsoftTeamsUserIdentifier.isAnonymous());
    assertEquals(USER_ID, microsoftTeamsUserIdentifier.getUserId());
    assertEquals(teamsVisitorUserRawId, microsoftTeamsUserIdentifier.getRawId());
}
Also used : MicrosoftTeamsUserIdentifier(com.azure.android.communication.common.MicrosoftTeamsUserIdentifier) CommunicationIdentifier(com.azure.android.communication.common.CommunicationIdentifier) Test(org.junit.jupiter.api.Test)

Example 5 with MicrosoftTeamsUserIdentifier

use of com.azure.android.communication.common.MicrosoftTeamsUserIdentifier in project azure-sdk-for-android by Azure.

the class CommunicationIdentifierConverterTests method serializeMicrosoftTeamsUser.

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void serializeMicrosoftTeamsUser(boolean isAnonymous) {
    CommunicationIdentifierModel model = CommunicationIdentifierConverter.convert(new MicrosoftTeamsUserIdentifier(teamsUserId, isAnonymous).setRawId(rawId).setCloudEnvironment(CommunicationCloudEnvironment.DOD), logger);
    assertNotNull(model.getMicrosoftTeamsUser());
    assertEquals(teamsUserId, model.getMicrosoftTeamsUser().getUserId());
    assertEquals(rawId, model.getRawId());
    assertEquals(CommunicationCloudEnvironmentModel.DOD, model.getMicrosoftTeamsUser().getCloud());
    assertEquals(isAnonymous, model.getMicrosoftTeamsUser().isAnonymous());
}
Also used : MicrosoftTeamsUserIdentifier(com.azure.android.communication.common.MicrosoftTeamsUserIdentifier) CommunicationIdentifierModel(com.azure.android.communication.chat.implementation.models.CommunicationIdentifierModel) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MicrosoftTeamsUserIdentifier (com.azure.android.communication.common.MicrosoftTeamsUserIdentifier)7 CommunicationIdentifier (com.azure.android.communication.common.CommunicationIdentifier)4 Test (org.junit.jupiter.api.Test)4 CommunicationIdentifierModel (com.azure.android.communication.chat.implementation.models.CommunicationIdentifierModel)2 MicrosoftTeamsUserIdentifierModel (com.azure.android.communication.chat.implementation.models.MicrosoftTeamsUserIdentifierModel)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 CommunicationCloudEnvironmentModel (com.azure.android.communication.chat.implementation.models.CommunicationCloudEnvironmentModel)1 PhoneNumberIdentifierModel (com.azure.android.communication.chat.implementation.models.PhoneNumberIdentifierModel)1 CommunicationUserIdentifier (com.azure.android.communication.common.CommunicationUserIdentifier)1 PhoneNumberIdentifier (com.azure.android.communication.common.PhoneNumberIdentifier)1 UnknownIdentifier (com.azure.android.communication.common.UnknownIdentifier)1