baselining azure-communication-common to L15

This commit is contained in:
Anu Thomas Chandy 2021-02-25 15:22:57 -08:00
Родитель 2c97b77488
Коммит f775e3062b
14 изменённых файлов: 33 добавлений и 35 удалений

Просмотреть файл

@ -11,9 +11,19 @@ android {
}
dependencies {
api "com.azure.android:azure-core:1.0.0-beta.3"
// <!-- begin: api Dependencies -->
api project(":sdk:core:azure-core")
api project(":sdk:core:azure-core-logging")
api project(":sdk:core:azure-core-credential")
// <!-- end: api Dependencies -->
// <!-- begin: implementation Dependencies -->
implementation "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
implementation "com.jakewharton.threetenabp:threetenabp:$threeTenAbpVersion"
// <!-- end: implementation Dependencies -->
// <!-- begin: test Dependencies -->
testImplementation "junit:junit:$jUnitVersion"
testImplementation "org.threeten:threetenbp:$threeTenBpVersion"
// <!-- end: test Dependencies -->
}

Просмотреть файл

@ -4,7 +4,7 @@
package com.azure.android.communication.common;
import com.azure.android.core.credential.AccessToken;
import com.azure.android.core.util.logging.ClientLogger;
import com.azure.android.core.logging.ClientLogger;
import java.util.Timer;
import java.util.TimerTask;
@ -17,7 +17,7 @@ class AutoRefreshUserCredential extends UserCredential {
private static final int ON_DEMAND_REFRESH_BUFFER_SECS = 120;
private static final int PROACTIVE_REFRESH_BUFFER_SECS = 600;
private final ClientLogger logger = ClientLogger.getDefault(AutoRefreshUserCredential.class);
private final ClientLogger logger = new ClientLogger(AutoRefreshUserCredential.class);
private Callable<String> tokenRefresher;
private Callable<AccessToken> accessTokenCallable;

Просмотреть файл

@ -4,11 +4,9 @@
package com.azure.android.communication.common;
import com.azure.android.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonProperty;
/** The CommunicationIdentifierModel model. */
@Fluent
public final class CommunicationIdentifierModel {
/*
* Raw Id of the identifier. Optional in requests, required in responses.

Просмотреть файл

@ -15,7 +15,9 @@ class CommunicationIdentifierSerializer {
* @return deserialized CommunicationIdentifier
*/
public static CommunicationIdentifier deserialize(CommunicationIdentifierModel identifier) {
Objects.requireNonNull(identifier, "'identifier' cannot be null");
if (identifier == null) {
throw new NullPointerException("'identifier' cannot be null");
}
assertSingleType(identifier);
String rawId = identifier.getRawId();
@ -26,8 +28,12 @@ class CommunicationIdentifierSerializer {
if (identifier.getPhoneNumber() != null) {
PhoneNumberIdentifierModel phoneNumberModel = identifier.getPhoneNumber();
Objects.requireNonNull(phoneNumberModel.getValue(), "'phoneNumber.value' cannot be null");
Objects.requireNonNull(rawId, "'rawId' cannot be null");
if (phoneNumberModel.getValue() == null) {
throw new NullPointerException("'phoneNumber.value' cannot be null");
}
if (rawId == null) {
throw new NullPointerException("'rawId' cannot be null");
}
return new PhoneNumberIdentifier(phoneNumberModel.getValue()).setRawId(rawId);
}

Просмотреть файл

@ -47,7 +47,7 @@ public class CommunicationTokenRefreshOptions {
* tokenRefresher before token expiry by minutes set
* with setCallbackOffsetMinutes or default value of
* two minutes
* @param token the serialized JWT token, cannot be null
* @param initialToken the serialized JWT token, cannot be null
*/
public CommunicationTokenRefreshOptions(Callable<String> tokenRefresher, boolean refreshProactively, String initialToken) {
if (tokenRefresher == null) {

Просмотреть файл

@ -2,9 +2,6 @@
// Licensed under the MIT License.
package com.azure.android.communication.common;
import com.azure.android.core.util.CoreUtil;
/**
* Communication identifier for Communication Services Users
*/
@ -19,7 +16,7 @@ public class CommunicationUserIdentifier extends CommunicationIdentifier {
* @throws IllegalArgumentException thrown if id parameter fail the validation.
*/
public CommunicationUserIdentifier(String id) {
if (CoreUtil.isNullOrEmpty(id)) {
if (id == null || id.length() == 0) {
throw new IllegalArgumentException("The initialization parameter [id] cannot be null or empty.");
}
this.id = id;

Просмотреть файл

@ -4,11 +4,9 @@
package com.azure.android.communication.common;
import com.azure.android.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonProperty;
/** The CommunicationUserIdentifierModel model. */
@Fluent
public final class CommunicationUserIdentifierModel {
/*
* The Id of the communication user.

Просмотреть файл

@ -4,8 +4,6 @@
package com.azure.android.communication.common;
import com.azure.android.core.util.CoreUtil;
import java.util.Objects;
/**
@ -43,7 +41,7 @@ public class MicrosoftTeamsUserIdentifier extends CommunicationIdentifier {
* @throws IllegalArgumentException thrown if userId parameter fail the validation.
*/
public MicrosoftTeamsUserIdentifier(String userId, boolean isAnonymous) {
if (CoreUtil.isNullOrEmpty(userId)) {
if (userId == null || userId.length() == 0) {
throw new IllegalArgumentException("The initialization parameter [userId] cannot be null or empty.");
}
this.userId = userId;

Просмотреть файл

@ -4,11 +4,9 @@
package com.azure.android.communication.common;
import com.azure.android.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonProperty;
/** The MicrosoftTeamsUserIdentifierModel model. */
@Fluent
public final class MicrosoftTeamsUserIdentifierModel {
/*
* The Id of the Microsoft Teams user. If not anonymous, this is the AAD

Просмотреть файл

@ -2,9 +2,6 @@
// Licensed under the MIT License.
package com.azure.android.communication.common;
import com.azure.android.core.util.CoreUtil;
/**
* Communication identifier for Communication Services Phone Numbers
*/
@ -21,7 +18,7 @@ public class PhoneNumberIdentifier extends CommunicationIdentifier {
* @throws IllegalArgumentException thrown if phoneNumber parameter fail the validation.
*/
public PhoneNumberIdentifier(String phoneNumber) {
if (CoreUtil.isNullOrEmpty(phoneNumber)) {
if (phoneNumber == null || phoneNumber.length() == 0) {
throw new IllegalArgumentException("The initialization parameter [phoneNumber] cannot be null to empty.");
}
this.phoneNumber = phoneNumber;

Просмотреть файл

@ -4,11 +4,9 @@
package com.azure.android.communication.common;
import com.azure.android.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonProperty;
/** The PhoneNumberIdentifierModel model. */
@Fluent
public final class PhoneNumberIdentifierModel {
/*
* The phone number in E.164 format.

Просмотреть файл

@ -5,8 +5,7 @@ package com.azure.android.communication.common;
import android.util.Base64;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.nio.charset.Charset;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -35,11 +34,13 @@ final class TokenParser {
*/
static AccessToken createAccessToken(String tokenStr) {
try {
Objects.requireNonNull(tokenStr, "'tokenStr' cannot be null.");
if (tokenStr == null) {
throw new NullPointerException("'tokenStr' cannot be null.");
}
String[] tokenParts = tokenStr.split("\\.");
String tokenPayload = tokenParts[1];
byte[] decodedBytes = Base64.decode(tokenPayload, Base64.DEFAULT);
String decodedPayloadJson = new String(decodedBytes, StandardCharsets.UTF_8);
String decodedPayloadJson = new String(decodedBytes, Charset.forName("UTF-8"));
ObjectNode payloadObj = jsonMapper.readValue(decodedPayloadJson, ObjectNode.class);
long expire = payloadObj.get("exp").longValue();

Просмотреть файл

@ -2,9 +2,6 @@
// Licensed under the MIT License.
package com.azure.android.communication.common;
import com.azure.android.core.util.CoreUtil;
/**
* Catch-all for all other Communication identifiers for Communication Services
*/
@ -19,7 +16,7 @@ public class UnknownIdentifier extends CommunicationIdentifier {
* @throws IllegalArgumentException thrown if id parameter fail the validation.
*/
public UnknownIdentifier(String id) {
if (CoreUtil.isNullOrEmpty(id)) {
if (id == null || id.length() == 0) {
throw new IllegalArgumentException("The initialization parameter [id] cannot be null or empty.");
}
this.id = id;

Просмотреть файл

@ -1,3 +1,4 @@
include ':sdk:communication:azure-communication-common'
include ":sdk:core:azure-core-logging"
include ':sdk:core:azure-core-jackson'
include ":sdk:core:azure-core"
@ -8,4 +9,3 @@ include ":sdk:core:azure-core-http-httpurlconnection"
include ":sdk:core:azure-core-rest"
include ":sdk:core:azure-core-test"
include ":eng:code-quality-reports"
include ':sdk:communication:azure-communication-common'