diff --git a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeUtils.java b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeUtils.java index 36dd206..4e5197e 100644 --- a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeUtils.java +++ b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeUtils.java @@ -17,6 +17,7 @@ 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.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -248,39 +249,30 @@ protected static Map generateInteractionXdm( final String experienceEventType, final List pendingDisplayedPropositions, final Boolean shouldAppendOfferIds) { - List> decisioningPropositions = new ArrayList<>(); + List> propositions = new ArrayList<>(); if (!pendingDisplayedPropositions.isEmpty()) { for (OptimizeProposition prop : pendingDisplayedPropositions) { - - Map propositionItem = new HashMap<>(); - List> propositionItemsList = new ArrayList<>(); - - Map map = new HashMap<>(); - map.put(OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_ID, prop.getId()); - map.put(OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_SCOPE, prop.getScope()); - map.put( + Map proposition = new HashMap<>(); + proposition.put( + OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_ID, prop.getId()); + proposition.put( + OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_SCOPE, prop.getScope()); + proposition.put( OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_SCOPEDETAILS, prop.getScopeDetails()); - if (shouldAppendOfferIds - && !prop.getOffers().isEmpty() - && prop.getOffers().get(0).getId() != null) { - propositionItem.put( - OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_ITEMS_ID, - prop.getOffers().get(0).getId()); - propositionItemsList.add(propositionItem); - map.put( + if (shouldAppendOfferIds && !prop.getOffers().isEmpty()) { + proposition.put( OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_ITEMS, - propositionItemsList); + getOfferIds(prop)); } - - decisioningPropositions.add(map); + propositions.add(proposition); } } Map experienceDecisioning = new HashMap<>(); experienceDecisioning.put( - OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS, decisioningPropositions); + OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS, propositions); Map experience = new HashMap<>(); experience.put(OptimizeConstants.JsonKeys.EXPERIENCE_DECISIONING, experienceDecisioning); @@ -291,4 +283,22 @@ protected static Map generateInteractionXdm( return xdm; } + + private static List> getOfferIds(final OptimizeProposition prop) { + List> offersIds = new ArrayList<>(); + for (Offer offer : prop.getOffers()) { + if (!StringUtils.isNullOrEmpty(offer.getId())) { + offersIds.add( + new HashMap() { + { + put( + OptimizeConstants.JsonKeys + .DECISIONING_PROPOSITIONS_ITEMS_ID, + offer.getId()); + } + }); + } + } + return offersIds; + } }