Skip to content

Commit

Permalink
[Communication]: Add CloudEnvironment and optional full Id (Azure#18766)
Browse files Browse the repository at this point in the history
* Add CloudEnvironment

* Remove MRI from test constants

Co-authored-by: JP Chen <jiach@microsoft.com>
  • Loading branch information
JianpingChen and JP Chen authored Jan 22, 2021
1 parent 4fcc209 commit d90271c
Show file tree
Hide file tree
Showing 13 changed files with 413 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CallingApplicationIdentifier extends CommunicationIdentifier {

/**
* Creates a CallingApplicationIdentifier object
*
*
* @param id the string identifier representing the identity
* @throws IllegalArgumentException thrown if id parameter fail the validation.
*/
Expand All @@ -24,10 +24,27 @@ public CallingApplicationIdentifier(String id) {
this.id = id;
}

/**
* @return the string identifier representing the object identity
*/
@Override
public String getId() {
return id;
}

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

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

return ((CallingApplicationIdentifier) that).getId().equals(id);
}


@Override
public int hashCode() {
return getId().hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.communication.common;

import java.util.Objects;

/**
* The cloud that the identifier belongs to.
*/
public class CommunicationCloudEnvironment {
private static final String PUBLIC_VALUE = "public";
private static final String DOD_VALUE = "dod";
private static final String GCCH_VALUE = "gcch";

private final String environmentValue;

/**
* Create CommunicationCloudEnvironment with name string
* @param environmentValue name of hte cloud environment
*/
public CommunicationCloudEnvironment(String environmentValue) {
Objects.requireNonNull(environmentValue);
this.environmentValue = environmentValue;
}

static CommunicationCloudEnvironment fromModel(CommunicationCloudEnvironmentModel environmentModel) {
return new CommunicationCloudEnvironment(environmentModel.toString());
}

/**
* Represent Azure public cloud
*/
public static final CommunicationCloudEnvironment PUBLIC = new CommunicationCloudEnvironment(PUBLIC_VALUE);

/**
* Represent Azure Dod cloud
*/
public static final CommunicationCloudEnvironment DOD = new CommunicationCloudEnvironment(DOD_VALUE);

/**
* Represent Azure Gcch cloud
*/
public static final CommunicationCloudEnvironment GCCH = new CommunicationCloudEnvironment(GCCH_VALUE);

@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
return that != null && this.environmentValue.equals(that.toString());
}

@Override
public String toString() {
return environmentValue;
}

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.communication.common;

class CommunicationCloudEnvironmentModel {

private static final String PUBLIC_VALUE = "public";
private static final String DOD_VALUE = "dod";
private static final String GCCH_VALUE = "gcch";

private final String environmentValue;

CommunicationCloudEnvironmentModel(String environmentValue) {
java.util.Objects.requireNonNull(environmentValue);
this.environmentValue = environmentValue;
}

public static final CommunicationCloudEnvironmentModel PUBLIC = new CommunicationCloudEnvironmentModel(PUBLIC_VALUE);
public static final CommunicationCloudEnvironmentModel DOD = new CommunicationCloudEnvironmentModel(DOD_VALUE);
public static final CommunicationCloudEnvironmentModel GCCH = new CommunicationCloudEnvironmentModel(GCCH_VALUE);

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

return that != null && this.environmentValue.equals(that.toString());
}

@Override
public String toString() {
return environmentValue;
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
* Common communication identifier for Communication Services
*/
public abstract class CommunicationIdentifier {
/**
* Get string representation of the identifier
* @return string representation of the identifier
*/
public abstract String getId();

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// 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;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// 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;

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

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

private CommunicationCloudEnvironmentModel cloudEnvironmentModel;

/**
* Get the kind property: Kind of the communication identifier.
*
* @return the kind value.
*/
public com.azure.communication.common.CommunicationIdentifierKind getKind() {
public CommunicationIdentifierKind getKind() {
return this.kind;
}

Expand All @@ -55,7 +56,7 @@ public com.azure.communication.common.CommunicationIdentifierKind getKind() {
* @param kind the kind value to set.
* @return the CommunicationIdentifierModel object itself.
*/
public CommunicationIdentifierModel setKind(com.azure.communication.common.CommunicationIdentifierKind kind) {
public CommunicationIdentifierModel setKind(CommunicationIdentifierKind kind) {
this.kind = kind;
return this;
}
Expand Down Expand Up @@ -139,4 +140,22 @@ public CommunicationIdentifierModel setIsAnonymous(Boolean isAnonymous) {
this.isAnonymous = isAnonymous;
return this;
}

/**
* Get the cloud environment model in which this identifier model is valid
* @return the cloud environment model
*/
CommunicationCloudEnvironmentModel getCloudEnvironmentModel() {
return this.cloudEnvironmentModel;
}

/**
* Set the cloud environment model in which this identifier model is valid
* @param cloudEnvironmentModel the cloud environment model in which this identifier model is valid
* @return the CommunicationIdentifierModel object itself.
*/
CommunicationIdentifierModel setCloudEnvironmentModel(CommunicationCloudEnvironmentModel cloudEnvironmentModel) {
this.cloudEnvironmentModel = cloudEnvironmentModel;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// 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;

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

if (kind == CommunicationIdentifierKind.PHONE_NUMBER) {
Objects.requireNonNull(identifier.getPhoneNumber());
return new PhoneNumberIdentifier(identifier.getPhoneNumber());
Objects.requireNonNull(identifier.getId());
return new PhoneNumberIdentifier(identifier.getPhoneNumber()).setId(identifier.getId());
}

if (kind == CommunicationIdentifierKind.MICROSOFT_TEAMS_USER) {
Objects.requireNonNull(identifier.getMicrosoftTeamsUserId());
return new MicrosoftTeamsUserIdentifier(identifier.getMicrosoftTeamsUserId(), identifier.isAnonymous());
Objects.requireNonNull(identifier.getCloudEnvironmentModel());
return new MicrosoftTeamsUserIdentifier(identifier.getMicrosoftTeamsUserId(), identifier.isAnonymous())
.setId(identifier.getId())
.setCloudEnvironment(CommunicationCloudEnvironment.fromModel(identifier.getCloudEnvironmentModel()));
}

Objects.requireNonNull(id);
Expand All @@ -51,14 +54,18 @@ public static CommunicationIdentifierModel serialize(CommunicationIdentifier ide
if (identifier instanceof PhoneNumberIdentifier) {
return new CommunicationIdentifierModel()
.setKind(CommunicationIdentifierKind.PHONE_NUMBER)
.setPhoneNumber(((PhoneNumberIdentifier) identifier).getPhoneNumber());
.setPhoneNumber(((PhoneNumberIdentifier) identifier).getPhoneNumber())
.setId(identifier.getId());
}

if (identifier instanceof MicrosoftTeamsUserIdentifier) {
MicrosoftTeamsUserIdentifier teamsUserIdentifier = (MicrosoftTeamsUserIdentifier) identifier;
return new CommunicationIdentifierModel()
.setKind(CommunicationIdentifierKind.MICROSOFT_TEAMS_USER)
.setMicrosoftTeamsUserId(((MicrosoftTeamsUserIdentifier) identifier).getUserId())
.setIsAnonymous(((MicrosoftTeamsUserIdentifier) identifier).isAnonymous());
.setMicrosoftTeamsUserId(teamsUserIdentifier.getUserId())
.setIsAnonymous(teamsUserIdentifier.isAnonymous())
.setId(teamsUserIdentifier.getId())
.setCloudEnvironmentModel(new CommunicationCloudEnvironmentModel(teamsUserIdentifier.getCloudEnvironment().toString()));
}

return new CommunicationIdentifierModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CommunicationUserIdentifier extends CommunicationIdentifier {

/**
* Creates a CommunicationUserIdentifier object
*
*
* @param id the string identifier representing the identity
* @throws IllegalArgumentException thrown if id parameter fail the validation.
*/
Expand All @@ -24,10 +24,26 @@ public CommunicationUserIdentifier(String id) {
this.id = id;
}

/**
* @return the string identifier representing the object identity
*/
@Override
public String getId() {
return id;
}

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

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

return ((CommunicationUserIdentifier) that).getId().equals(id);
}

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

0 comments on commit d90271c

Please sign in to comment.