Search in sources :

Example 1 with UnknownIdentifier

use of com.azure.android.communication.common.UnknownIdentifier 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 UnknownIdentifier

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

the class CommunicationIdentifierConverterTests method serializeUnknown.

@Test
public void serializeUnknown() {
    CommunicationIdentifierModel model = CommunicationIdentifierConverter.convert(new UnknownIdentifier(someId), logger);
    assertEquals(someId, model.getRawId());
}
Also used : UnknownIdentifier(com.azure.android.communication.common.UnknownIdentifier) CommunicationIdentifierModel(com.azure.android.communication.chat.implementation.models.CommunicationIdentifierModel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with UnknownIdentifier

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

the class NotificationUtilsTest method fallbackToUnknownIdentifierForUnknownRawId.

@Test
public void fallbackToUnknownIdentifierForUnknownRawId() {
    final String unknownRawId = "unknown_raw_id";
    CommunicationIdentifier communicationIdentifier = NotificationUtils.getCommunicationIdentifier(unknownRawId);
    assertNotNull(communicationIdentifier);
    assertTrue(communicationIdentifier instanceof UnknownIdentifier);
    UnknownIdentifier unknownIdentifier = (UnknownIdentifier) communicationIdentifier;
    assertEquals(unknownRawId, unknownIdentifier.getId());
}
Also used : CommunicationIdentifier(com.azure.android.communication.common.CommunicationIdentifier) UnknownIdentifier(com.azure.android.communication.common.UnknownIdentifier) Test(org.junit.jupiter.api.Test)

Aggregations

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