-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Communication]: Add identifier model and serializer (#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 <[email protected]>
- Loading branch information
1 parent
ddd9976
commit f707bc7
Showing
8 changed files
with
434 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...tion-common/src/main/java/com/azure/communication/common/CommunicationIdentifierKind.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// Code generated by Microsoft (R) AutoRest Code Generator. | ||
|
||
package com.azure.communication.common; | ||
|
||
import com.azure.core.util.ExpandableStringEnum; | ||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import java.util.Collection; | ||
|
||
/** Defines values for CommunicationIdentifierKind. */ | ||
public final class CommunicationIdentifierKind extends ExpandableStringEnum<CommunicationIdentifierKind> { | ||
/** Static value unknown for CommunicationIdentifierKind. */ | ||
public static final CommunicationIdentifierKind UNKNOWN = fromString("unknown"); | ||
|
||
/** Static value communicationUser for CommunicationIdentifierKind. */ | ||
public static final CommunicationIdentifierKind COMMUNICATION_USER = fromString("communicationUser"); | ||
|
||
/** Static value phoneNumber for CommunicationIdentifierKind. */ | ||
public static final CommunicationIdentifierKind PHONE_NUMBER = fromString("phoneNumber"); | ||
|
||
/** Static value callingApplication for CommunicationIdentifierKind. */ | ||
public static final CommunicationIdentifierKind CALLING_APPLICATION = fromString("callingApplication"); | ||
|
||
/** Static value microsoftTeamsUser for CommunicationIdentifierKind. */ | ||
public static final CommunicationIdentifierKind MICROSOFT_TEAMS_USER = fromString("microsoftTeamsUser"); | ||
|
||
/** | ||
* Creates or finds a CommunicationIdentifierKind from its string representation. | ||
* | ||
* @param name a name to look for. | ||
* @return the corresponding CommunicationIdentifierKind. | ||
*/ | ||
@JsonCreator | ||
public static CommunicationIdentifierKind fromString(String name) { | ||
return fromString(name, CommunicationIdentifierKind.class); | ||
} | ||
|
||
/** @return known CommunicationIdentifierKind values. */ | ||
public static Collection<CommunicationIdentifierKind> values() { | ||
return values(CommunicationIdentifierKind.class); | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
142
...ion-common/src/main/java/com/azure/communication/common/CommunicationIdentifierModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// Code generated by Microsoft (R) AutoRest Code Generator. | ||
|
||
package com.azure.communication.common; | ||
|
||
import com.azure.core.annotation.Fluent; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** The CommunicationIdentifierModel model. */ | ||
@Fluent | ||
public final class CommunicationIdentifierModel { | ||
/* | ||
* Kind of the communication identifier. | ||
*/ | ||
@JsonProperty(value = "kind", required = true) | ||
private com.azure.communication.common.CommunicationIdentifierKind kind; | ||
|
||
/* | ||
* Full Id of the identifier. | ||
*/ | ||
@JsonProperty(value = "id") | ||
private String id; | ||
|
||
/* | ||
* The phone number in E.164 format. | ||
*/ | ||
@JsonProperty(value = "phoneNumber") | ||
private String phoneNumber; | ||
|
||
/* | ||
* The AAD object Id of the Microsoft Teams user. | ||
*/ | ||
@JsonProperty(value = "microsoftTeamsUserId") | ||
private String microsoftTeamsUserId; | ||
|
||
/* | ||
* True if the identifier is anonymous. | ||
*/ | ||
@JsonProperty(value = "isAnonymous") | ||
private Boolean isAnonymous; | ||
|
||
/** | ||
* Get the kind property: Kind of the communication identifier. | ||
* | ||
* @return the kind value. | ||
*/ | ||
public com.azure.communication.common.CommunicationIdentifierKind getKind() { | ||
return this.kind; | ||
} | ||
|
||
/** | ||
* Set the kind property: Kind of the communication identifier. | ||
* | ||
* @param kind the kind value to set. | ||
* @return the CommunicationIdentifierModel object itself. | ||
*/ | ||
public CommunicationIdentifierModel setKind(com.azure.communication.common.CommunicationIdentifierKind kind) { | ||
this.kind = kind; | ||
return this; | ||
} | ||
|
||
/** | ||
* Get the id property: Full Id of the identifier. | ||
* | ||
* @return the id value. | ||
*/ | ||
public String getId() { | ||
return this.id; | ||
} | ||
|
||
/** | ||
* Set the id property: Full Id of the identifier. | ||
* | ||
* @param id the id value to set. | ||
* @return the CommunicationIdentifierModel object itself. | ||
*/ | ||
public CommunicationIdentifierModel setId(String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
/** | ||
* Get the phoneNumber property: The phone number in E.164 format. | ||
* | ||
* @return the phoneNumber value. | ||
*/ | ||
public String getPhoneNumber() { | ||
return this.phoneNumber; | ||
} | ||
|
||
/** | ||
* Set the phoneNumber property: The phone number in E.164 format. | ||
* | ||
* @param phoneNumber the phoneNumber value to set. | ||
* @return the CommunicationIdentifierModel object itself. | ||
*/ | ||
public CommunicationIdentifierModel setPhoneNumber(String phoneNumber) { | ||
this.phoneNumber = phoneNumber; | ||
return this; | ||
} | ||
|
||
/** | ||
* Get the microsoftTeamsUserId property: The AAD object Id of the Microsoft Teams user. | ||
* | ||
* @return the microsoftTeamsUserId value. | ||
*/ | ||
public String getMicrosoftTeamsUserId() { | ||
return this.microsoftTeamsUserId; | ||
} | ||
|
||
/** | ||
* Set the microsoftTeamsUserId property: The AAD object Id of the Microsoft Teams user. | ||
* | ||
* @param microsoftTeamsUserId the microsoftTeamsUserId value to set. | ||
* @return the CommunicationIdentifierModel object itself. | ||
*/ | ||
public CommunicationIdentifierModel setMicrosoftTeamsUserId(String microsoftTeamsUserId) { | ||
this.microsoftTeamsUserId = microsoftTeamsUserId; | ||
return this; | ||
} | ||
|
||
/** | ||
* Get the isAnonymous property: True if the identifier is anonymous. | ||
* | ||
* @return the isAnonymous value. | ||
*/ | ||
public Boolean isAnonymous() { | ||
return this.isAnonymous; | ||
} | ||
|
||
/** | ||
* Set the isAnonymous property: True if the identifier is anonymous. | ||
* | ||
* @param isAnonymous the isAnonymous value to set. | ||
* @return the CommunicationIdentifierModel object itself. | ||
*/ | ||
public CommunicationIdentifierModel setIsAnonymous(Boolean isAnonymous) { | ||
this.isAnonymous = isAnonymous; | ||
return this; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...ommon/src/main/java/com/azure/communication/common/CommunicationIdentifierSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// Code generated by Microsoft (R) AutoRest Code Generator. | ||
|
||
package com.azure.communication.common; | ||
|
||
import java.util.Objects; | ||
|
||
class CommunicationIdentifierSerializer { | ||
public static CommunicationIdentifier deserialize(CommunicationIdentifierModel identifier) { | ||
String id = identifier.getId(); | ||
CommunicationIdentifierKind kind = identifier.getKind(); | ||
|
||
if (kind == CommunicationIdentifierKind.COMMUNICATION_USER) { | ||
Objects.requireNonNull(id); | ||
return new CommunicationUserIdentifier(id); | ||
} | ||
|
||
if (kind == CommunicationIdentifierKind.CALLING_APPLICATION) { | ||
Objects.requireNonNull(id); | ||
return new CallingApplicationIdentifier(id); | ||
} | ||
|
||
if (kind == CommunicationIdentifierKind.PHONE_NUMBER) { | ||
Objects.requireNonNull(identifier.getPhoneNumber()); | ||
return new PhoneNumberIdentifier(identifier.getPhoneNumber()); | ||
} | ||
|
||
if (kind == CommunicationIdentifierKind.MICROSOFT_TEAMS_USER) { | ||
Objects.requireNonNull(identifier.getMicrosoftTeamsUserId()); | ||
return new MicrosoftTeamsUserIdentifier(identifier.getMicrosoftTeamsUserId(), identifier.isAnonymous()); | ||
} | ||
|
||
Objects.requireNonNull(id); | ||
return new UnknownIdentifier(id); | ||
} | ||
|
||
public static CommunicationIdentifierModel serialize(CommunicationIdentifier identifier) { | ||
if (identifier instanceof CommunicationUserIdentifier) { | ||
return new CommunicationIdentifierModel() | ||
.setKind(CommunicationIdentifierKind.COMMUNICATION_USER) | ||
.setId(((CommunicationUserIdentifier) identifier).getId()); | ||
} | ||
|
||
if (identifier instanceof CallingApplicationIdentifier) { | ||
return new CommunicationIdentifierModel() | ||
.setKind(CommunicationIdentifierKind.CALLING_APPLICATION) | ||
.setId(((CallingApplicationIdentifier) identifier).getId()); | ||
} | ||
|
||
if (identifier instanceof PhoneNumberIdentifier) { | ||
return new CommunicationIdentifierModel() | ||
.setKind(CommunicationIdentifierKind.PHONE_NUMBER) | ||
.setPhoneNumber(((PhoneNumberIdentifier) identifier).getPhoneNumber()); | ||
} | ||
|
||
if (identifier instanceof MicrosoftTeamsUserIdentifier) { | ||
return new CommunicationIdentifierModel() | ||
.setKind(CommunicationIdentifierKind.MICROSOFT_TEAMS_USER) | ||
.setMicrosoftTeamsUserId(((MicrosoftTeamsUserIdentifier) identifier).getUserId()) | ||
.setIsAnonymous(((MicrosoftTeamsUserIdentifier) identifier).isAnonymous()); | ||
} | ||
|
||
return new CommunicationIdentifierModel() | ||
.setKind(CommunicationIdentifierKind.UNKNOWN) | ||
.setId(((UnknownIdentifier) identifier).getId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.