Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt Log service and DataStoreService changes from Core 2.0 #77

Merged
merged 6 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

package com.adobe.marketing.mobile.edge.identity;

import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
import static com.adobe.marketing.mobile.edge.identity.IdentityConstants.LOG_TAG;

import com.adobe.marketing.mobile.services.Log;
import com.adobe.marketing.mobile.util.StringUtils;
import java.util.Locale;
import java.util.Objects;
Expand All @@ -23,6 +24,8 @@
*/
final class ECID {

private static final String LOG_SOURCE = "ECID";

private final String ecidString;

/**
Expand All @@ -43,9 +46,9 @@ final class ECID {
*/
ECID(final String ecidString) {
if (StringUtils.isNullOrEmpty(ecidString)) {
MobileCore.log(
LoggingMode.DEBUG,
IdentityConstants.LOG_TAG,
Log.debug(
LOG_TAG,
LOG_SOURCE,
"Creating an ECID with null or empty ecidString is not allowed, generating a new ECID."
);
this.ecidString = new ECID().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import com.adobe.marketing.mobile.Extension;
import com.adobe.marketing.mobile.ExtensionError;
import com.adobe.marketing.mobile.ExtensionErrorCallback;
import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.services.Log;
import com.adobe.marketing.mobile.util.DataReader;
import com.adobe.marketing.mobile.util.StringUtils;
import java.util.HashMap;
Expand All @@ -36,6 +36,8 @@ public class Identity {
public static final Class<? extends Extension> EXTENSION = IdentityExtension.class;
private static final long CALLBACK_TIMEOUT_MILLIS = 500L;

private static final String LOG_SOURCE = "Identity";

private Identity() {}

/**
Expand All @@ -59,11 +61,10 @@ public static void registerExtension() {
new ExtensionErrorCallback<ExtensionError>() {
@Override
public void error(ExtensionError extensionError) {
MobileCore.log(
LoggingMode.ERROR,
Log.error(
LOG_TAG,
"Identity - There was an error registering the Edge Identity extension: " +
extensionError.getErrorName()
LOG_SOURCE,
"There was an error registering the Edge Identity extension: " + extensionError.getErrorName()
);
}
}
Expand All @@ -79,11 +80,7 @@ public void error(ExtensionError extensionError) {
*/
public static void getExperienceCloudId(final AdobeCallback<String> callback) {
if (callback == null) {
MobileCore.log(
LoggingMode.DEBUG,
LOG_TAG,
"Identity - Unexpected null callback, provide a callback to retrieve current ECID."
);
Log.debug(LOG_TAG, LOG_SOURCE, "Unexpected null callback, provide a callback to retrieve current ECID.");
return;
}

Expand All @@ -105,10 +102,10 @@ public void call(Event responseEvent) {
final IdentityMap identityMap = IdentityMap.fromXDMMap(responseEvent.getEventData());

if (identityMap == null) {
MobileCore.log(
LoggingMode.DEBUG,
Log.debug(
LOG_TAG,
"Identity - Failed to read IdentityMap from response event, invoking error callback with AdobeError.UNEXPECTED_ERROR"
LOG_SOURCE,
"Failed to read IdentityMap from response event, invoking error callback with AdobeError.UNEXPECTED_ERROR"
);
returnError(callback, AdobeError.UNEXPECTED_ERROR);
return;
Expand All @@ -128,11 +125,11 @@ public void call(Event responseEvent) {
@Override
public void fail(AdobeError adobeError) {
returnError(callback, adobeError);
MobileCore.log(
LoggingMode.DEBUG,
Log.debug(
LOG_TAG,
LOG_SOURCE,
String.format(
"Identity - Failed to dispatch %s event: Error : %s.",
"Failed to dispatch %s event: Error : %s.",
IdentityConstants.EventNames.IDENTITY_REQUEST_IDENTITY_ECID,
adobeError.getErrorName()
)
Expand Down Expand Up @@ -162,10 +159,10 @@ public void fail(AdobeError adobeError) {
*/
public static void getUrlVariables(final AdobeCallback<String> callback) {
if (callback == null) {
MobileCore.log(
LoggingMode.DEBUG,
Log.debug(
LOG_TAG,
"Identity - Unexpected null callback, provide a callback to retrieve current visitor identifiers (URLVariables) query string."
LOG_SOURCE,
"Unexpected null callback, provide a callback to retrieve current visitor identifiers (URLVariables) query string."
);
return;
}
Expand Down Expand Up @@ -209,11 +206,11 @@ public void call(final Event responseEvent) {
@Override
public void fail(final AdobeError adobeError) {
returnError(callback, adobeError);
MobileCore.log(
LoggingMode.DEBUG,
Log.debug(
LOG_TAG,
LOG_SOURCE,
String.format(
"Identity - Failed to dispatch %s event: Error : %s.",
"Failed to dispatch %s event: Error : %s.",
IdentityConstants.EventNames.IDENTITY_REQUEST_URL_VARIABLES,
adobeError.getErrorName()
)
Expand All @@ -234,11 +231,7 @@ public void fail(final AdobeError adobeError) {
*/
public static void updateIdentities(final IdentityMap identityMap) {
if (identityMap == null || identityMap.isEmpty()) {
MobileCore.log(
LoggingMode.DEBUG,
LOG_TAG,
"Identity - Unable to updateIdentities, IdentityMap is null or empty"
);
Log.debug(LOG_TAG, LOG_SOURCE, "Unable to updateIdentities, IdentityMap is null or empty");
return;
}

Expand All @@ -262,16 +255,12 @@ public static void updateIdentities(final IdentityMap identityMap) {
*/
public static void removeIdentity(final IdentityItem item, final String namespace) {
if (StringUtils.isNullOrEmpty(namespace)) {
MobileCore.log(
LoggingMode.DEBUG,
LOG_TAG,
"Identity - Unable to removeIdentity, namespace is null or empty"
);
Log.debug(LOG_TAG, LOG_SOURCE, "Unable to removeIdentity, namespace is null or empty");
return;
}

if (item == null) {
MobileCore.log(LoggingMode.DEBUG, LOG_TAG, "Identity - Unable to removeIdentity, IdentityItem is null");
Log.debug(LOG_TAG, LOG_SOURCE, "Unable to removeIdentity, IdentityItem is null");
return;
}

Expand All @@ -297,10 +286,10 @@ public static void removeIdentity(final IdentityItem item, final String namespac
*/
public static void getIdentities(final AdobeCallback<IdentityMap> callback) {
if (callback == null) {
MobileCore.log(
LoggingMode.DEBUG,
Log.debug(
LOG_TAG,
"Identity - Unexpected null callback, provide a callback to retrieve current IdentityMap."
LOG_SOURCE,
"Unexpected null callback, provide a callback to retrieve current IdentityMap."
);
return;
}
Expand All @@ -323,10 +312,10 @@ public void call(final Event responseEvent) {
final IdentityMap identityMap = IdentityMap.fromXDMMap(responseEvent.getEventData());

if (identityMap == null) {
MobileCore.log(
LoggingMode.DEBUG,
Log.debug(
LOG_TAG,
"Identity - Failed to read IdentityMap from response event, invoking error callback with AdobeError.UNEXPECTED_ERROR"
LOG_SOURCE,
"Failed to read IdentityMap from response event, invoking error callback with AdobeError.UNEXPECTED_ERROR"
);
returnError(callback, AdobeError.UNEXPECTED_ERROR);
return;
Expand All @@ -338,11 +327,11 @@ public void call(final Event responseEvent) {
@Override
public void fail(final AdobeError adobeError) {
returnError(callback, adobeError);
MobileCore.log(
LoggingMode.DEBUG,
Log.debug(
LOG_TAG,
LOG_SOURCE,
String.format(
"Identity - Failed to dispatch %s event: Error : %s.",
"Failed to dispatch %s event: Error : %s.",
IdentityConstants.EventNames.REQUEST_IDENTITIES,
adobeError.getErrorName()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@
import com.adobe.marketing.mobile.Event;
import com.adobe.marketing.mobile.Extension;
import com.adobe.marketing.mobile.ExtensionApi;
import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.SharedStateResolution;
import com.adobe.marketing.mobile.SharedStateResult;
import com.adobe.marketing.mobile.SharedStateStatus;
import com.adobe.marketing.mobile.services.Log;
import com.adobe.marketing.mobile.services.ServiceProvider;
import com.adobe.marketing.mobile.util.StringUtils;
import com.adobe.marketing.mobile.util.TimeUtils;
import java.util.HashMap;
import java.util.Map;

class IdentityExtension extends Extension {

private static final String LOG_SOURCE = "IdentityExtension";

/**
* A {@code SharedStateCallback} to retrieve the last set state of an extension and to
* create an XDM state at the event provided.
Expand Down Expand Up @@ -190,7 +192,7 @@ private void handleUrlVariablesRequest(@NonNull final Event event) {
handleUrlVariableResponse(
event,
null,
"IdentityExtension - Cannot process getUrlVariables request Identity event, Experience Cloud Org ID not found in configuration."
"Cannot process getUrlVariables request Identity event, Experience Cloud Org ID not found in configuration."
);
return;
}
Expand All @@ -202,7 +204,7 @@ private void handleUrlVariablesRequest(@NonNull final Event event) {
handleUrlVariableResponse(
event,
null,
"IdentityExtension - Cannot process getUrlVariables request Identity event, ECID not found."
"Cannot process getUrlVariables request Identity event, ECID not found."
);
return;
}
Expand Down Expand Up @@ -250,7 +252,7 @@ void handleUrlVariableResponse(@NonNull final Event event, final String urlVaria
.build();

if (StringUtils.isNullOrEmpty(urlVariables) && !StringUtils.isNullOrEmpty(errorMsg)) {
MobileCore.log(LoggingMode.WARNING, LOG_TAG, errorMsg);
Log.warning(LOG_TAG, LOG_SOURCE, errorMsg);
}

getApi().dispatch(responseEvent);
Expand All @@ -264,15 +266,18 @@ void handleUrlVariableResponse(@NonNull final Event event, final String urlVaria
void handleUpdateIdentities(@NonNull final Event event) {
final Map<String, Object> eventData = event.getEventData();

if (eventData == null) return; // TODO: Add log message when logging changes are made
if (eventData == null) {
Log.trace(LOG_TAG, LOG_SOURCE, "Cannot update identifiers, event data is null.");
return;
}

final IdentityMap map = IdentityMap.fromXDMMap(eventData);

if (map == null) {
MobileCore.log(
LoggingMode.DEBUG,
Log.debug(
LOG_TAG,
"IdentityExtension - Failed to update identifiers as no identifiers were found in the event data."
LOG_SOURCE,
"Failed to update identifiers as no identifiers were found in the event data."
);
return;
}
Expand All @@ -289,15 +294,18 @@ void handleUpdateIdentities(@NonNull final Event event) {
void handleRemoveIdentity(@NonNull final Event event) {
final Map<String, Object> eventData = event.getEventData();

if (eventData == null) return; // TODO: Add log message when logging changes are made
if (eventData == null) {
Log.trace(LOG_TAG, LOG_SOURCE, "Cannot remove identifiers, event data is null.");
return;
}

final IdentityMap map = IdentityMap.fromXDMMap(eventData);

if (map == null) {
MobileCore.log(
LoggingMode.DEBUG,
Log.debug(
LOG_TAG,
"IdentityExtension - Failed to remove identifiers as no identifiers were found in the event data."
LOG_SOURCE,
"Failed to remove identifiers as no identifiers were found in the event data."
);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

import static com.adobe.marketing.mobile.edge.identity.IdentityConstants.LOG_TAG;

import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.services.Log;
import com.adobe.marketing.mobile.util.DataReader;
import com.adobe.marketing.mobile.util.DataReaderException;
import java.util.HashMap;
Expand All @@ -29,6 +28,8 @@
*/
public final class IdentityItem {

private static final String LOG_SOURCE = "IdentityItem";

private final String id;
private final AuthenticatedState authenticatedState;
private final boolean primary;
Expand Down Expand Up @@ -182,7 +183,7 @@ static IdentityItem fromData(final Map<String, Object> data) {

return new IdentityItem(id, authenticatedState, primary);
} catch (final DataReaderException e) {
MobileCore.log(LoggingMode.DEBUG, LOG_TAG, "IdentityItem - Failed to create IdentityItem from data.");
Log.debug(LOG_TAG, LOG_SOURCE, "Failed to create IdentityItem from data.");
return null;
}
}
Expand Down
Loading