3535import com .mparticle .identity .IdentityApi ;
3636import com .mparticle .identity .IdentityApiRequest ;
3737import com .mparticle .identity .IdentityApiResult ;
38- import com .mparticle .identity .IdentityHttpResponse ;
3938import com .mparticle .identity .IdentityStateListener ;
4039import com .mparticle .identity .MParticleUser ;
41- import com .mparticle .identity .TaskFailureListener ;
42- import com .mparticle .identity .TaskSuccessListener ;
4340import com .mparticle .internal .Constants ;
4441import com .mparticle .internal .CoreCallbacks ;
4542import com .mparticle .internal .KitManager ;
@@ -1366,41 +1363,9 @@ public void execute(@NonNull String viewName,
13661363 MParticleUser user = instance .Identity ().getCurrentUser ();
13671364 String email = getValueIgnoreCase (attributes , "email" );
13681365 String hashedEmail = getValueIgnoreCase (attributes , "emailsha256" );
1369- Map <String , String > finalAttributes = attributes ;
1366+ Map <String , String > tempAttributes = attributes ;
13701367 confirmEmail (email , hashedEmail , user , instance .Identity (), () -> {
1371- JSONArray jsonArray = new JSONArray ();
1372-
1373- KitConfiguration kitConfig = provider .getConfiguration ();
1374- if (kitConfig != null ) {
1375- try {
1376- jsonArray = kitConfig .getPlacementAttributesMapping ();
1377- } catch (JSONException e ) {
1378- Logger .warning ("Invalid placementAttributes for kit: " + provider .getName () + " JSON: " + e .getMessage ());
1379- }
1380- }
1381- for (int i = 0 ; i < jsonArray .length (); i ++) {
1382- JSONObject obj = jsonArray .optJSONObject (i );
1383- if (obj == null ) continue ;
1384- String mapFrom = obj .optString ("map" );
1385- String mapTo = obj .optString ("value" );
1386- if (finalAttributes .containsKey (mapFrom )) {
1387- String value = finalAttributes .remove (mapFrom );
1388- finalAttributes .put (mapTo , value );
1389- }
1390- }
1391- Map <String , Object > objectAttributes = new HashMap <>();
1392- for (Map .Entry <String , String > entry : finalAttributes .entrySet ()) {
1393- if (!entry .getKey ().equals (Constants .MessageKey .SANDBOX_MODE_ROKT )) {
1394- objectAttributes .put (entry .getKey (), entry .getValue ());
1395- }
1396- }
1397- if (user != null ) {
1398- user .setUserAttributes (objectAttributes );
1399- }
1400-
1401- if (!finalAttributes .containsKey (Constants .MessageKey .SANDBOX_MODE_ROKT )) {
1402- finalAttributes .put (Constants .MessageKey .SANDBOX_MODE_ROKT , Objects .toString (MPUtility .isDevEnv (), "false" )); // Default value is "false" if null
1403- }
1368+ Map <String , String > finalAttributes = prepareAttributes (provider , tempAttributes , user );
14041369
14051370 ((KitIntegration .RoktListener ) provider ).execute (viewName ,
14061371 finalAttributes ,
@@ -1426,6 +1391,43 @@ private String getValueIgnoreCase(Map<String, String> map, String searchKey) {
14261391 return null ;
14271392 }
14281393
1394+ private Map <String , String > prepareAttributes (KitIntegration provider , Map <String , String > finalAttributes , MParticleUser user ){
1395+ JSONArray jsonArray = new JSONArray ();
1396+
1397+ KitConfiguration kitConfig = provider .getConfiguration ();
1398+ if (kitConfig != null ) {
1399+ try {
1400+ jsonArray = kitConfig .getPlacementAttributesMapping ();
1401+ } catch (JSONException e ) {
1402+ Logger .warning ("Invalid placementAttributes for kit: " + provider .getName () + " JSON: " + e .getMessage ());
1403+ }
1404+ }
1405+ for (int i = 0 ; i < jsonArray .length (); i ++) {
1406+ JSONObject obj = jsonArray .optJSONObject (i );
1407+ if (obj == null ) continue ;
1408+ String mapFrom = obj .optString ("map" );
1409+ String mapTo = obj .optString ("value" );
1410+ if (finalAttributes .containsKey (mapFrom )) {
1411+ String value = finalAttributes .remove (mapFrom );
1412+ finalAttributes .put (mapTo , value );
1413+ }
1414+ }
1415+ Map <String , Object > objectAttributes = new HashMap <>();
1416+ for (Map .Entry <String , String > entry : finalAttributes .entrySet ()) {
1417+ if (!entry .getKey ().equals (Constants .MessageKey .SANDBOX_MODE_ROKT )) {
1418+ objectAttributes .put (entry .getKey (), entry .getValue ());
1419+ }
1420+ }
1421+ if (user != null ) {
1422+ user .setUserAttributes (objectAttributes );
1423+ }
1424+
1425+ if (!finalAttributes .containsKey (Constants .MessageKey .SANDBOX_MODE_ROKT )) {
1426+ finalAttributes .put (Constants .MessageKey .SANDBOX_MODE_ROKT , String .valueOf (Objects .toString (MPUtility .isDevEnv (), "false" ))); // Default value is "false" if null
1427+ }
1428+ return finalAttributes ;
1429+ }
1430+
14291431 @ Override
14301432 public Flow <RoktEvent > events (@ NonNull String identifier ) {
14311433 for (KitIntegration provider : providers .values ()) {
@@ -1481,6 +1483,32 @@ public void close() {
14811483 }
14821484 }
14831485
1486+ @ Override
1487+ public void prepareAttributesAsync (@ NonNull Map <String , String > attributes ) {
1488+
1489+ for (KitIntegration provider : providers .values ()) {
1490+ try {
1491+ if (provider instanceof KitIntegration .RoktListener && !provider .isDisabled ()) {
1492+ if (attributes == null ) {
1493+ attributes = new HashMap <>();
1494+ }
1495+ MParticle instance = MParticle .getInstance ();
1496+ MParticleUser user = instance .Identity ().getCurrentUser ();
1497+ String email = attributes .get ("email" );
1498+ String hashedEmail = getValueIgnoreCase (attributes , "emailsha256" );
1499+ Map <String , String > tempAttributes = attributes ;
1500+ confirmEmail (email , hashedEmail , user , instance .Identity (), () -> {
1501+ Map <String , String > finalAttributes = prepareAttributes (provider , tempAttributes , user );
1502+ ((KitIntegration .RoktListener ) provider ).enrichAttributes (
1503+ finalAttributes , FilteredMParticleUser .getInstance (user .getId (), provider ));
1504+ });
1505+ }
1506+ } catch (Exception e ) {
1507+ Logger .warning ("Failed to call prepareRoktListener for kit: " + provider .getName () + ": " + e .getMessage ());
1508+ }
1509+ }
1510+ }
1511+
14841512 private void confirmEmail (
14851513 @ Nullable String email ,
14861514 @ Nullable String hashedEmail ,
0 commit comments