Skip to content

Commit a166752

Browse files
author
Naman Arora
committed
generatePropositionInteractionXdm removed
1 parent 8e5f825 commit a166752

File tree

1 file changed

+1
-189
lines changed

1 file changed

+1
-189
lines changed

packages/messaging/android/src/main/java/com/adobe/marketing/mobile/reactnative/messaging/RCTAEPMessagingModule.java

Lines changed: 1 addition & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
import com.adobe.marketing.mobile.AdobeCallback;
2323
import com.adobe.marketing.mobile.AdobeCallbackWithError;
2424
import com.adobe.marketing.mobile.AdobeError;
25-
import com.adobe.marketing.mobile.LoggingMode;
2625
import com.adobe.marketing.mobile.Message;
2726
import com.adobe.marketing.mobile.Messaging;
2827
import com.adobe.marketing.mobile.MessagingEdgeEventType;
29-
import com.adobe.marketing.mobile.MobileCore;
3028
import com.adobe.marketing.mobile.messaging.MessagingUtils;
3129
import com.adobe.marketing.mobile.messaging.Proposition;
3230
import com.adobe.marketing.mobile.messaging.PropositionItem;
@@ -52,29 +50,13 @@
5250
import java.util.Map;
5351
import java.util.concurrent.CountDownLatch;
5452
import java.util.concurrent.ConcurrentHashMap;
55-
import org.json.JSONObject;
56-
57-
58-
import java.nio.charset.StandardCharsets;
59-
import java.util.UUID;
60-
import java.util.concurrent.atomic.AtomicLong;
6153

6254

6355

6456
public final class RCTAEPMessagingModule
6557
extends ReactContextBaseJavaModule implements PresentationDelegate {
66-
private final AtomicLong globalUuidCounter = new AtomicLong(0L);
6758
private final Map<String, PropositionItem> propositionItemByUuid = new ConcurrentHashMap<>();
6859

69-
public void registerPropositionItemUuid(@NonNull final String uuid, @NonNull final PropositionItem item) {
70-
if (uuid != null && item != null) {
71-
propositionItemByUuid.put(uuid, item);
72-
}
73-
}
74-
private String generateItemUuid(String activityId, long counter) {
75-
String key = (activityId != null ? activityId : "") + "#" + counter;
76-
return UUID.nameUUIDFromBytes(key.getBytes(StandardCharsets.UTF_8)).toString();
77-
}
7860
@SuppressWarnings("unchecked")
7961
private String extractActivityId(Proposition proposition) {
8062
try {
@@ -98,11 +80,6 @@ private String extractActivityId(Proposition proposition) {
9880
private CountDownLatch latch = new CountDownLatch(1);
9981
private Message latestMessage = null;
10082

101-
// Cache to store PropositionItem objects by their ID for unified tracking
102-
private final Map<String, PropositionItem> propositionItemCache = new ConcurrentHashMap<>();
103-
// Cache to store the parent Proposition for each PropositionItem
104-
private final Map<String, Proposition> propositionCache = new ConcurrentHashMap<>();
105-
10683
public RCTAEPMessagingModule(ReactApplicationContext reactContext) {
10784
super(reactContext);
10885
this.reactContext = reactContext;
@@ -210,7 +187,7 @@ public void call(Map<Surface, List<Proposition>> propositionsMap) {
210187
}
211188

212189
// Inject UUID and cache native item for future tracking
213-
final String uuid = generateItemUuid(activityId, globalUuidCounter.incrementAndGet());
190+
final String uuid = activityId;
214191
itemMap.putString("uuid", uuid);
215192
propositionItemByUuid.put(uuid, item);
216193

@@ -453,7 +430,6 @@ public void trackContentCardInteraction(ReadableMap propositionMap, ReadableMap
453430
* Tracks interactions with a PropositionItem using the provided interaction and event type.
454431
* This method is used by the React Native PropositionItem.track() method.
455432
*
456-
* @param itemId The unique identifier of the PropositionItem
457433
* @param interaction A custom string value to be recorded in the interaction (nullable)
458434
* @param eventType The MessagingEdgeEventType numeric value
459435
* @param tokens Array containing the sub-item tokens for recording interaction (nullable)
@@ -515,168 +491,4 @@ public void trackPropositionItem(String uuid, @Nullable String interaction, int
515491
}
516492
}
517493

518-
519-
520-
/**
521-
* Generates XDM data for PropositionItem interactions.
522-
* This method is used by the React Native PropositionItem.generateInteractionXdm() method.
523-
*
524-
* @param itemId The unique identifier of the PropositionItem
525-
* @param interaction A custom string value to be recorded in the interaction (nullable)
526-
* @param eventType The MessagingEdgeEventType numeric value
527-
* @param tokens Array containing the sub-item tokens for recording interaction (nullable)
528-
* @param promise Promise to resolve with XDM data for the proposition interaction
529-
*/
530-
@ReactMethod
531-
public void generatePropositionInteractionXdm(String itemId, @Nullable String interaction, int eventType, @Nullable ReadableArray tokens, Promise promise) {
532-
try {
533-
// Convert eventType int to MessagingEdgeEventType enum
534-
MessagingEdgeEventType edgeEventType = RCTAEPMessagingUtil.getEventType(eventType);
535-
if (edgeEventType == null) {
536-
promise.reject("InvalidEventType", "Invalid eventType: " + eventType);
537-
return;
538-
}
539-
540-
// Find the PropositionItem by ID
541-
PropositionItem propositionItem = findPropositionItemById(itemId);
542-
543-
if (propositionItem == null) {
544-
promise.reject("PropositionItemNotFound", "No PropositionItem found with ID: " + itemId);
545-
return;
546-
}
547-
548-
// Convert ReadableArray to List<String> if provided
549-
List<String> tokenList = null;
550-
if (tokens != null) {
551-
tokenList = new ArrayList<>();
552-
for (int i = 0; i < tokens.size(); i++) {
553-
tokenList.add(tokens.getString(i));
554-
}
555-
}
556-
557-
// Generate XDM data using the appropriate method
558-
Map<String, Object> xdmData;
559-
if (interaction != null && tokenList != null) {
560-
xdmData = propositionItem.generateInteractionXdm(interaction, edgeEventType, tokenList);
561-
} else if (interaction != null) {
562-
xdmData = propositionItem.generateInteractionXdm(interaction, edgeEventType, null);
563-
} else {
564-
xdmData = propositionItem.generateInteractionXdm(edgeEventType);
565-
}
566-
567-
if (xdmData != null) {
568-
// Convert Map to WritableMap for React Native
569-
WritableMap result = RCTAEPMessagingUtil.toWritableMap(xdmData);
570-
promise.resolve(result);
571-
} else {
572-
promise.reject("XDMGenerationFailed", "Failed to generate XDM data for PropositionItem: " + itemId);
573-
}
574-
575-
} catch (Exception e) {
576-
// Log.error(TAG, "Error generating XDM data for PropositionItem: " + itemId + ", error: " + e.getMessage());
577-
promise.reject("XDMGenerationError", "Error generating XDM data: " + e.getMessage(), e);
578-
}
579-
}
580-
581-
/**
582-
* Caches a PropositionItem and its parent Proposition for later tracking.
583-
* This method should be called when PropositionItems are created from propositions.
584-
*
585-
* @param propositionItem The PropositionItem to cache
586-
* @param parentProposition The parent Proposition containing this item
587-
*/
588-
public void cachePropositionItem(PropositionItem propositionItem, Proposition parentProposition) {
589-
if (propositionItem != null && propositionItem.getItemId() != null) {
590-
String itemId = propositionItem.getItemId();
591-
592-
// Cache the PropositionItem
593-
propositionItemCache.put(itemId, propositionItem);
594-
595-
// Cache the parent Proposition
596-
if (parentProposition != null) {
597-
propositionCache.put(itemId, parentProposition);
598-
599-
// Set the proposition reference in the PropositionItem if possible
600-
try {
601-
// Use reflection to set the proposition reference
602-
java.lang.reflect.Field propositionRefField = propositionItem.getClass().getDeclaredField("propositionReference");
603-
propositionRefField.setAccessible(true);
604-
propositionRefField.set(propositionItem, new java.lang.ref.SoftReference<>(parentProposition));
605-
} catch (Exception e) {
606-
607-
}
608-
}
609-
610-
}
611-
}
612-
613-
/**
614-
* Caches multiple PropositionItems from a list of propositions.
615-
* This is a convenience method for caching all items from multiple propositions.
616-
*
617-
* @param propositions List of propositions containing items to cache
618-
*/
619-
public void cachePropositionsItems(List<Proposition> propositions) {
620-
if (propositions != null) {
621-
for (Proposition proposition : propositions) {
622-
if (proposition.getItems() != null) {
623-
for (PropositionItem item : proposition.getItems()) {
624-
cachePropositionItem(item, proposition);
625-
}
626-
}
627-
}
628-
}
629-
}
630-
631-
/**
632-
* Finds a cached PropositionItem by its ID.
633-
*
634-
* @param itemId The ID of the PropositionItem to find
635-
* @return The PropositionItem if found, null otherwise
636-
*/
637-
private PropositionItem findPropositionItemById(String itemId) {
638-
return propositionItemCache.get(itemId);
639-
}
640-
641-
/**
642-
* Finds a cached parent Proposition by PropositionItem ID.
643-
*
644-
* @param itemId The ID of the PropositionItem whose parent to find
645-
* @return The parent Proposition if found, null otherwise
646-
*/
647-
private Proposition findPropositionByItemId(String itemId) {
648-
return propositionCache.get(itemId);
649-
}
650-
651-
/**
652-
* Clears the PropositionItem cache.
653-
* This should be called when propositions are refreshed or when memory cleanup is needed.
654-
*/
655-
@ReactMethod
656-
public void clearPropositionItemCache() {
657-
propositionItemCache.clear();
658-
propositionCache.clear();
659-
}
660-
661-
/**
662-
* Gets the current size of the PropositionItem cache.
663-
* Useful for debugging and monitoring.
664-
*
665-
* @param promise Promise that resolves with the cache size
666-
*/
667-
@ReactMethod
668-
public void getPropositionItemCacheSize(Promise promise) {
669-
promise.resolve(propositionItemCache.size());
670-
}
671-
672-
/**
673-
* Checks if a PropositionItem exists in the cache.
674-
*
675-
* @param itemId The ID of the PropositionItem to check
676-
* @param promise Promise that resolves with boolean indicating if item exists
677-
*/
678-
@ReactMethod
679-
public void hasPropositionItem(String itemId, Promise promise) {
680-
promise.resolve(propositionItemCache.containsKey(itemId));
681-
}
682494
}

0 commit comments

Comments
 (0)