Skip to content

Commit

Permalink
Changed MS bot identifier to MS Teams app identifier. (#37463)
Browse files Browse the repository at this point in the history
* Changed MS bot identifier to MS Teams app identifier.

* Made SetRawId protected for MSTeams app identifier

* Updating changelog.

* Fixing Changelog.

* Changed communication common package version to minor version bump

* Changing the version to beta.2 as beta.1 was already released
  • Loading branch information
jiriburant authored Dec 5, 2023
1 parent fc8e083 commit 2b02072
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 188 deletions.
2 changes: 1 addition & 1 deletion eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ com.azure:azure-code-customization-parent;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-communication-callautomation;1.1.0;1.2.0-beta.1
com.azure:azure-communication-callingserver;1.0.0-beta.4;1.0.0-beta.5
com.azure:azure-communication-chat;1.3.14;1.4.0
com.azure:azure-communication-common;1.2.14;2.0.0-beta.2
com.azure:azure-communication-common;1.2.14;1.3.0-beta.2
com.azure:azure-communication-common-perf;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-communication-email;1.0.8;1.1.0-beta.1
com.azure:azure-communication-identity;1.5.0;1.6.0-beta.1
Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/azure-communication-common-perf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-communication-common</artifactId>
<version>2.0.0-beta.2</version> <!-- {x-version-update;com.azure:azure-communication-common;current} -->
<version>1.3.0-beta.2</version> <!-- {x-version-update;com.azure:azure-communication-common;current} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
Expand Down
4 changes: 3 additions & 1 deletion sdk/communication/azure-communication-common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Release History

## 2.0.0-beta.2 (Unreleased)
## 1.3.0-beta.2 (Unreleased)

### Features Added
- Added support for a new communication identifier `MicrosoftTeamsAppIdentifier`.

### Breaking Changes
- Introduction of `MicrosoftTeamsAppIdentifier` is a breaking change. It will impact any code that previously depended on the use of UnknownIdentifier with rawIDs starting with `28:orgid:`, `28:dod:`, or `28:gcch:`.

### Bugs Fixed

Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/azure-communication-common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ add the direct dependency to your project as follows.
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-communication-common</artifactId>
<version>2.0.0-beta.1</version>
<version>1.3.0-beta.2</version>
</dependency>
```
[//]: # ({x-version-update-end})
Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/azure-communication-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<groupId>com.azure</groupId>
<artifactId>azure-communication-common</artifactId>
<packaging>jar</packaging>
<version>2.0.0-beta.2</version> <!-- {x-version-update;com.azure:azure-communication-common;current} -->
<version>1.3.0-beta.2</version> <!-- {x-version-update;com.azure:azure-communication-common;current} -->

<name>Microsoft Azure common library for communication service client</name>
<description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ public abstract class CommunicationIdentifier {

static final String PHONE_NUMBER_PREFIX = "4:";

static final String BOT_PREFIX = "28:";
static final String TEAMS_APP_PUBLIC_CLOUD_PREFIX = "28:orgid:";

static final String BOT_PUBLIC_CLOUD_PREFIX = "28:orgid:";
static final String TEAMS_APP_DOD_CLOUD_PREFIX = "28:dod:";

static final String BOT_DOD_CLOUD_PREFIX = "28:dod:";

static final String BOT_DOD_CLOUD_GLOBAL_PREFIX = "28:dod-global:";

static final String BOT_GCCH_CLOUD_PREFIX = "28:gcch:";

static final String BOT_GCCH_CLOUD_GLOBAL_PREFIX = "28:gcch-global:";
static final String TEAMS_APP_GCCH_CLOUD_PREFIX = "28:gcch:";

static final String TEAMS_USER_ANONYMOUS_PREFIX = "8:teamsvisitor:";

Expand Down Expand Up @@ -58,9 +52,6 @@ public static CommunicationIdentifier fromRawId(String rawId) {
}
final String[] segments = rawId.split(":");
if (segments.length != 3) {
if (segments.length == 2 && rawId.startsWith(BOT_PREFIX)) {
return new MicrosoftBotIdentifier(segments[1], false, CommunicationCloudEnvironment.PUBLIC);
}
return new UnknownIdentifier(rawId);
}

Expand All @@ -77,16 +68,12 @@ public static CommunicationIdentifier fromRawId(String rawId) {
return new MicrosoftTeamsUserIdentifier(suffix, false).setCloudEnvironment(CommunicationCloudEnvironment.GCCH);
} else if (ACS_USER_PREFIX.equals(prefix) || SPOOL_USER_PREFIX.equals(prefix) || ACS_USER_DOD_CLOUD_PREFIX.equals(prefix) || ACS_USER_GCCH_CLOUD_PREFIX.equals(prefix)) {
return new CommunicationUserIdentifier(rawId);
} else if (BOT_GCCH_CLOUD_GLOBAL_PREFIX.equals(prefix)) {
return new MicrosoftBotIdentifier(suffix, false, CommunicationCloudEnvironment.GCCH);
} else if (BOT_PUBLIC_CLOUD_PREFIX.equals(prefix)) {
return new MicrosoftBotIdentifier(suffix, true, CommunicationCloudEnvironment.PUBLIC);
} else if (BOT_DOD_CLOUD_GLOBAL_PREFIX.equals(prefix)) {
return new MicrosoftBotIdentifier(suffix, false, CommunicationCloudEnvironment.DOD);
} else if (BOT_GCCH_CLOUD_PREFIX.equals(prefix)) {
return new MicrosoftBotIdentifier(suffix, true, CommunicationCloudEnvironment.GCCH);
} else if (BOT_DOD_CLOUD_PREFIX.equals(prefix)) {
return new MicrosoftBotIdentifier(suffix, true, CommunicationCloudEnvironment.DOD);
} else if (TEAMS_APP_PUBLIC_CLOUD_PREFIX.equals(prefix)) {
return new MicrosoftTeamsAppIdentifier(suffix, CommunicationCloudEnvironment.PUBLIC);
} else if (TEAMS_APP_GCCH_CLOUD_PREFIX.equals(prefix)) {
return new MicrosoftTeamsAppIdentifier(suffix, CommunicationCloudEnvironment.GCCH);
} else if (TEAMS_APP_DOD_CLOUD_PREFIX.equals(prefix)) {
return new MicrosoftTeamsAppIdentifier(suffix, CommunicationCloudEnvironment.DOD);
}

return new UnknownIdentifier(rawId);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.communication.common;

import com.azure.core.util.CoreUtils;

/**
* Communication identifier for Microsoft Teams Application
*/
public final class MicrosoftTeamsAppIdentifier extends CommunicationIdentifier {
private final String appId;

private final CommunicationCloudEnvironment cloudEnvironment;

/**
* Creates a MicrosoftTeamsAppIdentifier object
*
* @param appId ID of the Microsoft Teams Application.
* @param cloudEnvironment the cloud environment in which this identifier is created.
* @throws IllegalArgumentException thrown if appId parameter fails the validation.
*/
public MicrosoftTeamsAppIdentifier(String appId, CommunicationCloudEnvironment cloudEnvironment) {
if (CoreUtils.isNullOrEmpty(appId)) {
throw new IllegalArgumentException("The initialization parameter [appId] cannot be null or empty.");
}
this.appId = appId;
this.cloudEnvironment = cloudEnvironment;
generateRawId();
}

/**
* Creates a MicrosoftTeamsAppIdentifier object
*
* @param appId ID of the Microsoft Teams Application.
* @throws IllegalArgumentException thrown if appId parameter fails the validation.
*/
public MicrosoftTeamsAppIdentifier(String appId) {
this(appId, CommunicationCloudEnvironment.PUBLIC);
}

/**
* Get application ID
* @return ID of the Microsoft Teams Application.
*/
public String getAppId() {
return this.appId;
}

/**
* Get cloud environment of the application identifier
*
* @return cloud environment in which this identifier is created.
*/
public CommunicationCloudEnvironment getCloudEnvironment() {
return cloudEnvironment;
}

/**
* Set full ID of the identifier
* RawId is the encoded format for identifiers to store in databases or as stable keys in general.
*
* @param rawId full ID of the identifier.
* @return MicrosoftTeamsAppIdentifier object itself.
*/
@Override
protected MicrosoftTeamsAppIdentifier setRawId(String rawId) {
super.setRawId(rawId);
return this;
}

@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}

if (!(that instanceof MicrosoftTeamsAppIdentifier)) {
return false;
}

return ((MicrosoftTeamsAppIdentifier) that).getRawId().equals(getRawId());
}

@Override
public int hashCode() {
return getRawId().hashCode();
}

private void generateRawId() {
if (cloudEnvironment.equals(CommunicationCloudEnvironment.DOD)) {
super.setRawId(TEAMS_APP_DOD_CLOUD_PREFIX + this.appId);
} else if (cloudEnvironment.equals(CommunicationCloudEnvironment.GCCH)) {
super.setRawId(TEAMS_APP_GCCH_CLOUD_PREFIX + this.appId);
} else {
super.setRawId(TEAMS_APP_PUBLIC_CLOUD_PREFIX + this.appId);
}
}
}
Loading

0 comments on commit 2b02072

Please sign in to comment.