Search in sources :

Example 1 with PhoneNumberIdentifierModel

use of com.azure.android.communication.chat.implementation.models.PhoneNumberIdentifierModel 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)));
    }
}
Also used : CommunicationUserIdentifierModel(com.azure.android.communication.chat.implementation.models.CommunicationUserIdentifierModel) PhoneNumberIdentifierModel(com.azure.android.communication.chat.implementation.models.PhoneNumberIdentifierModel) ArrayList(java.util.ArrayList) MicrosoftTeamsUserIdentifierModel(com.azure.android.communication.chat.implementation.models.MicrosoftTeamsUserIdentifierModel)

Example 2 with PhoneNumberIdentifierModel

use of com.azure.android.communication.chat.implementation.models.PhoneNumberIdentifierModel 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 3 with PhoneNumberIdentifierModel

use of com.azure.android.communication.chat.implementation.models.PhoneNumberIdentifierModel in project azure-sdk-for-android by Azure.

the class CommunicationIdentifierConverterTests method deserializePhoneNumber.

@Test
public void deserializePhoneNumber() {
    CommunicationIdentifier identifier = CommunicationIdentifierConverter.convert(new CommunicationIdentifierModel().setRawId(rawId).setPhoneNumber(new PhoneNumberIdentifierModel().setValue(testPhoneNumber)), logger);
    assertEquals(PhoneNumberIdentifier.class, identifier.getClass());
    assertEquals(testPhoneNumber, ((PhoneNumberIdentifier) identifier).getPhoneNumber());
    assertEquals(rawId, ((PhoneNumberIdentifier) identifier).getRawId());
}
Also used : CommunicationIdentifier(com.azure.android.communication.common.CommunicationIdentifier) PhoneNumberIdentifierModel(com.azure.android.communication.chat.implementation.models.PhoneNumberIdentifierModel) CommunicationIdentifierModel(com.azure.android.communication.chat.implementation.models.CommunicationIdentifierModel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with PhoneNumberIdentifierModel

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

Example 5 with PhoneNumberIdentifierModel

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

Aggregations

PhoneNumberIdentifierModel (com.azure.android.communication.chat.implementation.models.PhoneNumberIdentifierModel)5 MicrosoftTeamsUserIdentifierModel (com.azure.android.communication.chat.implementation.models.MicrosoftTeamsUserIdentifierModel)4 CommunicationIdentifierModel (com.azure.android.communication.chat.implementation.models.CommunicationIdentifierModel)3 CommunicationUserIdentifierModel (com.azure.android.communication.chat.implementation.models.CommunicationUserIdentifierModel)3 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 CommunicationCloudEnvironmentModel (com.azure.android.communication.chat.implementation.models.CommunicationCloudEnvironmentModel)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 UnknownIdentifier (com.azure.android.communication.common.UnknownIdentifier)1 ArrayList (java.util.ArrayList)1