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

[Dev] - AuthenticationState Renaming and Remove ECID variable #16

Merged
merged 27 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
958f767
[AMSDK-11081] - Rename listener tests
PravinPK Mar 11, 2021
b3d6fc7
[AMSDK-11081] - Listeners for remove and update Identity requests + t…
PravinPK Mar 11, 2021
0e49313
[AMSDK-11081] - UpdateIdentity Public API
PravinPK Mar 11, 2021
93174db
Merge with dev and resolve conflicts
PravinPK Mar 11, 2021
68b8e5b
[AMSDK-11081] - Fix spacings in IdentityMap class
PravinPK Mar 11, 2021
6de193a
[Dev] - Add the functional test helpers + first valid functional test
PravinPK Mar 12, 2021
8ce362c
[Dev] - First functional test
PravinPK Mar 12, 2021
25618e9
Resolve conflict and merge with dev
PravinPK Mar 12, 2021
1b7d9c5
[Dev] - Assertion fail on misread of persistence in TestPersistence h…
PravinPK Mar 12, 2021
10cb7c2
Resolve conflict and merge with dev
PravinPK Mar 15, 2021
9fc4fe8
Merge branch 'dev' of github.com:adobe/aepsdk-identityedge-android in…
PravinPK Mar 15, 2021
062e5f1
[AMSDK-11081] - Update/Remove Identity API implementation
PravinPK Mar 17, 2021
ce35e5f
[AMSDK-11081] - Unit test for IdentityMap and RemoveIdentity Public API
PravinPK Mar 17, 2021
b9014e8
Merge branch 'dev' of github.com:adobe/aepsdk-identityedge-android in…
PravinPK Mar 17, 2021
6d142fa
[AMSDK-11081] - More Unit test for update/Remove
PravinPK Mar 17, 2021
fd8aa6c
[AMSDK-11081] - Few more edits to unittests
PravinPK Mar 17, 2021
b10ff0e
[AMSDK-11081] - better naming and typo fixes
PravinPK Mar 18, 2021
0e30d59
[AMSDK-11081]- Merge with latest dev and resolve conflicts
PravinPK Mar 18, 2021
b45302d
[AMSDK-11081] - rearrange parameters, setECID handling, case-insensit…
PravinPK Mar 19, 2021
46858b3
[AMSDK-11081] - Resolve conflict and merge with dev
PravinPK Mar 19, 2021
ea6e55d
[AMSDK-11081] - Caseinsensitive removal of reserved namespace items +…
PravinPK Mar 19, 2021
706b36e
[AMSDK-11081] - cleanup and renaming
PravinPK Mar 19, 2021
0080312
[Dev] - Rename enum to AuthenticatedState and fix its toString
PravinPK Mar 19, 2021
052d8fa
[Dev] - Enum AuthenticatedState
PravinPK Mar 19, 2021
1284996
[Dev] - removed local ecid and secondaryECID local instances variables
PravinPK Mar 19, 2021
87608df
conflict merge
PravinPK Mar 19, 2021
f4f3739
[AMSDK-11081] - final on IdentityMap, enum string comparison change
PravinPK Mar 22, 2021
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 @@ -14,25 +14,25 @@
/**
* Represents the authentication state for an {@link IdentityItem}
*/
public enum AuthenticationState {
public enum AuthenticatedState {
AMBIGUOUS("ambiguous"),
AUTHENTICATED("authenticated"),
LOGGED_OUT("loggedOut");

private String name;

private AuthenticationState(final String name) {
private AuthenticatedState(final String name) {
this.name = name;
}

public String getName() {
return name;
}

public static AuthenticationState fromString(final String state) {
if ("authenticated".equalsIgnoreCase(state)) {
public static AuthenticatedState fromString(final String state) {
if (AUTHENTICATED.getName().equalsIgnoreCase(state)) {
return AUTHENTICATED;
} else if ("loggedOut".equalsIgnoreCase(state)) {
} else if (LOGGED_OUT.getName().equalsIgnoreCase(state)) {
return LOGGED_OUT;
} else {
return AMBIGUOUS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,20 @@ class IdentityEdgeProperties {
add(IdentityEdgeConstants.Namespaces.IDFA);
}};

// The current Experience Cloud ID
private ECID ecid;
private final IdentityMap identityMap;

// A secondary (non-primary) Experience Cloud ID
private ECID ecidSecondary;

private IdentityMap identityMap = new IdentityMap();

IdentityEdgeProperties() { }
IdentityEdgeProperties() {
this.identityMap = new IdentityMap();
}

/**
* Creates a identity edge properties instance based on the map
*
* @param xdmData a map representing an identity edge properties instance
*/
IdentityEdgeProperties(final Map<String, Object> xdmData) {
if (Utils.isNullOrEmpty(xdmData)) {
return;
}

identityMap = IdentityMap.fromData(xdmData);
if (identityMap != null) {
final List<IdentityItem> ecidItems = identityMap.getIdentityItemsForNamespace(IdentityEdgeConstants.Namespaces.ECID);
if (ecidItems != null) {
if (ecidItems.size() > 0 && ecidItems.get(0) != null && ecidItems.get(0).getId() != null) {
ecid = new ECID(ecidItems.get(0).getId());
}
if (ecidItems.size() > 1 && ecidItems.get(1) != null && ecidItems.get(1).getId() != null) {
ecidSecondary = new ECID(ecidItems.get(1).getId());
}
}
}
IdentityMap map = IdentityMap.fromData(xdmData);
this.identityMap = map == null ? new IdentityMap() : map; // always keep an empty identity map so there is no need for null check
}

/**
Expand All @@ -72,8 +54,9 @@ class IdentityEdgeProperties {
*/
void setECID(final ECID newEcid) {
// delete the previous ECID from the identity map if exist
if (ecid != null) {
final IdentityItem previousECIDItem = new IdentityItem(ecid.toString());
final ECID currentECID = getECID();
if (currentECID != null) {
final IdentityItem previousECIDItem = new IdentityItem(currentECID.toString());
identityMap.removeItem(previousECIDItem, IdentityEdgeConstants.Namespaces.ECID);
}

Expand All @@ -83,11 +66,9 @@ void setECID(final ECID newEcid) {
identityMap.clearItemsForNamespace(IdentityEdgeConstants.Namespaces.ECID);
} else {
// And add the new primary Ecid as a first element of Identity map
final IdentityItem newECIDItem = new IdentityItem(newEcid.toString(), AuthenticationState.AMBIGUOUS, false);
final IdentityItem newECIDItem = new IdentityItem(newEcid.toString(), AuthenticatedState.AMBIGUOUS, false);
identityMap.addItem(newECIDItem, IdentityEdgeConstants.Namespaces.ECID, true);
}

this.ecid = newEcid; // keep the local variable up to date
}

/**
Expand All @@ -96,7 +77,11 @@ void setECID(final ECID newEcid) {
* @return current {@code ECID}
*/
ECID getECID() {
return ecid;
final List<IdentityItem> ecidItems = identityMap.getIdentityItemsForNamespace(IdentityEdgeConstants.Namespaces.ECID);
if (ecidItems != null && !ecidItems.isEmpty() && ecidItems.get(0) != null && !Utils.isNullOrEmpty(ecidItems.get(0).getId())) {
return new ECID(ecidItems.get(0).getId());
}
return null;
}

/**
Expand All @@ -106,25 +91,23 @@ ECID getECID() {
*/
void setECIDSecondary(final ECID newSecondaryEcid) {
// delete the previous secondary ECID from the identity map if exist
final ECID ecidSecondary = getECIDSecondary();
if (ecidSecondary != null) {
final IdentityItem previousECIDItem = new IdentityItem(ecidSecondary.toString());
identityMap.removeItem(previousECIDItem, IdentityEdgeConstants.Namespaces.ECID);
}

// do not set secondary ECID if primary ECID is not set
if (ecid == null) {
if (getECID() == null) {
MobileCore.log(LoggingMode.DEBUG, LOG_TAG, "Cannot set secondary ECID value as no primary ECID exists.");
this.ecidSecondary = null;
return;
}

// add the new secondary ECID to Identity map
if (newSecondaryEcid != null) {
final IdentityItem newSecondaryECIDItem = new IdentityItem(newSecondaryEcid.toString(), AuthenticationState.AMBIGUOUS, false);
final IdentityItem newSecondaryECIDItem = new IdentityItem(newSecondaryEcid.toString(), AuthenticatedState.AMBIGUOUS, false);
identityMap.addItem(newSecondaryECIDItem, IdentityEdgeConstants.Namespaces.ECID);
}

this.ecidSecondary = newSecondaryEcid; // keep the local variable up to date
}

/**
Expand All @@ -133,7 +116,11 @@ void setECIDSecondary(final ECID newSecondaryEcid) {
* @return secondary {@code ECID}
*/
ECID getECIDSecondary() {
return ecidSecondary;
final List<IdentityItem> ecidItems = identityMap.getIdentityItemsForNamespace(IdentityEdgeConstants.Namespaces.ECID);
if (ecidItems != null && ecidItems.size() > 1 && ecidItems.get(1) != null && !Utils.isNullOrEmpty(ecidItems.get(1).getId())) {
return new ECID(ecidItems.get(1).getId());
}
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class IdentityEdgeState {
private IdentityEdgeProperties identityProperties;

/**
* Creates a new {@link IdentityEdgeState} with the given {@link IdentityEdgeProperties}
* Creates a new {@link IdentityEdgeState} with the given {@link IdentityEdgeProperties}
*
* @param identityProperties identity edge properties
*/
IdentityEdgeState(final IdentityEdgeProperties identityProperties) {
Expand All @@ -47,10 +48,13 @@ boolean hasBooted() {

/**
* Completes init for the Identity Edge extension.
*
* @return True if we should share state after bootup, false otherwise
*/
boolean bootupIfReady() {
if (hasBooted) { return true; }
if (hasBooted) {
return true;
}
// Load properties from local storage
identityProperties = IdentityEdgeStorageService.loadPropertiesFromPersistence();

Expand Down Expand Up @@ -114,17 +118,26 @@ void removeCustomerIdentifiers(final IdentityMap map) {
/**
* Update the legacy ECID property with {@code legacyEcid} provided it does not equal the primary or secondary ECIDs
* currently in {@code IdentityEdgePoperties}.
*
* @param legacyEcid the current ECID from the direct Identity extension
* @return true if the legacy ECID was updated in {@code IdentityEdgeProperties}
*/
boolean updateLegacyExperienceCloudId(final ECID legacyEcid) {
if (legacyEcid == identityProperties.getECID() || legacyEcid == identityProperties.getECIDSecondary()) {
final ECID ecid = identityProperties.getECID();
final ECID ecidSecondary = identityProperties.getECIDSecondary();

if ((legacyEcid != null) && (legacyEcid.equals(ecid) || legacyEcid.equals(ecidSecondary))) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else if ..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need an else if ?


// no need to clear secondaryECID if its already null
if (legacyEcid == null && ecidSecondary == null){
return false;
}

identityProperties.setECIDSecondary(legacyEcid);
IdentityEdgeStorageService.savePropertiesToPersistence(identityProperties);
MobileCore.log(LoggingMode.DEBUG, LOG_TAG,"Identity direct ECID updated to '" + legacyEcid + "', updating the IdentityMap");
MobileCore.log(LoggingMode.DEBUG, LOG_TAG, "Identity direct ECID updated to '" + legacyEcid + "', updating the IdentityMap");
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,43 @@
*/
public final class IdentityItem {
private final String id;
private final AuthenticationState authenticationState;
private final AuthenticatedState authenticatedState;
private final boolean primary;

private static final String LOG_TAG = "IdentityItem";

/**
* Creates a new {@link IdentityItem}
* @param id id for the item
* @param authenticationState {@link AuthenticationState} for the item
* @param authenticatedState {@link AuthenticatedState} for the item
* @param primary primary flag for the item
* @throws IllegalArgumentException if id is null
*/
public IdentityItem(final String id, final AuthenticationState authenticationState, final boolean primary) {
public IdentityItem(final String id, final AuthenticatedState authenticatedState, final boolean primary) {
if (id == null) {
throw new IllegalArgumentException("id must be non-null");
}
this.id = id;
this.authenticationState = authenticationState != null ? authenticationState : AuthenticationState.AMBIGUOUS;
this.authenticatedState = authenticatedState != null ? authenticatedState : AuthenticatedState.AMBIGUOUS;
this.primary = primary;
}

/**
* Creates a new {@link IdentityItem} with default values
* authenticationState is set to AMBIGUOUS
* authenticatedState is set to AMBIGUOUS
* primary is set to false
* @param id the id for this {@link IdentityItem}
*/
public IdentityItem(final String id) {
this(id, AuthenticationState.AMBIGUOUS, false);
this(id, AuthenticatedState.AMBIGUOUS, false);
}

/**
* Creates a copy of item
* @param item A {@link IdentityItem} to be copied
*/
public IdentityItem(final IdentityItem item) {
this(item.id, item.authenticationState, item.primary);
this(item.id, item.authenticatedState, item.primary);
}

/**
Expand All @@ -72,10 +72,10 @@ Map<String, Object> toObjectMap() {
map.put(IdentityEdgeConstants.XDMKeys.ID, id);
}

if (authenticationState != null) {
map.put(IdentityEdgeConstants.XDMKeys.AUTHENTICATED_STATE, authenticationState.toString());
if (authenticatedState != null) {
map.put(IdentityEdgeConstants.XDMKeys.AUTHENTICATED_STATE, authenticatedState.getName());
} else {
map.put(IdentityEdgeConstants.XDMKeys.AUTHENTICATED_STATE, AuthenticationState.AMBIGUOUS.toString());
map.put(IdentityEdgeConstants.XDMKeys.AUTHENTICATED_STATE, AuthenticatedState.AMBIGUOUS.getName());
}

map.put(IdentityEdgeConstants.XDMKeys.PRIMARY, primary);
Expand All @@ -90,10 +90,10 @@ public String getId() {
}

/**
* @return Current {@link AuthenticationState} for this item
* @return Current {@link AuthenticatedState} for this item
*/
public AuthenticationState getAuthenticationState() {
return authenticationState;
public AuthenticatedState getAuthenticatedState() {
return authenticatedState;
}

/**
Expand All @@ -113,17 +113,17 @@ static IdentityItem fromData(final Map<String, Object> data) {

try {
final String id = (String) data.get(IdentityEdgeConstants.XDMKeys.ID);
AuthenticationState authenticationState = AuthenticationState.fromString((String) data.get(IdentityEdgeConstants.XDMKeys.AUTHENTICATED_STATE));
if (authenticationState == null) {
authenticationState = AuthenticationState.AMBIGUOUS;
AuthenticatedState authenticatedState = AuthenticatedState.fromString((String) data.get(IdentityEdgeConstants.XDMKeys.AUTHENTICATED_STATE));
if (authenticatedState == null) {
authenticatedState = AuthenticatedState.AMBIGUOUS;
}

boolean primary = false;
if (data.get(IdentityEdgeConstants.XDMKeys.PRIMARY) != null) {
primary = (boolean) data.get(IdentityEdgeConstants.XDMKeys.PRIMARY);
}

return new IdentityItem(id, authenticationState, primary);
return new IdentityItem(id, authenticatedState, primary);
} catch (ClassCastException e) {
MobileCore.log(LoggingMode.DEBUG, LOG_TAG, "Failed to create IdentityItem from data.");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,14 @@ public void test_handleUpdateIdentities() throws Exception {
verify(mockExtensionApi, times(1)).setXDMSharedEventState(sharedStateCaptor.capture(), eq(updateIdentityEvent), any(ExtensionErrorCallback.class));
Map<String, String> sharedState = flattenMap(sharedStateCaptor.getValue());
assertEquals("secretID", sharedState.get("identityMap.UserId[0].id"));
assertEquals("AMBIGUOUS", sharedState.get("identityMap.UserId[0].authenticatedState"));
assertEquals("ambiguous", sharedState.get("identityMap.UserId[0].authenticatedState"));
assertEquals("false", sharedState.get("identityMap.UserId[0].primary"));

// verify persistence
verify(mockSharedPreferenceEditor, times(2)).putString(eq(IdentityEdgeConstants.DataStoreKey.IDENTITY_PROPERTIES), persistenceValueCaptor.capture());
Map<String, String> persistedData = flattenJSONString(persistenceValueCaptor.getAllValues().get(1));
assertEquals("secretID", persistedData.get("identityMap.UserId[0].id"));
assertEquals("AMBIGUOUS", persistedData.get("identityMap.UserId[0].authenticatedState"));
assertEquals("ambiguous", persistedData.get("identityMap.UserId[0].authenticatedState"));
assertEquals("false", persistedData.get("identityMap.UserId[0].primary"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public void test_toXDMData_Full() {

// verify primary ECID
assertEquals(props.getECID().toString(), flatMap.get("identityMap.ECID[0].id"));
assertEquals("AMBIGUOUS", flatMap.get("identityMap.ECID[0].authenticatedState"));
assertEquals("ambiguous", flatMap.get("identityMap.ECID[0].authenticatedState"));
assertEquals("false", flatMap.get("identityMap.ECID[0].primary"));

// verify secondary ECID
assertEquals(props.getECIDSecondary().toString(), flatMap.get("identityMap.ECID[1].id"));
assertEquals("AMBIGUOUS", flatMap.get("identityMap.ECID[1].authenticatedState"));
assertEquals("ambiguous", flatMap.get("identityMap.ECID[1].authenticatedState"));
assertEquals("false", flatMap.get("identityMap.ECID[1].primary"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

package com.adobe.marketing.mobile.identityedge;

import android.provider.ContactsContract;

import com.adobe.marketing.mobile.AdobeCallback;
import com.adobe.marketing.mobile.AdobeCallbackWithError;
import com.adobe.marketing.mobile.AdobeError;
Expand Down Expand Up @@ -260,8 +258,8 @@ public void testUpdateIdentities() {

// test
IdentityMap map = new IdentityMap();
map.addItem(new IdentityItem("id", AuthenticationState.AUTHENTICATED, true),"mainspace");
map.addItem(new IdentityItem("idtwo", AuthenticationState.LOGGED_OUT, false),"secondspace");
map.addItem(new IdentityItem("id", AuthenticatedState.AUTHENTICATED, true),"mainspace");
map.addItem(new IdentityItem("idtwo", AuthenticatedState.LOGGED_OUT, false),"secondspace");
IdentityEdge.updateIdentities(map);

// verify
Expand Down Expand Up @@ -298,7 +296,7 @@ public void testRemoveIdentity() {
// setup
final ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
final ArgumentCaptor<ExtensionErrorCallback> extensionErrorCallbackCaptor = ArgumentCaptor.forClass(ExtensionErrorCallback.class);
IdentityItem sampleItem = new IdentityItem("sample", AuthenticationState.AMBIGUOUS, false);
IdentityItem sampleItem = new IdentityItem("sample", AuthenticatedState.AMBIGUOUS, false);

// test
IdentityEdge.removeIdentity(sampleItem, "namespace");
Expand All @@ -323,7 +321,7 @@ public void testRemoveIdentity() {
@Test
public void testRemoveIdentity_WithInvalidInputs() {
// setup
IdentityItem sampleItem = new IdentityItem("sample", AuthenticationState.AMBIGUOUS, false);
IdentityItem sampleItem = new IdentityItem("sample", AuthenticatedState.AMBIGUOUS, false);

// test
IdentityEdge.removeIdentity(null, "namespace");
Expand Down Expand Up @@ -396,11 +394,11 @@ public void call(IdentityMap map) {
IdentityItem coreItem = callbackReturnValues.get(0).getIdentityItemsForNamespace("CORE").get(0);

assertEquals(ecid.toString(), ecidItem.getId());
assertEquals(AuthenticationState.AMBIGUOUS, ecidItem.getAuthenticationState());
assertEquals(AuthenticatedState.AMBIGUOUS, ecidItem.getAuthenticatedState());
assertEquals(true, ecidItem.isPrimary());

assertEquals(coreId, coreItem.getId());
assertEquals(AuthenticationState.AUTHENTICATED, coreItem.getAuthenticationState());
assertEquals(AuthenticatedState.AUTHENTICATED, coreItem.getAuthenticatedState());
assertEquals(false, coreItem.isPrimary());

// TODO - enable when ExtensionError creation is available
Expand Down
Loading