From 07377d304bcde55c077a9010f78637a116d07cdb Mon Sep 17 00:00:00 2001 From: Inderpal Singh Aulakh <73618019+iaulakh@users.noreply.github.com> Date: Tue, 2 Aug 2022 05:41:26 -0700 Subject: [PATCH 1/5] [CommunicationIdentifier] Added setter for rawId --- .../common/CommunicationIdentifier.java | 18 ++++++++++++++---- .../common/CommunicationUserIdentifier.java | 15 ++++++++++++++- .../common/MicrosoftTeamsUserIdentifier.java | 14 ++++++++------ .../common/PhoneNumberIdentifier.java | 6 ++++-- .../common/UnknownIdentifier.java | 15 ++++++++++++++- .../common/CommunicationIdentifierTests.java | 2 +- 6 files changed, 55 insertions(+), 15 deletions(-) diff --git a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationIdentifier.java b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationIdentifier.java index dc1b0f081eac1..5aa72a2e283bd 100644 --- a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationIdentifier.java +++ b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationIdentifier.java @@ -8,10 +8,8 @@ * Common communication identifier for Communication Services */ public abstract class CommunicationIdentifier { - /** - * encoded format for identifiers to store in databases or as stable keys in general. - */ - protected String rawId; + + private String rawId; /** * When storing rawIds, use this function to restore the identifier that was encoded in the rawId. @@ -61,6 +59,18 @@ public String getRawId() { return rawId; } + /** + * 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 CommunicationIdentifier object itself + */ + public CommunicationIdentifier setRawId(String rawId) { + this.rawId = rawId; + return this; + } + @Override public boolean equals(Object that) { if (this == that) { diff --git a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationUserIdentifier.java b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationUserIdentifier.java index a44e7356b8205..564a14ce4cff2 100644 --- a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationUserIdentifier.java +++ b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationUserIdentifier.java @@ -22,7 +22,7 @@ public CommunicationUserIdentifier(String id) { throw new IllegalArgumentException("The initialization parameter [id] cannot be null or empty."); } this.id = id; - this.rawId = id; + this.setRawId(id); } /** @@ -34,6 +34,19 @@ public String getId() { return id; } + /** + * 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 CommunicationUserIdentifier object itself + */ + @Override + public CommunicationUserIdentifier setRawId(String rawId) { + super.setRawId(rawId); + return this; + } + @Override public boolean equals(Object that) { if (this == that) { diff --git a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/MicrosoftTeamsUserIdentifier.java b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/MicrosoftTeamsUserIdentifier.java index a50315bce4dce..7b1adb82169e4 100644 --- a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/MicrosoftTeamsUserIdentifier.java +++ b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/MicrosoftTeamsUserIdentifier.java @@ -81,12 +81,14 @@ public MicrosoftTeamsUserIdentifier setCloudEnvironment(CommunicationCloudEnviro /** * 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 CommunicationIdentifier object itself + * @return MicrosoftTeamsUserIdentifier object itself */ + @Override public MicrosoftTeamsUserIdentifier setRawId(String rawId) { - this.rawId = rawId; + super.setRawId(rawId); rawIdSet = true; return this; } @@ -124,13 +126,13 @@ public int hashCode() { private void generateRawId() { if (!rawIdSet) { if (this.isAnonymous) { - this.rawId = "8:teamsvisitor:" + this.userId; + this.setRawId("8:teamsvisitor:" + this.userId); } else if (cloudEnvironment.equals(CommunicationCloudEnvironment.DOD)) { - this.rawId = "8:dod:" + this.userId; + this.setRawId("8:dod:" + this.userId); } else if (cloudEnvironment.equals(CommunicationCloudEnvironment.GCCH)) { - this.rawId = "8:gcch:" + this.userId; + this.setRawId("8:gcch:" + this.userId); } else { - this.rawId = "8:orgid:" + this.userId; + this.setRawId("8:orgid:" + this.userId); } } } diff --git a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/PhoneNumberIdentifier.java b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/PhoneNumberIdentifier.java index fe5dd6b6f1ed7..58146089c55f6 100644 --- a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/PhoneNumberIdentifier.java +++ b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/PhoneNumberIdentifier.java @@ -23,7 +23,7 @@ public PhoneNumberIdentifier(String phoneNumber) { throw new IllegalArgumentException("The initialization parameter [phoneNumber] cannot be null to empty."); } this.phoneNumber = phoneNumber; - this.rawId = "4:" + phoneNumber.replaceAll("^[+]", ""); + this.setRawId("4:" + phoneNumber.replaceAll("^[+]", "")); } /** @@ -35,12 +35,14 @@ public String getPhoneNumber() { /** * 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 PhoneNumberIdentifier object itself */ + @Override public PhoneNumberIdentifier setRawId(String rawId) { - this.rawId = rawId; + super.setRawId(rawId); return this; } diff --git a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java index 4522400d1be5b..d68e283208dd0 100644 --- a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java +++ b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java @@ -22,7 +22,7 @@ public UnknownIdentifier(String id) { throw new IllegalArgumentException("The initialization parameter [id] cannot be null or empty."); } this.id = id; - this.rawId = id; + this.setRawId(id); } /** @@ -34,6 +34,19 @@ public String getId() { return id; } + /** + * 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 UnknownIdentifier object itself + */ + @Override + public UnknownIdentifier setRawId(String rawId) { + super.setRawId(rawId); + return this; + } + @Override public boolean equals(Object that) { if (this == that) { diff --git a/sdk/communication/azure-communication-common/src/test/java/com/azure/communication/common/CommunicationIdentifierTests.java b/sdk/communication/azure-communication-common/src/test/java/com/azure/communication/common/CommunicationIdentifierTests.java index aff4c960d601a..e204ff3624fc5 100644 --- a/sdk/communication/azure-communication-common/src/test/java/com/azure/communication/common/CommunicationIdentifierTests.java +++ b/sdk/communication/azure-communication-common/src/test/java/com/azure/communication/common/CommunicationIdentifierTests.java @@ -126,7 +126,7 @@ public void rawIdStaysTheSameAfterConversionToIdentifierAndBack() { } private void assertRawId(CommunicationIdentifier identifier, String expectedRawId) { - assertEquals(identifier.rawId, expectedRawId); + assertEquals(identifier.getRawId(), expectedRawId); } private void assertIdentifier(String rawId, CommunicationIdentifier expectedIdentifier) { From e127be561d1c8f734e73c4a5b189721a7f10f569 Mon Sep 17 00:00:00 2001 From: Inderpal Singh Aulakh <73618019+iaulakh@users.noreply.github.com> Date: Tue, 2 Aug 2022 06:08:33 -0700 Subject: [PATCH 2/5] [refactor] correct call to super class to set rawId --- .../common/MicrosoftTeamsUserIdentifier.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/MicrosoftTeamsUserIdentifier.java b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/MicrosoftTeamsUserIdentifier.java index 7b1adb82169e4..03e8d94af66de 100644 --- a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/MicrosoftTeamsUserIdentifier.java +++ b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/MicrosoftTeamsUserIdentifier.java @@ -126,13 +126,13 @@ public int hashCode() { private void generateRawId() { if (!rawIdSet) { if (this.isAnonymous) { - this.setRawId("8:teamsvisitor:" + this.userId); + super.setRawId("8:teamsvisitor:" + this.userId); } else if (cloudEnvironment.equals(CommunicationCloudEnvironment.DOD)) { - this.setRawId("8:dod:" + this.userId); + super.setRawId("8:dod:" + this.userId); } else if (cloudEnvironment.equals(CommunicationCloudEnvironment.GCCH)) { - this.setRawId("8:gcch:" + this.userId); + super.setRawId("8:gcch:" + this.userId); } else { - this.setRawId("8:orgid:" + this.userId); + super.setRawId("8:orgid:" + this.userId); } } } From 00380267a374be70e8ba2eeadc4c0ca9608ffd16 Mon Sep 17 00:00:00 2001 From: Inderpal Singh Aulakh <73618019+iaulakh@users.noreply.github.com> Date: Tue, 2 Aug 2022 13:49:53 -0700 Subject: [PATCH 3/5] [Refactor] make setRawId protected except for MicrosoftTeam, PhoneNumber Identifier --- .../com/azure/communication/common/CommunicationIdentifier.java | 2 +- .../azure/communication/common/CommunicationUserIdentifier.java | 2 +- .../java/com/azure/communication/common/UnknownIdentifier.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationIdentifier.java b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationIdentifier.java index 5aa72a2e283bd..e1944ff6c3510 100644 --- a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationIdentifier.java +++ b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationIdentifier.java @@ -66,7 +66,7 @@ public String getRawId() { * @param rawId full id of the identifier * @return CommunicationIdentifier object itself */ - public CommunicationIdentifier setRawId(String rawId) { + protected CommunicationIdentifier setRawId(String rawId) { this.rawId = rawId; return this; } diff --git a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationUserIdentifier.java b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationUserIdentifier.java index 564a14ce4cff2..2896ecd0b1743 100644 --- a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationUserIdentifier.java +++ b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CommunicationUserIdentifier.java @@ -42,7 +42,7 @@ public String getId() { * @return CommunicationUserIdentifier object itself */ @Override - public CommunicationUserIdentifier setRawId(String rawId) { + protected CommunicationUserIdentifier setRawId(String rawId) { super.setRawId(rawId); return this; } diff --git a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java index d68e283208dd0..2c5b5d1dcee1f 100644 --- a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java +++ b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java @@ -17,7 +17,7 @@ public final class UnknownIdentifier extends CommunicationIdentifier { * @param id the string identifier representing the identity * @throws IllegalArgumentException thrown if id parameter fail the validation. */ - public UnknownIdentifier(String id) { + protected UnknownIdentifier(String id) { if (CoreUtils.isNullOrEmpty(id)) { throw new IllegalArgumentException("The initialization parameter [id] cannot be null or empty."); } From 237c60c9a4b2a9b9a3653ee8728b8f951fc55146 Mon Sep 17 00:00:00 2001 From: Inderpal Singh Aulakh <73618019+iaulakh@users.noreply.github.com> Date: Wed, 3 Aug 2022 08:56:56 -0700 Subject: [PATCH 4/5] Update UnknownIdentifier.java --- .../java/com/azure/communication/common/UnknownIdentifier.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java index 2c5b5d1dcee1f..d68e283208dd0 100644 --- a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java +++ b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java @@ -17,7 +17,7 @@ public final class UnknownIdentifier extends CommunicationIdentifier { * @param id the string identifier representing the identity * @throws IllegalArgumentException thrown if id parameter fail the validation. */ - protected UnknownIdentifier(String id) { + public UnknownIdentifier(String id) { if (CoreUtils.isNullOrEmpty(id)) { throw new IllegalArgumentException("The initialization parameter [id] cannot be null or empty."); } From af2ae2208e062174920f873d41bcbab62dbd902a Mon Sep 17 00:00:00 2001 From: Inderpal Singh Aulakh <73618019+iaulakh@users.noreply.github.com> Date: Wed, 3 Aug 2022 11:02:15 -0700 Subject: [PATCH 5/5] [Refactor] make rawID protected --- .../java/com/azure/communication/common/UnknownIdentifier.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java index d68e283208dd0..012a411ea5344 100644 --- a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java +++ b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/UnknownIdentifier.java @@ -42,7 +42,7 @@ public String getId() { * @return UnknownIdentifier object itself */ @Override - public UnknownIdentifier setRawId(String rawId) { + protected UnknownIdentifier setRawId(String rawId) { super.setRawId(rawId); return this; }