Skip to content

Commit df9cb2a

Browse files
alexandra142Alexandra Lamiova Pistrakova
andauthored
Update Communication Common SDK for Teams Phone Extensibility identifier (#1918)
* Add TeamsPhoneExtensionIdentifier, Add isAnonymous and getAssertedId methods to PhoneNumberIdentifier * Set Is Anonymous during instantiation. * Set Is Anonymous during setting a rawId * Add test for IsAnonymous when SetRawId method is called. * Add test for IsAnonymous when SetRawId method is called. * Rename StringUtils.java to ValidationUtils.java - Throw IllegalArgumentException when cloud parameter in SetCloudEnvironment is null * Use class parameters for TeamsExtensionIdentifier tests * Use class parameters for TeamsExtensionIdentifier_rawIdTakesPrecedenceInEqualityCheck * Use class parameters for TeamsExtensionIdentifier_rawIdTakesPrecedenceInEqualityCheck * Set 1.3.0 version * Revert changes * Update readme * Fix Gradle.properties to version 1.3.. * Remove empty rows --------- Co-authored-by: Alexandra Lamiova Pistrakova <[email protected]>
1 parent 7bd7ef6 commit df9cb2a

File tree

9 files changed

+473
-29
lines changed

9 files changed

+473
-29
lines changed

sdk/communication/azure-communication-common/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release History
22

3+
## 1.3.0 (2025-03-12)
4+
5+
### Features Added
6+
- Added support for a new communication identifier `TeamsExtensionUserIdentifier` which maps rawIds with format `8:acs:{resourceId}_{tenantId}_{userId}`.
7+
- Added `isAnonymous` and `getAssertedId` methods to `PhoneNumberIdentifier`.
8+
39
## 1.2.1 (2024-02-23)
410

511
### Other Changes

sdk/communication/azure-communication-common/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This package contains common code for Azure Communication Service libraries.
2020
APIs that would require the Java 8+ API desugaring provided by Android Gradle plugin 4.0.0.
2121

2222
### Versions available
23-
The current version of this library is **1.2.1**.
23+
The current version of this library is **1.3.0**.
2424

2525
### Install the library
2626
To install the Azure client libraries for Android, add them as dependencies within your
@@ -36,13 +36,13 @@ Add an `implementation` configuration to the `dependencies` block of your app's
3636
// build.gradle
3737
dependencies {
3838
...
39-
implementation "com.azure.android:azure-communication-common:1.2.1"
39+
implementation "com.azure.android:azure-communication-common:1.3.0"
4040
}
4141
4242
// build.gradle.kts
4343
dependencies {
4444
...
45-
implementation("com.azure.android:azure-communication-common:1.2.1")
45+
implementation("com.azure.android:azure-communication-common:1.3.0")
4646
}
4747
```
4848

@@ -53,7 +53,7 @@ To import the library into your project using the [Maven](https://maven.apache.o
5353
<dependency>
5454
<groupId>com.azure.android</groupId>
5555
<artifactId>azure-communication-common</artifactId>
56-
<version>1.2.1</version>
56+
<version>1.3.0</version>
5757
</dependency>
5858
```
5959

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=1.2.1
1+
version=1.3.0

sdk/communication/azure-communication-common/src/main/java/com/azure/android/communication/common/CommunicationIdentifier.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ public abstract class CommunicationIdentifier {
2828
* @throws IllegalArgumentException raw id is null or empty.
2929
*/
3030
public static CommunicationIdentifier fromRawId(String rawId) {
31-
if (rawId == null || rawId.trim().length() == 0) {
32-
throw new IllegalArgumentException("The parameter [rawId] cannot be null to empty.");
33-
}
31+
ValidationUtils.validateNotNullOrEmpty(rawId, "rawId");
3432

3533
if (rawId.startsWith(PHONE_NUMBER_PREFIX)) {
3634
return new PhoneNumberIdentifier(rawId.substring(PHONE_NUMBER_PREFIX.length()));
@@ -60,11 +58,12 @@ public static CommunicationIdentifier fromRawId(String rawId) {
6058
return new MicrosoftTeamsAppIdentifier(suffix, CommunicationCloudEnvironment.DOD);
6159
case TEAMS_APP_GCCH_CLOUD_PREFIX:
6260
return new MicrosoftTeamsAppIdentifier(suffix, CommunicationCloudEnvironment.GCCH);
63-
case ACS_USER_PREFIX:
6461
case SPOOL_USER_PREFIX:
62+
return new CommunicationUserIdentifier(rawId);
63+
case ACS_USER_PREFIX:
6564
case ACS_USER_DOD_CLOUD_PREFIX:
6665
case ACS_USER_GCCH_CLOUD_PREFIX:
67-
return new CommunicationUserIdentifier(rawId);
66+
return tryCreateTeamsExtensionUserOrCommunicationUser(prefix, suffix, rawId);
6867
default:
6968
return new UnknownIdentifier(rawId);
7069
}
@@ -110,4 +109,38 @@ public boolean equals(Object that) {
110109
public int hashCode() {
111110
return getRawId().hashCode();
112111
}
112+
113+
private static CommunicationIdentifier tryCreateTeamsExtensionUserOrCommunicationUser(String prefix, String suffix,
114+
String rawId) {
115+
String[] segments = suffix.split("_");
116+
if (segments.length != 3) {
117+
return new CommunicationUserIdentifier(rawId);
118+
}
119+
120+
String resourceId = segments[0];
121+
String tenantId = segments[1];
122+
String userId = segments[2];
123+
CommunicationCloudEnvironment cloud = determineCloudEnvironment(prefix);
124+
125+
return new TeamsExtensionUserIdentifier(userId, tenantId, resourceId).setCloudEnvironment(cloud);
126+
}
127+
128+
/**
129+
* Determine the cloud based on identifier prefix.
130+
* @param cloudPrefix .
131+
* @return CommunicationCloudEnvironment.
132+
* @throws IllegalArgumentException thrown if CommunicationCloudEnvironment cannot be initialized.
133+
*/
134+
static CommunicationCloudEnvironment determineCloudEnvironment(String cloudPrefix) {
135+
switch (cloudPrefix) {
136+
case ACS_USER_DOD_CLOUD_PREFIX:
137+
return CommunicationCloudEnvironment.DOD;
138+
case ACS_USER_GCCH_CLOUD_PREFIX:
139+
return CommunicationCloudEnvironment.GCCH;
140+
case ACS_USER_PREFIX:
141+
return CommunicationCloudEnvironment.PUBLIC;
142+
default:
143+
throw new IllegalArgumentException("Cannot initialize CommunicationCloudEnvironment.");
144+
}
145+
}
113146
}

sdk/communication/azure-communication-common/src/main/java/com/azure/android/communication/common/MicrosoftTeamsUserIdentifier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public final class MicrosoftTeamsUserIdentifier extends CommunicationIdentifier
1616
* Creates a MicrosoftTeamsUserIdentifier object
1717
*
1818
* @param userId Id of the Microsoft Teams user. If the user isn't anonymous,
19-
* the id is the AAD object id of the user.
19+
* the id is the Entra ID object id of the user.
2020
* @param isAnonymous set this to true if the user is anonymous,
2121
* for example when joining a meeting with a share link
2222
* @throws IllegalArgumentException thrown if userId parameter fail the validation.
@@ -34,7 +34,7 @@ public MicrosoftTeamsUserIdentifier(String userId, boolean isAnonymous) {
3434
* Creates a MicrosoftTeamsUserIdentifier object
3535
*
3636
* @param userId Id of the Microsoft Teams user. If the user isn't anonymous,
37-
* the id is the AAD object id of the user.
37+
* the id is the Entra ID object id of the user.
3838
* @throws IllegalArgumentException thrown if userId parameter fail the validation.
3939
*/
4040
public MicrosoftTeamsUserIdentifier(String userId) {

sdk/communication/azure-communication-common/src/main/java/com/azure/android/communication/common/PhoneNumberIdentifier.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
* Communication identifier for Communication Services Phone Numbers
77
*/
88
public final class PhoneNumberIdentifier extends CommunicationIdentifier {
9+
private static final String ANONYMOUS = "anonymous";
910
private final String phoneNumber;
11+
private String assertedId;
12+
13+
private boolean isAnonymous;
1014

1115
/**
1216
* Creates a PhoneNumberIdentifier object
@@ -16,10 +20,7 @@ public final class PhoneNumberIdentifier extends CommunicationIdentifier {
1620
* @throws IllegalArgumentException thrown if phoneNumber parameter fail the validation.
1721
*/
1822
public PhoneNumberIdentifier(String phoneNumber) {
19-
if (phoneNumber == null || phoneNumber.trim().length() == 0) {
20-
throw new IllegalArgumentException("The initialization parameter [phoneNumber] cannot be null to empty.");
21-
}
22-
this.phoneNumber = phoneNumber;
23+
this.phoneNumber = ValidationUtils.validateNotNullOrEmpty(phoneNumber, "phoneNumber");
2324
this.setRawId(PHONE_NUMBER_PREFIX + phoneNumber);
2425
}
2526

@@ -30,6 +31,35 @@ public String getPhoneNumber() {
3031
return phoneNumber;
3132
}
3233

34+
/**
35+
* Checks if the phone number is anonymous, e.g., used to represent a hidden caller ID.
36+
*
37+
* @return true if the phone number is anonymous, false otherwise.
38+
*/
39+
public boolean isAnonymous() {
40+
return isAnonymous;
41+
}
42+
43+
/**
44+
* Gets the asserted ID for the phone number, distinguishing it from other connections made through the same number.
45+
*
46+
* @return the string identifier representing the asserted ID for the phone number.
47+
*/
48+
public String getAssertedId() {
49+
if (assertedId != null && !assertedId.trim().isEmpty()) {
50+
return assertedId;
51+
}
52+
53+
String[] segments = getRawId().substring(PHONE_NUMBER_PREFIX.length()).split("_");
54+
if (segments.length > 1) {
55+
assertedId = segments[segments.length - 1];
56+
return assertedId;
57+
}
58+
59+
assertedId = "";
60+
return null;
61+
}
62+
3363
/**
3464
* Set full id of the identifier
3565
* RawId is the encoded format for identifiers to store in databases or as stable keys in general.
@@ -40,6 +70,7 @@ public String getPhoneNumber() {
4070
@Override
4171
public PhoneNumberIdentifier setRawId(String rawId) {
4272
super.setRawId(rawId);
73+
isAnonymous = getRawId().equals(PHONE_NUMBER_PREFIX + ANONYMOUS);
4374
return this;
4475
}
4576

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.android.communication.common;
5+
6+
/**
7+
* Communication identifier for Microsoft Teams Phone user who is using a Communication Services resource
8+
* to extend their Teams Phone set up.
9+
*/
10+
public final class TeamsExtensionUserIdentifier extends CommunicationIdentifier {
11+
12+
private final String userId;
13+
14+
private final String tenantId;
15+
16+
private final String resourceId;
17+
18+
private CommunicationCloudEnvironment cloudEnvironment;
19+
20+
/**
21+
* Creates a TeamsExtensionUserIdentifier object with PUBLIC cloud environment.
22+
*
23+
* @param userId ID of the Microsoft Teams Extension user i.e. the Entra ID object id of the user.
24+
* @param tenantId Tenant ID of the Microsoft Teams Extension user.
25+
* @param resourceId The Communication Services resource id.
26+
* @throws IllegalArgumentException if any parameter fail the validation.
27+
*/
28+
public TeamsExtensionUserIdentifier(String userId, String tenantId, String resourceId) {
29+
this.userId = ValidationUtils.validateNotNullOrEmpty(userId, "userId");
30+
this.tenantId = ValidationUtils.validateNotNullOrEmpty(tenantId, "tenantId");
31+
this.resourceId = ValidationUtils.validateNotNullOrEmpty(resourceId, "resourceId");
32+
this.cloudEnvironment = CommunicationCloudEnvironment.PUBLIC;
33+
34+
generateRawId();
35+
}
36+
37+
/**
38+
* Set full ID of the identifier
39+
* RawId is the encoded format for identifiers to store in databases or as stable keys in general.
40+
*
41+
* @param rawId full ID of the identifier.
42+
* @return TeamsExtensionUserIdentifier object itself.
43+
*/
44+
@Override
45+
public TeamsExtensionUserIdentifier setRawId(String rawId) {
46+
super.setRawId(rawId);
47+
return this;
48+
}
49+
50+
/**
51+
* Get Microsoft Teams Extension user
52+
* @return ID of the Microsoft Teams Extension user i.e. the Entra ID object id of the user.
53+
*/
54+
public String getUserId() {
55+
return userId;
56+
}
57+
58+
/**
59+
* Get Microsoft Teams Extension user Tenant ID
60+
* @return Tenant ID of the Microsoft Teams Extension user.
61+
*/
62+
public String getTenantId() {
63+
return tenantId;
64+
}
65+
66+
/**
67+
* Get Communication Services resource id.
68+
* @return the Communication Services resource id.
69+
*/
70+
public String getResourceId() {
71+
return resourceId;
72+
}
73+
74+
/**
75+
* Get cloud environment of the Teams Extension User identifier
76+
* @return cloud environment in which this identifier is created
77+
*/
78+
public CommunicationCloudEnvironment getCloudEnvironment() {
79+
return cloudEnvironment;
80+
}
81+
82+
/**
83+
* Set cloud environment of the Teams Extension User identifier
84+
*
85+
* @param cloudEnvironment the cloud environment in which this identifier is created
86+
* @return this object
87+
* @throws IllegalArgumentException if cloudEnvironment .
88+
*
89+
*/
90+
public TeamsExtensionUserIdentifier setCloudEnvironment(CommunicationCloudEnvironment cloudEnvironment) {
91+
this.cloudEnvironment = ValidationUtils.validateNotNull(cloudEnvironment, "cloudEnvironment");
92+
generateRawId();
93+
return this;
94+
}
95+
96+
@Override
97+
public boolean equals(Object that) {
98+
if (this == that) {
99+
return true;
100+
}
101+
102+
if (!(that instanceof TeamsExtensionUserIdentifier)) {
103+
return false;
104+
}
105+
106+
return super.equals(that);
107+
}
108+
109+
@Override
110+
public int hashCode() {
111+
return super.hashCode();
112+
}
113+
114+
private void generateRawId() {
115+
String identifierBase = this.resourceId + "_" + this.tenantId + "_" + this.userId;
116+
if (cloudEnvironment.equals(CommunicationCloudEnvironment.DOD)) {
117+
super.setRawId(ACS_USER_DOD_CLOUD_PREFIX + identifierBase);
118+
} else if (cloudEnvironment.equals(CommunicationCloudEnvironment.GCCH)) {
119+
super.setRawId(ACS_USER_GCCH_CLOUD_PREFIX + identifierBase);
120+
} else {
121+
super.setRawId(ACS_USER_PREFIX + identifierBase);
122+
}
123+
}
124+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.android.communication.common;
5+
6+
class ValidationUtils {
7+
8+
/**
9+
* Validate string
10+
* @param value a value to be validated
11+
* @param paramName Parameter name for exceptionMessage
12+
* @return value
13+
*
14+
* @throws IllegalArgumentException when value is null or Empty.
15+
*/
16+
public static String validateNotNullOrEmpty(String value, String paramName) {
17+
if (value == null || value.trim().isEmpty()) {
18+
String message = "The parameter [" + paramName + "] cannot be null or empty.";
19+
throw new IllegalArgumentException(message);
20+
}
21+
return value;
22+
}
23+
24+
/**
25+
* Validate string
26+
* @param cloudEnvironment a value to be validated
27+
* @param paramName Parameter name for exceptionMessage
28+
* @return value
29+
*
30+
* @throws IllegalArgumentException when value is null or Empty.
31+
*/
32+
public static CommunicationCloudEnvironment validateNotNull(CommunicationCloudEnvironment cloudEnvironment,
33+
String paramName) {
34+
if (cloudEnvironment == null) {
35+
String message = "The parameter [" + paramName + "] cannot be null.";
36+
throw new IllegalArgumentException(message);
37+
}
38+
return cloudEnvironment;
39+
}
40+
41+
}

0 commit comments

Comments
 (0)