Skip to content

Commit f707bc7

Browse files
JianpingChenJP Chen
andauthored
[Communication]: Add identifier model and serializer (Azure#18685)
* Add CommunicationIdentifierModel to models * Move IdentifierModel to common and add serializer * Add unit tests * Fix code styling issues * Rename PhoneNumberIdentifier getValue to getPhoneNumber Co-authored-by: JP Chen <jiach@microsoft.com>
1 parent ddd9976 commit f707bc7

File tree

8 files changed

+434
-27
lines changed

8 files changed

+434
-27
lines changed

sdk/communication/azure-communication-administration/src/main/java/com/azure/communication/administration/PhoneNumberAsyncClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ Mono<Response<UpdateNumberCapabilitiesResponse>> updateCapabilitiesWithResponse(
220220
Map<String, NumberUpdateCapabilities> capabilitiesMap = new HashMap<>();
221221
for (Map.Entry<PhoneNumberIdentifier, NumberUpdateCapabilities> entry
222222
: phoneNumberCapabilitiesUpdate.entrySet()) {
223-
capabilitiesMap.put(entry.getKey().getValue(), entry.getValue());
223+
capabilitiesMap.put(entry.getKey().getPhoneNumber(), entry.getValue());
224224
}
225225
UpdateNumberCapabilitiesRequest updateNumberCapabilitiesRequest = new UpdateNumberCapabilitiesRequest();
226226
updateNumberCapabilitiesRequest.setPhoneNumberCapabilitiesUpdate(capabilitiesMap);
@@ -289,7 +289,7 @@ Mono<Response<NumberConfigurationResponse>> getNumberConfigurationWithResponse(
289289
try {
290290
Objects.requireNonNull(phoneNumber, "'phoneNumber' cannot be null.");
291291
NumberConfigurationPhoneNumber configurationPhoneNumber = new NumberConfigurationPhoneNumber();
292-
configurationPhoneNumber.setPhoneNumber(phoneNumber.getValue());
292+
configurationPhoneNumber.setPhoneNumber(phoneNumber.getPhoneNumber());
293293

294294
if (context == null) {
295295
return phoneNumberAdministrations.getNumberConfigurationWithResponseAsync(
@@ -335,7 +335,7 @@ Mono<Response<Void>> configureNumberWithResponse(
335335
Objects.requireNonNull(pstnConfiguration, "'pstnConfiguration' cannot be null.");
336336

337337
NumberConfiguration numberConfiguration = new NumberConfiguration();
338-
numberConfiguration.setPhoneNumber(phoneNumber.getValue()).setPstnConfiguration(pstnConfiguration);
338+
numberConfiguration.setPhoneNumber(phoneNumber.getPhoneNumber()).setPstnConfiguration(pstnConfiguration);
339339

340340
if (context == null) {
341341
return phoneNumberAdministrations.configureNumberWithResponseAsync(numberConfiguration);
@@ -373,7 +373,7 @@ Mono<Response<Void>> unconfigureNumberWithResponse(PhoneNumberIdentifier phoneNu
373373
try {
374374
Objects.requireNonNull(phoneNumber, "'phoneNumber' cannot be null.");
375375
NumberConfigurationPhoneNumber configurationPhoneNumber = new NumberConfigurationPhoneNumber();
376-
configurationPhoneNumber.setPhoneNumber(phoneNumber.getValue());
376+
configurationPhoneNumber.setPhoneNumber(phoneNumber.getPhoneNumber());
377377

378378
if (context == null) {
379379
return phoneNumberAdministrations.unconfigureNumberWithResponseAsync(configurationPhoneNumber);
@@ -559,7 +559,7 @@ private Mono<Response<ReleaseResponse>> releasePhoneNumbersWithResponse(
559559

560560
List<String> phoneNumberStrings = phoneNumbers
561561
.stream()
562-
.map(PhoneNumberIdentifier::getValue)
562+
.map(PhoneNumberIdentifier::getPhoneNumber)
563563
.collect(Collectors.toList());
564564
ReleaseRequest releaseRequest = new ReleaseRequest();
565565
releaseRequest.setPhoneNumbers(phoneNumberStrings);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
// Code generated by Microsoft (R) AutoRest Code Generator.
4+
5+
package com.azure.communication.common;
6+
7+
import com.azure.core.util.ExpandableStringEnum;
8+
import com.fasterxml.jackson.annotation.JsonCreator;
9+
import java.util.Collection;
10+
11+
/** Defines values for CommunicationIdentifierKind. */
12+
public final class CommunicationIdentifierKind extends ExpandableStringEnum<CommunicationIdentifierKind> {
13+
/** Static value unknown for CommunicationIdentifierKind. */
14+
public static final CommunicationIdentifierKind UNKNOWN = fromString("unknown");
15+
16+
/** Static value communicationUser for CommunicationIdentifierKind. */
17+
public static final CommunicationIdentifierKind COMMUNICATION_USER = fromString("communicationUser");
18+
19+
/** Static value phoneNumber for CommunicationIdentifierKind. */
20+
public static final CommunicationIdentifierKind PHONE_NUMBER = fromString("phoneNumber");
21+
22+
/** Static value callingApplication for CommunicationIdentifierKind. */
23+
public static final CommunicationIdentifierKind CALLING_APPLICATION = fromString("callingApplication");
24+
25+
/** Static value microsoftTeamsUser for CommunicationIdentifierKind. */
26+
public static final CommunicationIdentifierKind MICROSOFT_TEAMS_USER = fromString("microsoftTeamsUser");
27+
28+
/**
29+
* Creates or finds a CommunicationIdentifierKind from its string representation.
30+
*
31+
* @param name a name to look for.
32+
* @return the corresponding CommunicationIdentifierKind.
33+
*/
34+
@JsonCreator
35+
public static CommunicationIdentifierKind fromString(String name) {
36+
return fromString(name, CommunicationIdentifierKind.class);
37+
}
38+
39+
/** @return known CommunicationIdentifierKind values. */
40+
public static Collection<CommunicationIdentifierKind> values() {
41+
return values(CommunicationIdentifierKind.class);
42+
}
43+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
// Code generated by Microsoft (R) AutoRest Code Generator.
4+
5+
package com.azure.communication.common;
6+
7+
import com.azure.core.annotation.Fluent;
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
10+
/** The CommunicationIdentifierModel model. */
11+
@Fluent
12+
public final class CommunicationIdentifierModel {
13+
/*
14+
* Kind of the communication identifier.
15+
*/
16+
@JsonProperty(value = "kind", required = true)
17+
private com.azure.communication.common.CommunicationIdentifierKind kind;
18+
19+
/*
20+
* Full Id of the identifier.
21+
*/
22+
@JsonProperty(value = "id")
23+
private String id;
24+
25+
/*
26+
* The phone number in E.164 format.
27+
*/
28+
@JsonProperty(value = "phoneNumber")
29+
private String phoneNumber;
30+
31+
/*
32+
* The AAD object Id of the Microsoft Teams user.
33+
*/
34+
@JsonProperty(value = "microsoftTeamsUserId")
35+
private String microsoftTeamsUserId;
36+
37+
/*
38+
* True if the identifier is anonymous.
39+
*/
40+
@JsonProperty(value = "isAnonymous")
41+
private Boolean isAnonymous;
42+
43+
/**
44+
* Get the kind property: Kind of the communication identifier.
45+
*
46+
* @return the kind value.
47+
*/
48+
public com.azure.communication.common.CommunicationIdentifierKind getKind() {
49+
return this.kind;
50+
}
51+
52+
/**
53+
* Set the kind property: Kind of the communication identifier.
54+
*
55+
* @param kind the kind value to set.
56+
* @return the CommunicationIdentifierModel object itself.
57+
*/
58+
public CommunicationIdentifierModel setKind(com.azure.communication.common.CommunicationIdentifierKind kind) {
59+
this.kind = kind;
60+
return this;
61+
}
62+
63+
/**
64+
* Get the id property: Full Id of the identifier.
65+
*
66+
* @return the id value.
67+
*/
68+
public String getId() {
69+
return this.id;
70+
}
71+
72+
/**
73+
* Set the id property: Full Id of the identifier.
74+
*
75+
* @param id the id value to set.
76+
* @return the CommunicationIdentifierModel object itself.
77+
*/
78+
public CommunicationIdentifierModel setId(String id) {
79+
this.id = id;
80+
return this;
81+
}
82+
83+
/**
84+
* Get the phoneNumber property: The phone number in E.164 format.
85+
*
86+
* @return the phoneNumber value.
87+
*/
88+
public String getPhoneNumber() {
89+
return this.phoneNumber;
90+
}
91+
92+
/**
93+
* Set the phoneNumber property: The phone number in E.164 format.
94+
*
95+
* @param phoneNumber the phoneNumber value to set.
96+
* @return the CommunicationIdentifierModel object itself.
97+
*/
98+
public CommunicationIdentifierModel setPhoneNumber(String phoneNumber) {
99+
this.phoneNumber = phoneNumber;
100+
return this;
101+
}
102+
103+
/**
104+
* Get the microsoftTeamsUserId property: The AAD object Id of the Microsoft Teams user.
105+
*
106+
* @return the microsoftTeamsUserId value.
107+
*/
108+
public String getMicrosoftTeamsUserId() {
109+
return this.microsoftTeamsUserId;
110+
}
111+
112+
/**
113+
* Set the microsoftTeamsUserId property: The AAD object Id of the Microsoft Teams user.
114+
*
115+
* @param microsoftTeamsUserId the microsoftTeamsUserId value to set.
116+
* @return the CommunicationIdentifierModel object itself.
117+
*/
118+
public CommunicationIdentifierModel setMicrosoftTeamsUserId(String microsoftTeamsUserId) {
119+
this.microsoftTeamsUserId = microsoftTeamsUserId;
120+
return this;
121+
}
122+
123+
/**
124+
* Get the isAnonymous property: True if the identifier is anonymous.
125+
*
126+
* @return the isAnonymous value.
127+
*/
128+
public Boolean isAnonymous() {
129+
return this.isAnonymous;
130+
}
131+
132+
/**
133+
* Set the isAnonymous property: True if the identifier is anonymous.
134+
*
135+
* @param isAnonymous the isAnonymous value to set.
136+
* @return the CommunicationIdentifierModel object itself.
137+
*/
138+
public CommunicationIdentifierModel setIsAnonymous(Boolean isAnonymous) {
139+
this.isAnonymous = isAnonymous;
140+
return this;
141+
}
142+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
// Code generated by Microsoft (R) AutoRest Code Generator.
4+
5+
package com.azure.communication.common;
6+
7+
import java.util.Objects;
8+
9+
class CommunicationIdentifierSerializer {
10+
public static CommunicationIdentifier deserialize(CommunicationIdentifierModel identifier) {
11+
String id = identifier.getId();
12+
CommunicationIdentifierKind kind = identifier.getKind();
13+
14+
if (kind == CommunicationIdentifierKind.COMMUNICATION_USER) {
15+
Objects.requireNonNull(id);
16+
return new CommunicationUserIdentifier(id);
17+
}
18+
19+
if (kind == CommunicationIdentifierKind.CALLING_APPLICATION) {
20+
Objects.requireNonNull(id);
21+
return new CallingApplicationIdentifier(id);
22+
}
23+
24+
if (kind == CommunicationIdentifierKind.PHONE_NUMBER) {
25+
Objects.requireNonNull(identifier.getPhoneNumber());
26+
return new PhoneNumberIdentifier(identifier.getPhoneNumber());
27+
}
28+
29+
if (kind == CommunicationIdentifierKind.MICROSOFT_TEAMS_USER) {
30+
Objects.requireNonNull(identifier.getMicrosoftTeamsUserId());
31+
return new MicrosoftTeamsUserIdentifier(identifier.getMicrosoftTeamsUserId(), identifier.isAnonymous());
32+
}
33+
34+
Objects.requireNonNull(id);
35+
return new UnknownIdentifier(id);
36+
}
37+
38+
public static CommunicationIdentifierModel serialize(CommunicationIdentifier identifier) {
39+
if (identifier instanceof CommunicationUserIdentifier) {
40+
return new CommunicationIdentifierModel()
41+
.setKind(CommunicationIdentifierKind.COMMUNICATION_USER)
42+
.setId(((CommunicationUserIdentifier) identifier).getId());
43+
}
44+
45+
if (identifier instanceof CallingApplicationIdentifier) {
46+
return new CommunicationIdentifierModel()
47+
.setKind(CommunicationIdentifierKind.CALLING_APPLICATION)
48+
.setId(((CallingApplicationIdentifier) identifier).getId());
49+
}
50+
51+
if (identifier instanceof PhoneNumberIdentifier) {
52+
return new CommunicationIdentifierModel()
53+
.setKind(CommunicationIdentifierKind.PHONE_NUMBER)
54+
.setPhoneNumber(((PhoneNumberIdentifier) identifier).getPhoneNumber());
55+
}
56+
57+
if (identifier instanceof MicrosoftTeamsUserIdentifier) {
58+
return new CommunicationIdentifierModel()
59+
.setKind(CommunicationIdentifierKind.MICROSOFT_TEAMS_USER)
60+
.setMicrosoftTeamsUserId(((MicrosoftTeamsUserIdentifier) identifier).getUserId())
61+
.setIsAnonymous(((MicrosoftTeamsUserIdentifier) identifier).isAnonymous());
62+
}
63+
64+
return new CommunicationIdentifierModel()
65+
.setKind(CommunicationIdentifierKind.UNKNOWN)
66+
.setId(((UnknownIdentifier) identifier).getId());
67+
}
68+
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
*/
1010
public class PhoneNumberIdentifier extends CommunicationIdentifier {
1111

12-
private final String value;
12+
private final String phoneNumber;
1313

1414
/**
1515
* Creates a PhoneNumberIdentifier object
16-
*
16+
*
1717
* @param phoneNumber the string identifier representing the PhoneNumber in E.164 format.
1818
* E.164 is a phone number formatted as +[CountryCode][AreaCode][LocalNumber] eg. "+18005555555"
1919
* @throws IllegalArgumentException thrown if phoneNumber parameter fail the validation.
@@ -22,13 +22,13 @@ public PhoneNumberIdentifier(String phoneNumber) {
2222
if (CoreUtils.isNullOrEmpty(phoneNumber)) {
2323
throw new IllegalArgumentException("The initialization parameter [phoneNumber] cannot be null to empty.");
2424
}
25-
this.value = phoneNumber;
25+
this.phoneNumber = phoneNumber;
2626
}
2727

2828
/**
2929
* @return the string identifier representing the object identity
3030
*/
31-
public String getValue() {
32-
return value;
31+
public String getPhoneNumber() {
32+
return phoneNumber;
3333
}
3434
}

0 commit comments

Comments
 (0)