Skip to content

Commit

Permalink
Merge pull request #86 from adobe/staging
Browse files Browse the repository at this point in the history
Staging v3.0.1 -> main
  • Loading branch information
spoorthipujariadobe authored May 21, 2024
2 parents 60110d4 + f4528d8 commit a41b4a4
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 64 deletions.
2 changes: 1 addition & 1 deletion code/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ org.gradle.caching=true
android.useAndroidX=true

moduleName=optimize
moduleVersion=3.0.0
moduleVersion=3.0.1

#Maven artifact
mavenRepoName=AdobeMobileOptimizeSdk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class OptimizeTestConstants {

static final String EXTENSION_VERSION = "3.0.0";
static final String EXTENSION_VERSION = "3.0.1";
public static final String LOG_TAG = "OptimizeTest";
static final String CONFIG_DATA_STORE = "AdobeMobile_ConfigState";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,33 +92,46 @@ boolean isValid() {
}

final String jsonString = OptimizeUtils.base64Decode(name);

// Since name can be any plain string in case of Target mbox
// return true if base64 decoding fails
if (OptimizeUtils.isNullOrEmpty(jsonString)) {
Log.debug(
Log.trace(
OptimizeConstants.LOG_TAG,
SELF_TAG,
"Invalid scope (%s)! Base64Decoded Scope name is null or empty.",
"Base64Decoded scope name is null or empty.",
name);
return false;
return true;
}
try {
// If the scope name represents an ODE encoded decision scope
// the decoded value will be a JSON string
final JSONObject jsonObject = new JSONObject(jsonString);

// A valid ODE decision scope will be in one of the following formats:
// 1. JSON object having key "xdm:name" with non null and non empty value
if (jsonObject.has(OptimizeConstants.XDM_NAME)) {
final String scopeName = jsonObject.getString(OptimizeConstants.XDM_NAME);
if (OptimizeUtils.isNullOrEmpty(scopeName)) {
Log.debug(
OptimizeConstants.LOG_TAG,
SELF_TAG,
"Invalid scope (%s)! Scope name is null or empty.",
"Invalid encoded decision scope (%s)! Scope name is null or empty.",
name);
return false;
}
} else if (jsonObject.has(OptimizeConstants.XDM_ACTIVITY_ID)) {
}

// 2. JSON object having key "xdm:activityId" with non null and non empty value
// and key "xdm:placementId" with non null and non empty value
// and key "xdm:itemCount" with value greater than 0
else if (jsonObject.has(OptimizeConstants.XDM_ACTIVITY_ID)) {
final String activityId = jsonObject.getString(OptimizeConstants.XDM_ACTIVITY_ID);
if (OptimizeUtils.isNullOrEmpty(activityId)) {
Log.debug(
OptimizeConstants.LOG_TAG,
SELF_TAG,
"Invalid scope (%s)! Activity Id is null or empty.",
"Invalid encoded decision scope (%s)! Activity Id is null or empty.",
name);
return false;
}
Expand All @@ -128,7 +141,7 @@ boolean isValid() {
Log.debug(
OptimizeConstants.LOG_TAG,
SELF_TAG,
"Invalid scope (%s)! Placement Id is null or empty.",
"Invalid encoded decision scope (%s)! Placement Id is null or empty.",
name);
return false;
}
Expand All @@ -139,18 +152,23 @@ boolean isValid() {
Log.debug(
OptimizeConstants.LOG_TAG,
SELF_TAG,
"Invalid scope (%s)! Item count (%d) is invalid.",
"Invalid encoded decision scope (%s)! Item count (%d) is invalid.",
name,
itemCount);
return false;
}
} else {
}

// 3. JSON object having key "activityId" with non null and non empty value
// and key "placementId" with non null and non empty value
// and key "itemCount" with value greater than 0
else {
final String activityId = jsonObject.getString(OptimizeConstants.ACTIVITY_ID);
if (OptimizeUtils.isNullOrEmpty(activityId)) {
Log.debug(
OptimizeConstants.LOG_TAG,
SELF_TAG,
"Invalid scope (%s)! Activity Id is null or empty.",
"Invalid encoded decision scope (%s)! Activity Id is null or empty.",
name);
return false;
}
Expand All @@ -160,7 +178,7 @@ boolean isValid() {
Log.debug(
OptimizeConstants.LOG_TAG,
SELF_TAG,
"Invalid scope (%s)! Placement Id is null or empty.",
"Invalid encoded decision scope (%s)! Placement Id is null or empty.",
name);
return false;
}
Expand All @@ -171,22 +189,32 @@ boolean isValid() {
Log.debug(
OptimizeConstants.LOG_TAG,
SELF_TAG,
"Invalid scope (%s)! Item count (%d) is invalid.",
"Invalid encoded decision scope (%s)! Item count (%d) is invalid.",
name,
itemCount);
return false;
}
}
} catch (JSONException e) {
Log.warning(
// name represents a valid ODE encoded decision scope
Log.trace(
OptimizeConstants.LOG_TAG,
SELF_TAG,
"Scope name (%s), when decoded, does not contain a JSON string.",
"Encoded decision scope (%s) is valid.",
name);
return true;
} catch (JSONException e) {
// Since name can be any string in case of Target mbox,
// return true if the name is decodable but decoded name is not a JSON string
// or does not have the required JSON keys
Log.trace(
OptimizeConstants.LOG_TAG,
SELF_TAG,
"Scope name (%s), when decoded, does not contain a JSON string"
+ "or does have the required JSON keys. Error: %s",
name,
e.getLocalizedMessage());
return true;
}

Log.trace(OptimizeConstants.LOG_TAG, SELF_TAG, "Decision scope (%s) is valid.", name);
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public Map<String, String> getCharacteristics() {
}

/**
* Gets the containing {@code Proposition} for this {@code Offer}.
* Gets the containing {@code OptimizeProposition} for this {@code Offer}.
*
* @return {@link OptimizeProposition} instance.
*/
Expand All @@ -277,7 +277,7 @@ public OptimizeProposition getProposition() {

/**
* Dispatches an event for the Edge network extension to send an Experience Event to the Edge
* network with the display interaction data for the given {@code Proposition} offer.
* network with the display interaction data for the given {@code OptimizeProposition} offer.
*
* @see Offer#trackWithData(Map)
*/
Expand All @@ -287,7 +287,7 @@ public void displayed() {

/**
* Dispatches an event for the Edge network extension to send an Experience Event to the Edge
* network with the tap interaction data for the given {@code Proposition} offer.
* network with the tap interaction data for the given {@code OptimizeProposition} offer.
*
* @see Offer#trackWithData(Map)
*/
Expand All @@ -296,8 +296,8 @@ public void tapped() {
}

/**
* Generates a map containing XDM formatted data for {@code Experience Event - Proposition
* Interactions} field group from this {@code Proposition} item.
* Generates a map containing XDM formatted data for {@code Experience Event -
* OptimizeProposition Interactions} field group from this {@code OptimizeProposition} item.
*
* <p>The returned XDM data does contain the {@code eventType} for the Experience Event with
* value {@code decisioning.propositionDisplay}.
Expand All @@ -314,8 +314,8 @@ public Map<String, Object> generateDisplayInteractionXdm() {
}

/**
* Generates a map containing XDM formatted data for {@code Experience Event - Proposition
* Interactions} field group from this {@code Proposition} offer.
* Generates a map containing XDM formatted data for {@code Experience Event -
* OptimizeProposition Interactions} field group from this {@code OptimizeProposition} offer.
*
* <p>The returned XDM data contains the {@code eventType} for the Experience Event with value
* {@code decisioning.propositionInteract}.
Expand All @@ -332,9 +332,9 @@ public Map<String, Object> generateTapInteractionXdm() {
}

/**
* Generates a map containing XDM formatted data for {@code Experience Event - Proposition
* Interactions} field group from this {@code Proposition} offer and given {@code
* experienceEventType}.
* Generates a map containing XDM formatted data for {@code Experience Event -
* OptimizeProposition Interactions} field group from this {@code OptimizeProposition} offer and
* given {@code experienceEventType}.
*
* <p>The method returns null if the proposition reference within the offer is released and no
* longer valid.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public static void updatePropositions(
*
* @param decisionScopes {@code List<DecisionScope>} containing scopes for which offers need to
* be requested.
* @param callback {@code AdobeCallbackWithError<Map<DecisionScope, Proposition>>} which will be
* invoked when decision propositions are retrieved from the local cache.
* @param callback {@code AdobeCallbackWithError<Map<DecisionScope, OptimizeProposition>>} which
* will be invoked when decision propositions are retrieved from the local cache.
*/
public static void getPropositions(
@NonNull final List<DecisionScope> decisionScopes,
Expand Down Expand Up @@ -245,8 +245,8 @@ public void call(final Event event) {
* Optimize#updatePropositions(List, Map, Map)} API, Edge extension {@code
* sendEvent(ExperienceEvent, EdgeCallback)} API or launch consequence rules.
*
* @param callback {@code AdobeCallbackWithError<Map<DecisionScope, Proposition>>} which will be
* invoked when decision propositions are received from the Edge network.
* @param callback {@code AdobeCallbackWithError<Map<DecisionScope, OptimizeProposition>>} which
* will be invoked when decision propositions are received from the Edge network.
*/
public static void onPropositionsUpdate(
@NonNull final AdobeCallback<Map<DecisionScope, OptimizeProposition>> callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class OptimizeConstants {
static final String LOG_TAG = "Optimize";
static final String EXTENSION_VERSION = "3.0.0";
static final String EXTENSION_VERSION = "3.0.1";
static final String EXTENSION_NAME = "com.adobe.optimize";
static final String FRIENDLY_NAME = "Optimize";
static final long DEFAULT_RESPONSE_CALLBACK_TIMEOUT = 500L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@

public class OptimizeProposition {

private static final String SELF_TAG = "Proposition";
private static final String SELF_TAG = "OptimizeProposition";

private final String id;
private final List<Offer> offers;
private final String scope;
private final Map<String, Object> scopeDetails;

/**
* Constructor creates a {@code Proposition} using the provided proposition {@code id}, {@code
* offers}, {@code scope} and {@code scopeDetails}.
* Constructor creates a {@code OptimizeProposition} using the provided proposition {@code id},
* {@code offers}, {@code scope} and {@code scopeDetails}.
*
* @param id {@link String} containing proposition identifier.
* @param offers {@code List<Offer>} containing proposition items.
Expand All @@ -48,7 +48,7 @@ public class OptimizeProposition {
this.scopeDetails = scopeDetails != null ? scopeDetails : new HashMap<>();

this.offers = offers != null ? offers : new ArrayList<>();
// Setting a soft reference to Proposition in each Offer
// Setting a soft reference to OptimizeProposition in each Offer
for (final Offer o : this.offers) {
if (o.propositionReference == null) {
o.propositionReference = new SoftReference<>(this);
Expand All @@ -57,7 +57,7 @@ public class OptimizeProposition {
}

/**
* Gets the {@code Proposition} identifier.
* Gets the {@code OptimizeProposition} identifier.
*
* @return {@link String} containing the {@link OptimizeProposition} identifier.
*/
Expand All @@ -66,7 +66,7 @@ public String getId() {
}

/**
* Gets the {@code Proposition} items.
* Gets the {@code OptimizeProposition} items.
*
* @return {@code List<Offer>} containing the {@link OptimizeProposition} items.
*/
Expand All @@ -75,7 +75,7 @@ public List<Offer> getOffers() {
}

/**
* Gets the {@code Proposition} scope.
* Gets the {@code OptimizeProposition} scope.
*
* @return {@link String} containing the encoded {@link OptimizeProposition} scope.
*/
Expand All @@ -84,7 +84,7 @@ public String getScope() {
}

/**
* Gets the {@code Proposition} scope details.
* Gets the {@code OptimizeProposition} scope details.
*
* @return {@code Map<String, Object>} containing the {@link OptimizeProposition} scope details.
*/
Expand All @@ -93,8 +93,8 @@ public Map<String, Object> getScopeDetails() {
}

/**
* Generates a map containing XDM formatted data for {@code Experience Event - Proposition
* Reference} field group from this {@code Proposition}.
* Generates a map containing XDM formatted data for {@code Experience Event -
* OptimizeProposition Reference} field group from this {@code OptimizeProposition}.
*
* <p>The returned XDM data does not contain {@code eventType} for the Experience Event.
*
Expand All @@ -114,20 +114,21 @@ public Map<String, Object> generateReferenceXdm() {
}

/**
* Creates a {@code Proposition} object using information provided in {@code data} map.
* Creates a {@code OptimizeProposition} object using information provided in {@code data} map.
*
* <p>This method returns null if the provided {@code data} is empty or null or if it does not
* contain required info for creating a {@link OptimizeProposition} object.
*
* @param data {@code Map<String, Object>} containing proposition data.
* @return {@code Proposition} object or null.
* @return {@code OptimizeProposition} object or null.
*/
public static OptimizeProposition fromEventData(final Map<String, Object> data) {
if (OptimizeUtils.isNullOrEmpty(data)) {
Log.debug(
OptimizeConstants.LOG_TAG,
SELF_TAG,
"Cannot create Proposition object, provided data Map is empty or null.");
"Cannot create OptimizeProposition object, provided data Map is empty or"
+ " null.");
return null;
}

Expand All @@ -137,7 +138,7 @@ public static OptimizeProposition fromEventData(final Map<String, Object> data)
Log.debug(
OptimizeConstants.LOG_TAG,
SELF_TAG,
"Cannot create Proposition object, provided data does not contain"
"Cannot create OptimizeProposition object, provided data does not contain"
+ " proposition identifier.");
return null;
}
Expand All @@ -147,7 +148,7 @@ public static OptimizeProposition fromEventData(final Map<String, Object> data)
Log.debug(
OptimizeConstants.LOG_TAG,
SELF_TAG,
"Cannot create Proposition object, provided data does not contain"
"Cannot create OptimizeProposition object, provided data does not contain"
+ " proposition scope.");
return null;
}
Expand Down Expand Up @@ -175,13 +176,14 @@ public static OptimizeProposition fromEventData(final Map<String, Object> data)
Log.warning(
OptimizeConstants.LOG_TAG,
SELF_TAG,
"Cannot create Proposition object, provided data contains invalid fields.");
"Cannot create OptimizeProposition object, provided data contains invalid"
+ " fields.");
return null;
}
}

/**
* Creates a {@code Map<String, Object>} using this {@code Proposition}'s attributes.
* Creates a {@code Map<String, Object>} using this {@code OptimizeProposition}'s attributes.
*
* @return {@code Map<String, Object>} containing {@link OptimizeProposition} data.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static String base64Decode(final String str) {
try {
output = new String(Base64.decode(str, Base64.DEFAULT));
} catch (final IllegalArgumentException ex) {
Log.debug(
Log.trace(
OptimizeConstants.LOG_TAG,
SELF_TAG,
String.format(
Expand Down
Loading

0 comments on commit a41b4a4

Please sign in to comment.