Skip to content

Commit d90271c

Browse files
JianpingChenJP Chen
andauthored
[Communication]: Add CloudEnvironment and optional full Id (Azure#18766)
* Add CloudEnvironment * Remove MRI from test constants Co-authored-by: JP Chen <[email protected]>
1 parent 4fcc209 commit d90271c

13 files changed

+413
-58
lines changed

sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CallingApplicationIdentifier.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class CallingApplicationIdentifier extends CommunicationIdentifier {
1313

1414
/**
1515
* Creates a CallingApplicationIdentifier object
16-
*
16+
*
1717
* @param id the string identifier representing the identity
1818
* @throws IllegalArgumentException thrown if id parameter fail the validation.
1919
*/
@@ -24,10 +24,27 @@ public CallingApplicationIdentifier(String id) {
2424
this.id = id;
2525
}
2626

27-
/**
28-
* @return the string identifier representing the object identity
29-
*/
27+
@Override
3028
public String getId() {
3129
return id;
3230
}
31+
32+
@Override
33+
public boolean equals(Object that) {
34+
if (this == that) {
35+
return true;
36+
}
37+
38+
if (!(that instanceof CallingApplicationIdentifier)) {
39+
return false;
40+
}
41+
42+
return ((CallingApplicationIdentifier) that).getId().equals(id);
43+
}
44+
45+
46+
@Override
47+
public int hashCode() {
48+
return getId().hashCode();
49+
}
3350
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
package com.azure.communication.common;
4+
5+
import java.util.Objects;
6+
7+
/**
8+
* The cloud that the identifier belongs to.
9+
*/
10+
public class CommunicationCloudEnvironment {
11+
private static final String PUBLIC_VALUE = "public";
12+
private static final String DOD_VALUE = "dod";
13+
private static final String GCCH_VALUE = "gcch";
14+
15+
private final String environmentValue;
16+
17+
/**
18+
* Create CommunicationCloudEnvironment with name string
19+
* @param environmentValue name of hte cloud environment
20+
*/
21+
public CommunicationCloudEnvironment(String environmentValue) {
22+
Objects.requireNonNull(environmentValue);
23+
this.environmentValue = environmentValue;
24+
}
25+
26+
static CommunicationCloudEnvironment fromModel(CommunicationCloudEnvironmentModel environmentModel) {
27+
return new CommunicationCloudEnvironment(environmentModel.toString());
28+
}
29+
30+
/**
31+
* Represent Azure public cloud
32+
*/
33+
public static final CommunicationCloudEnvironment PUBLIC = new CommunicationCloudEnvironment(PUBLIC_VALUE);
34+
35+
/**
36+
* Represent Azure Dod cloud
37+
*/
38+
public static final CommunicationCloudEnvironment DOD = new CommunicationCloudEnvironment(DOD_VALUE);
39+
40+
/**
41+
* Represent Azure Gcch cloud
42+
*/
43+
public static final CommunicationCloudEnvironment GCCH = new CommunicationCloudEnvironment(GCCH_VALUE);
44+
45+
@Override
46+
public boolean equals(Object that) {
47+
if (this == that) {
48+
return true;
49+
}
50+
return that != null && this.environmentValue.equals(that.toString());
51+
}
52+
53+
@Override
54+
public String toString() {
55+
return environmentValue;
56+
}
57+
58+
@Override
59+
public int hashCode() {
60+
return toString().hashCode();
61+
}
62+
63+
}
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+
package com.azure.communication.common;
4+
5+
class CommunicationCloudEnvironmentModel {
6+
7+
private static final String PUBLIC_VALUE = "public";
8+
private static final String DOD_VALUE = "dod";
9+
private static final String GCCH_VALUE = "gcch";
10+
11+
private final String environmentValue;
12+
13+
CommunicationCloudEnvironmentModel(String environmentValue) {
14+
java.util.Objects.requireNonNull(environmentValue);
15+
this.environmentValue = environmentValue;
16+
}
17+
18+
public static final CommunicationCloudEnvironmentModel PUBLIC = new CommunicationCloudEnvironmentModel(PUBLIC_VALUE);
19+
public static final CommunicationCloudEnvironmentModel DOD = new CommunicationCloudEnvironmentModel(DOD_VALUE);
20+
public static final CommunicationCloudEnvironmentModel GCCH = new CommunicationCloudEnvironmentModel(GCCH_VALUE);
21+
22+
@Override
23+
public boolean equals(Object that) {
24+
if (this == that) {
25+
return true;
26+
}
27+
28+
return that != null && this.environmentValue.equals(that.toString());
29+
}
30+
31+
@Override
32+
public String toString() {
33+
return environmentValue;
34+
}
35+
36+
@Override
37+
public int hashCode() {
38+
return toString().hashCode();
39+
}
40+
41+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@
66
* Common communication identifier for Communication Services
77
*/
88
public abstract class CommunicationIdentifier {
9+
/**
10+
* Get string representation of the identifier
11+
* @return string representation of the identifier
12+
*/
13+
public abstract String getId();
14+
915
}

sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationIdentifierKind.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3-
// Code generated by Microsoft (R) AutoRest Code Generator.
43

54
package com.azure.communication.common;
65

sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationIdentifierModel.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3-
// Code generated by Microsoft (R) AutoRest Code Generator.
43

54
package com.azure.communication.common;
65

@@ -14,7 +13,7 @@ public final class CommunicationIdentifierModel {
1413
* Kind of the communication identifier.
1514
*/
1615
@JsonProperty(value = "kind", required = true)
17-
private com.azure.communication.common.CommunicationIdentifierKind kind;
16+
private CommunicationIdentifierKind kind;
1817

1918
/*
2019
* Full Id of the identifier.
@@ -40,12 +39,14 @@ public final class CommunicationIdentifierModel {
4039
@JsonProperty(value = "isAnonymous")
4140
private Boolean isAnonymous;
4241

42+
private CommunicationCloudEnvironmentModel cloudEnvironmentModel;
43+
4344
/**
4445
* Get the kind property: Kind of the communication identifier.
4546
*
4647
* @return the kind value.
4748
*/
48-
public com.azure.communication.common.CommunicationIdentifierKind getKind() {
49+
public CommunicationIdentifierKind getKind() {
4950
return this.kind;
5051
}
5152

@@ -55,7 +56,7 @@ public com.azure.communication.common.CommunicationIdentifierKind getKind() {
5556
* @param kind the kind value to set.
5657
* @return the CommunicationIdentifierModel object itself.
5758
*/
58-
public CommunicationIdentifierModel setKind(com.azure.communication.common.CommunicationIdentifierKind kind) {
59+
public CommunicationIdentifierModel setKind(CommunicationIdentifierKind kind) {
5960
this.kind = kind;
6061
return this;
6162
}
@@ -139,4 +140,22 @@ public CommunicationIdentifierModel setIsAnonymous(Boolean isAnonymous) {
139140
this.isAnonymous = isAnonymous;
140141
return this;
141142
}
143+
144+
/**
145+
* Get the cloud environment model in which this identifier model is valid
146+
* @return the cloud environment model
147+
*/
148+
CommunicationCloudEnvironmentModel getCloudEnvironmentModel() {
149+
return this.cloudEnvironmentModel;
150+
}
151+
152+
/**
153+
* Set the cloud environment model in which this identifier model is valid
154+
* @param cloudEnvironmentModel the cloud environment model in which this identifier model is valid
155+
* @return the CommunicationIdentifierModel object itself.
156+
*/
157+
CommunicationIdentifierModel setCloudEnvironmentModel(CommunicationCloudEnvironmentModel cloudEnvironmentModel) {
158+
this.cloudEnvironmentModel = cloudEnvironmentModel;
159+
return this;
160+
}
142161
}

sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationIdentifierSerializer.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3-
// Code generated by Microsoft (R) AutoRest Code Generator.
43

54
package com.azure.communication.common;
65

@@ -23,12 +22,16 @@ public static CommunicationIdentifier deserialize(CommunicationIdentifierModel i
2322

2423
if (kind == CommunicationIdentifierKind.PHONE_NUMBER) {
2524
Objects.requireNonNull(identifier.getPhoneNumber());
26-
return new PhoneNumberIdentifier(identifier.getPhoneNumber());
25+
Objects.requireNonNull(identifier.getId());
26+
return new PhoneNumberIdentifier(identifier.getPhoneNumber()).setId(identifier.getId());
2727
}
2828

2929
if (kind == CommunicationIdentifierKind.MICROSOFT_TEAMS_USER) {
3030
Objects.requireNonNull(identifier.getMicrosoftTeamsUserId());
31-
return new MicrosoftTeamsUserIdentifier(identifier.getMicrosoftTeamsUserId(), identifier.isAnonymous());
31+
Objects.requireNonNull(identifier.getCloudEnvironmentModel());
32+
return new MicrosoftTeamsUserIdentifier(identifier.getMicrosoftTeamsUserId(), identifier.isAnonymous())
33+
.setId(identifier.getId())
34+
.setCloudEnvironment(CommunicationCloudEnvironment.fromModel(identifier.getCloudEnvironmentModel()));
3235
}
3336

3437
Objects.requireNonNull(id);
@@ -51,14 +54,18 @@ public static CommunicationIdentifierModel serialize(CommunicationIdentifier ide
5154
if (identifier instanceof PhoneNumberIdentifier) {
5255
return new CommunicationIdentifierModel()
5356
.setKind(CommunicationIdentifierKind.PHONE_NUMBER)
54-
.setPhoneNumber(((PhoneNumberIdentifier) identifier).getPhoneNumber());
57+
.setPhoneNumber(((PhoneNumberIdentifier) identifier).getPhoneNumber())
58+
.setId(identifier.getId());
5559
}
5660

5761
if (identifier instanceof MicrosoftTeamsUserIdentifier) {
62+
MicrosoftTeamsUserIdentifier teamsUserIdentifier = (MicrosoftTeamsUserIdentifier) identifier;
5863
return new CommunicationIdentifierModel()
5964
.setKind(CommunicationIdentifierKind.MICROSOFT_TEAMS_USER)
60-
.setMicrosoftTeamsUserId(((MicrosoftTeamsUserIdentifier) identifier).getUserId())
61-
.setIsAnonymous(((MicrosoftTeamsUserIdentifier) identifier).isAnonymous());
65+
.setMicrosoftTeamsUserId(teamsUserIdentifier.getUserId())
66+
.setIsAnonymous(teamsUserIdentifier.isAnonymous())
67+
.setId(teamsUserIdentifier.getId())
68+
.setCloudEnvironmentModel(new CommunicationCloudEnvironmentModel(teamsUserIdentifier.getCloudEnvironment().toString()));
6269
}
6370

6471
return new CommunicationIdentifierModel()

sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationUserIdentifier.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class CommunicationUserIdentifier extends CommunicationIdentifier {
1313

1414
/**
1515
* Creates a CommunicationUserIdentifier object
16-
*
16+
*
1717
* @param id the string identifier representing the identity
1818
* @throws IllegalArgumentException thrown if id parameter fail the validation.
1919
*/
@@ -24,10 +24,26 @@ public CommunicationUserIdentifier(String id) {
2424
this.id = id;
2525
}
2626

27-
/**
28-
* @return the string identifier representing the object identity
29-
*/
27+
@Override
3028
public String getId() {
3129
return id;
3230
}
31+
32+
@Override
33+
public boolean equals(Object that) {
34+
if (this == that) {
35+
return true;
36+
}
37+
38+
if (!(that instanceof CommunicationUserIdentifier)) {
39+
return false;
40+
}
41+
42+
return ((CommunicationUserIdentifier) that).getId().equals(id);
43+
}
44+
45+
@Override
46+
public int hashCode() {
47+
return getId().hashCode();
48+
}
3349
}

0 commit comments

Comments
 (0)