Skip to content
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 @@ -33,9 +33,10 @@ open class AttributeListenerTestKit :
onAttributeReceived?.invoke(attributeKey, attributeValueList)
}

override fun setAllUserAttributes(
override fun onSetAllUserAttributes(
userAttributes: Map<String, String>,
userAttributeLists: Map<String, MutableList<String>>,
userAttributeLists: Map<String, List<String>>,
user: FilteredMParticleUser,
) {
setAllUserAttributes?.invoke(userAttributes, userAttributeLists)
userAttributes.forEach { onAttributeReceived?.invoke(it.key, it.value) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,23 @@ void onSetUserAttributeList(
@Nullable String attributeKey,
@Nullable List<String> attributeValueList,
@Nullable FilteredMParticleUser user);

/**
* Called when the full set of user attributes is synchronized for the current user.
*
* @param userAttributes scalar user attributes
* @param userAttributeLists list-valued user attributes when {@link #supportsAttributeLists()} is true;
* otherwise list values may be merged into scalars by the framework
* @param user filtered user context for this kit
*/
void onSetAllUserAttributes(
Map<String, String> userAttributes,
Map<String, List<String>> userAttributeLists,
FilteredMParticleUser user);
}

public interface AttributeListener extends BaseAttributeListener {

void setAllUserAttributes(Map<String, String> userAttributes, Map<String, List<String>> userAttributeLists);

void setUserIdentity(MParticle.IdentityType identityType, String identity);

void removeUserIdentity(MParticle.IdentityType identityType);
Expand Down Expand Up @@ -575,9 +586,8 @@ public interface UserAttributeListener extends BaseAttributeListener {

void onSetUserTag(String key, FilteredMParticleUser user);

void onSetAllUserAttributes(Map<String, String> userAttributes, Map<String, List<String>> userAttributeLists, FilteredMParticleUser user);

void onConsentStateUpdated(ConsentState oldState, ConsentState newState, FilteredMParticleUser user);

}

public interface BatchListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,34 +599,22 @@ public void onUserAttributesReceived(Map<String, String> userAttributes, Map<Str
userAttributeLists = mDataplanFilter.transformUserAttributes(userAttributeLists);
for (KitIntegration provider : providers.values()) {
try {
if ((provider instanceof KitIntegration.AttributeListener || provider instanceof KitIntegration.UserAttributeListener)
if ((provider instanceof KitIntegration.BaseAttributeListener listener)
&& !provider.isDisabled()) {
Map<String, String> filteredAttributeSingles = (Map<String, String>) KitConfiguration.filterAttributes(provider.getConfiguration().getUserAttributeFilters(),
userAttributes);
Map<String, List<String>> filteredAttributeLists = (Map<String, List<String>>) KitConfiguration.filterAttributes(provider.getConfiguration().getUserAttributeFilters(),
userAttributeLists);
boolean supportsAttributeLists = ((KitIntegration.BaseAttributeListener) provider).supportsAttributeLists();
if (provider instanceof KitIntegration.AttributeListener) {
if (supportsAttributeLists) {
((KitIntegration.AttributeListener) provider).setAllUserAttributes(filteredAttributeSingles, filteredAttributeLists);
} else {
Map<String, String> singlesCopy = new HashMap<>(filteredAttributeSingles);
for (Map.Entry<String, List<String>> entry : filteredAttributeLists.entrySet()) {
singlesCopy.put(entry.getKey(), KitUtils.join(entry.getValue()));
}
((KitIntegration.AttributeListener) provider).setAllUserAttributes(singlesCopy, new HashMap<String, List<String>>());
}
}
if (provider instanceof KitIntegration.UserAttributeListener) {
if (supportsAttributeLists) {
((KitIntegration.UserAttributeListener) provider).onSetAllUserAttributes(filteredAttributeSingles, filteredAttributeLists, FilteredMParticleUser.getInstance(mpid, provider));
} else {
Map<String, String> singlesCopy = new HashMap<>(filteredAttributeSingles);
for (Map.Entry<String, List<String>> entry : filteredAttributeLists.entrySet()) {
singlesCopy.put(entry.getKey(), KitUtils.join(entry.getValue()));
}
((KitIntegration.UserAttributeListener) provider).onSetAllUserAttributes(singlesCopy, new HashMap<String, List<String>>(), FilteredMParticleUser.getInstance(mpid, provider));
boolean supportsAttributeLists = listener.supportsAttributeLists();
FilteredMParticleUser filteredUser = FilteredMParticleUser.getInstance(mpid, provider);
if (supportsAttributeLists) {
listener.onSetAllUserAttributes(filteredAttributeSingles, filteredAttributeLists, filteredUser);
} else {
Map<String, String> singlesCopy = new HashMap<>(filteredAttributeSingles);
for (Map.Entry<String, List<String>> entry : filteredAttributeLists.entrySet()) {
singlesCopy.put(entry.getKey(), KitUtils.join(entry.getValue()));
}
listener.onSetAllUserAttributes(singlesCopy, new HashMap<String, List<String>>(), filteredUser);
}
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,15 +519,15 @@ class KitManagerImplTest {
attributeList.add("3")
userAttributeLists["test 3"] = attributeList
manager.onUserAttributesReceived(userAttributeSingles, userAttributeLists, 1L)
verify(integration as AttributeListener, Mockito.times(1))
.setAllUserAttributes(userAttributeSingles, userAttributeLists)
verify(integration as BaseAttributeListener, Mockito.times(1))
.onSetAllUserAttributes(eq(userAttributeSingles), eq(userAttributeLists), any())
val userAttributesCombined: MutableMap<String, String> = HashMap()
userAttributesCombined["test"] = "whatever"
userAttributesCombined["test 2"] = "whatever 2"
userAttributesCombined["test 3"] = "1,2,3"
val clearedOutList: Map<String, List<String>> = HashMap()
verify(integration2 as AttributeListener, Mockito.times(1))
.setAllUserAttributes(userAttributesCombined, clearedOutList)
verify(integration2 as BaseAttributeListener, Mockito.times(1))
.onSetAllUserAttributes(eq(userAttributesCombined), eq(clearedOutList), any())
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ abstract class AdobeKitBase :

override fun supportsAttributeLists(): Boolean = false

override fun setAllUserAttributes(
map: Map<String, String>,
map1: Map<String, List<String>>,
override fun onSetAllUserAttributes(
userAttributes: Map<String, String>,
userAttributeLists: Map<String, List<String>>,
user: FilteredMParticleUser,
) {
syncIds()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ open class AdobeKit :

override fun supportsAttributeLists(): Boolean = false

override fun setAllUserAttributes(
map: Map<String, String>,
map1: Map<String, List<String>>,
override fun onSetAllUserAttributes(
userAttributes: Map<String, String>,
userAttributeLists: Map<String, List<String>>,
user: FilteredMParticleUser,
) {
syncIds()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,11 @@ class AppsFlyerKit :
userAttributeLists: MutableMap<String, MutableList<String>>?,
user: FilteredMParticleUser?,
) {
// No-op: this kit does not implement this feature.
}

override fun supportsAttributeLists(): Boolean = true

override fun setAllUserAttributes(
map: Map<String, String>,
map1: Map<String, List<String>>,
) {
// No-op: this kit does not implement this feature.
}

override fun removeUserIdentity(identityType: MParticle.IdentityType) {
with(instance) {
if (MParticle.IdentityType.CustomerId == identityType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ class ApptimizeKit :
override fun supportsAttributeLists(): Boolean = false

/**
* @param attributeLists is ignored by the Apptimize kit.
* [userAttributeLists] is ignored by the Apptimize kit.
*/
override fun setAllUserAttributes(
attributes: Map<String, String>,
attributeLists: Map<String, List<String>>,
override fun onSetAllUserAttributes(
userAttributes: Map<String, String>,
userAttributeLists: Map<String, List<String>>,
user: FilteredMParticleUser,
) {
for ((key, value) in attributes) {
for ((key, value) in userAttributes) {
Apptimize.setUserAttribute(key, value)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,12 @@

override fun supportsAttributeLists(): Boolean = true

override fun setAllUserAttributes(
map: Map<String, String>,
map1: Map<String, List<String>>,
) {}
override fun onSetAllUserAttributes(
userAttributes: Map<String, String>,
userAttributeLists: Map<String, List<String>>,
user: FilteredMParticleUser,
) {
}

Check failure on line 192 in kits/branch/branch-5/src/main/kotlin/com/mparticle/kits/BranchMetricsKit.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a nested comment explaining why this function is empty or complete the implementation.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-android-sdk&issues=AZ1ORqD3O7fy5yC2gq_S&open=AZ1ORqD3O7fy5yC2gq_S&pullRequest=691

override fun onRemoveUserAttribute(
key: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
}

override fun onError() {
Logger.warning("unable to set key: " + keyIn + " with value: " + attributeValue)

Check failure on line 319 in kits/braze/braze-38/src/main/kotlin/com/mparticle/kits/AppboyKit.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "unable to set key: " 3 times.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-android-sdk&issues=AZ1ORqJsO7fy5yC2gq_U&open=AZ1ORqJsO7fy5yC2gq_U&pullRequest=691
}
},
)
Expand Down Expand Up @@ -535,6 +535,31 @@
userAttributeLists: MutableMap<String, MutableList<String>>?,
user: FilteredMParticleUser?,
) {
val attributes = userAttributes ?: emptyMap()
val attributeLists = userAttributeLists ?: emptyMap()
if (!kitPreferences.getBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, false)) {
for ((key, value) in attributes) {
applyScalarUserAttribute(key, value)
}
for ((key, value) in attributeLists) {
Braze
.getInstance(context)
.getCurrentUser(
object : IValueCallback<BrazeUser> {
override fun onSuccess(brazeUser: BrazeUser) {
val array = value.toTypedArray<String?>()
brazeUser.setCustomAttributeArray(key, array)
queueDataFlush()
}

override fun onError() {
Logger.warning("unable to set key: " + key + " with User Attribute List: " + value)
}
},
)
}
kitPreferences.edit().putBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, true).apply()
}
}

override fun supportsAttributeLists(): Boolean = true
Expand Down Expand Up @@ -672,38 +697,6 @@
dataFlushRunnable?.let { dataFlushHandler.postDelayed(it, FLUSH_DELAY.toLong()) }
}

/**
* This is called when the Kit is added to the mParticle SDK, typically on app-startup.
*/
override fun setAllUserAttributes(
attributes: Map<String, String>,
attributeLists: Map<String, List<String>>,
) {
if (!kitPreferences.getBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, false)) {
for ((key, value) in attributes) {
applyScalarUserAttribute(key, value)
}
for ((key, value) in attributeLists) {
Braze
.getInstance(context)
.getCurrentUser(
object : IValueCallback<BrazeUser> {
override fun onSuccess(brazeUser: BrazeUser) {
val array = value.toTypedArray<String?>()
brazeUser.setCustomAttributeArray(key, array)
queueDataFlush()
}

override fun onError() {
Logger.warning("unable to set key: " + key + " with User Attribute List: " + value)
}
},
)
}
kitPreferences.edit().putBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, true).apply()
}
}

override fun setUserIdentity(
identityType: IdentityType,
identity: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
}

override fun onError() {
Logger.warning("unable to set key: " + keyIn + " with value: " + attributeValue)

Check failure on line 319 in kits/braze/braze-39/src/main/kotlin/com/mparticle/kits/AppboyKit.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "unable to set key: " 3 times.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-android-sdk&issues=AZ1ORqJLO7fy5yC2gq_T&open=AZ1ORqJLO7fy5yC2gq_T&pullRequest=691
}
},
)
Expand Down Expand Up @@ -535,6 +535,31 @@
userAttributeLists: MutableMap<String, MutableList<String>>?,
user: FilteredMParticleUser?,
) {
val attributes = userAttributes ?: emptyMap()
val attributeLists = userAttributeLists ?: emptyMap()
if (!kitPreferences.getBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, false)) {
for ((key, value) in attributes) {
applyScalarUserAttribute(key, value)
}
for ((key, value) in attributeLists) {
Braze
.getInstance(context)
.getCurrentUser(
object : IValueCallback<BrazeUser> {
override fun onSuccess(brazeUser: BrazeUser) {
val array = value.toTypedArray<String?>()
brazeUser.setCustomAttributeArray(key, array)
queueDataFlush()
}

override fun onError() {
Logger.warning("unable to set key: " + key + " with User Attribute List: " + value)
}
},
)
}
kitPreferences.edit().putBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, true).apply()
}
}

override fun supportsAttributeLists(): Boolean = true
Expand Down Expand Up @@ -672,38 +697,6 @@
dataFlushRunnable?.let { dataFlushHandler.postDelayed(it, FLUSH_DELAY.toLong()) }
}

/**
* This is called when the Kit is added to the mParticle SDK, typically on app-startup.
*/
override fun setAllUserAttributes(
attributes: Map<String, String>,
attributeLists: Map<String, List<String>>,
) {
if (!kitPreferences.getBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, false)) {
for ((key, value) in attributes) {
applyScalarUserAttribute(key, value)
}
for ((key, value) in attributeLists) {
Braze
.getInstance(context)
.getCurrentUser(
object : IValueCallback<BrazeUser> {
override fun onSuccess(brazeUser: BrazeUser) {
val array = value.toTypedArray<String?>()
brazeUser.setCustomAttributeArray(key, array)
queueDataFlush()
}

override fun onError() {
Logger.warning("unable to set key: " + key + " with User Attribute List: " + value)
}
},
)
}
kitPreferences.edit().putBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, true).apply()
}
}

override fun setUserIdentity(
identityType: IdentityType,
identity: String,
Expand Down
Loading
Loading