Skip to content

Commit

Permalink
Merge pull request #120 from adobe/staging
Browse files Browse the repository at this point in the history
Staging to Main
  • Loading branch information
navratan-soni authored Dec 6, 2024
2 parents e14d4ff + 632cba5 commit f927b25
Show file tree
Hide file tree
Showing 15 changed files with 1,673 additions and 90 deletions.
58 changes: 58 additions & 0 deletions Documentation/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Refer to the [Getting Started Guide](getting-started.md).
- [onPropositionsUpdate](#onPropositionsUpdate)
- [resetIdentities](#resetIdentities)
- [updatePropositions](#updatePropositions)
- [updatePropositionsWithCompletionHandler](#updatePropositionsWithCompletionHandler)

## Public classes

Expand Down Expand Up @@ -184,6 +185,63 @@ Optimize.updatePropositions(decisionScopes,
});
```

## updatePropositionsWithCompletionHandler

This API dispatches an event for the Edge network extension to fetch decision propositions, for the provided decision scopes array, from the decisioning services enabled in the Experience Edge. The returned decision propositions are cached in-memory in the Optimize SDK extension and can be retrieved using `getPropositions` API.

> [!TIP]
> Completion callback passed to `updatePropositions` supports network timeout and fatal errors returned by edge network along with fetched propositions data. The SDK's internal retry mechanism handles the recoverable HTTP errors. As a result, recoverable HTTP errors are not returned through this callback.
### Java

#### Syntax

```java
public static void updatePropositions(final List<DecisionScope> decisionScopes,
final Map<String, Object> xdm,
final Map<String, Object> data,
final AdobeCallback<Map<DecisionScope, OptimizeProposition>> callback)
```

* _decisionScopes_ is a list of decision scopes for which propositions need updating.
* _xdm_ is a map containing additional xdm formatted data to be attached to the Experience Event.
* _data_ is a map containing additional freeform data to be attached to the Experience Event.
* _callback_ is an optional completion handler that is invoked at the completion of the edge request. `call` method is invoked with propositions map of type `Map<DecisionScope, OptimizeProposition>`. If the callback is an instance of `AdobeCallbackWithOptimizeError`, and if the operation times out or an error occurs in retrieving propositions, the `fail` method is invoked with the appropriate [AEPOptimizeError](https://developer.adobe.com/client-sdks/edge/adobe-journey-optimizer-decisioning/api-reference/#aepoptimizeerror). _Note:_ In certain cases, both the success and failure callbacks may be triggered. To handle these cases, ensure that your implementation checks for both successful propositions and errors within the callback, as both may be present simultaneously.

#### Example

```java
final DecisionScope decisionScope1 = DecisionScope("xcore:offer-activity:1111111111111111", "xcore:offer-placement:1111111111111111", 2);
final DecisionScope decisionScope2 = new DecisionScope("myScope");

final List<DecisionScope> decisionScopes = new ArrayList<>();
decisionScopes.add(decisionScope1);
decisionScopes.add(decisionScope2);

Optimize.updatePropositions(decisionScopes,
new HashMap<String, Object>() {
{
put("xdmKey", "xdmValue");
}
},
new HashMap<String, Object>() {
{
put("dataKey", "dataValue");
}
},
new AdobeCallbackWithOptimizeError<Map<DecisionScope, OptimizeProposition>>() {
@Override
public void fail(AEPOptimizeError optimizeError) {
responseError = optimizeError;
}

@Override
public void call(Map<DecisionScope, OptimizeProposition> propositionsMap) {
responseMap = propositionsMap;
}
});
```

## Public classes

### DecisionScope
Expand Down
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.1.0
moduleVersion=3.2.2

#Maven artifact
mavenRepoName=AdobeMobileOptimizeSdk
Expand Down

Large diffs are not rendered by default.

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.1.0";
static final String EXTENSION_VERSION = "3.2.2";
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 @@ -84,6 +84,7 @@ data class AEPOptimizeError(
return getAdobeErrorFromStatus(data[STATUS] as Int?)
}

@JvmStatic
fun getTimeoutError(): AEPOptimizeError {
return AEPOptimizeError(
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private Optimize() {}
* @param data {@code Map<String, Object>} containing additional free-form data to be sent in
* the personalization query request.
*/
@Deprecated
public static void updatePropositions(
@NonNull final List<DecisionScope> decisionScopes,
@Nullable final Map<String, Object> xdm,
Expand Down Expand Up @@ -88,6 +89,45 @@ public static void updatePropositions(
@Nullable final Map<String, Object> xdm,
@Nullable final Map<String, Object> data,
@Nullable final AdobeCallback<Map<DecisionScope, OptimizeProposition>> callback) {
final double defaultTimeoutSeconds =
OptimizeConstants.EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT;
updatePropositionsInternal(decisionScopes, xdm, data, defaultTimeoutSeconds, callback);
}

/**
* This API dispatches an Event for the Edge network extension to fetch decision propositions,
* for the provided decision scopes list, from the decisioning services enabled in the
* Experience Edge network.
*
* <p>The returned decision propositions are cached in-memory in the Optimize SDK extension and
* can be retrieved using {@link #getPropositions(List, double, AdobeCallback)} API.
*
* @param decisionScopes {@code List<DecisionScope>} containing scopes for which offers need to
* be updated.
* @param xdm {@code Map<String, Object>} containing additional XDM-formatted data to be sent in
* the personalization query request.
* @param data {@code Map<String, Object>} containing additional free-form data to be sent in
* the personalization query request.
* @param timeoutSeconds {@code Double} containing additional configurable timeout(seconds) to
* be sent in the personalization query request.
* @param callback {@code AdobeCallback<Map<DecisionScope, OptimizeProposition>>} which will be
* invoked when decision propositions are received from the Edge network.
*/
public static void updatePropositions(
@NonNull final List<DecisionScope> decisionScopes,
@Nullable final Map<String, Object> xdm,
@Nullable final Map<String, Object> data,
final double timeoutSeconds,
@Nullable final AdobeCallback<Map<DecisionScope, OptimizeProposition>> callback) {
updatePropositionsInternal(decisionScopes, xdm, data, timeoutSeconds, callback);
}

private static void updatePropositionsInternal(
@NonNull final List<DecisionScope> decisionScopes,
@Nullable final Map<String, Object> xdm,
@Nullable final Map<String, Object> data,
final double timeoutSeconds,
@Nullable final AdobeCallback<Map<DecisionScope, OptimizeProposition>> callback) {

if (OptimizeUtils.isNullOrEmpty(decisionScopes)) {
Log.warning(
Expand Down Expand Up @@ -138,6 +178,10 @@ public static void updatePropositions(
eventData.put(OptimizeConstants.EventDataKeys.DATA, data);
}

long timeoutMillis = (long) (timeoutSeconds * OptimizeConstants.TIMEOUT_CONVERSION_FACTOR);

eventData.put(OptimizeConstants.EventDataKeys.TIMEOUT, timeoutMillis);

final Event event =
new Event.Builder(
OptimizeConstants.EventNames.UPDATE_PROPOSITIONS_REQUEST,
Expand All @@ -148,7 +192,7 @@ public static void updatePropositions(

MobileCore.dispatchEventWithResponseCallback(
event,
OptimizeConstants.EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT,
timeoutMillis,
new AdobeCallbackWithError<Event>() {
@Override
public void fail(final AdobeError adobeError) {
Expand Down Expand Up @@ -236,6 +280,30 @@ public void call(final Event event) {
public static void getPropositions(
@NonNull final List<DecisionScope> decisionScopes,
@NonNull final AdobeCallback<Map<DecisionScope, OptimizeProposition>> callback) {
final double defaultTimeoutSeconds = OptimizeConstants.GET_RESPONSE_CALLBACK_TIMEOUT;
getPropositionsInternal(decisionScopes, defaultTimeoutSeconds, callback);
}

/**
* This API retrieves the previously fetched propositions, for the provided decision scopes,
* from the in-memory extension propositions cache.
*
* @param decisionScopes {@code List<DecisionScope>} containing scopes for which offers need to
* be requested.
* @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,
final double timeoutSeconds,
@NonNull final AdobeCallback<Map<DecisionScope, OptimizeProposition>> callback) {
getPropositionsInternal(decisionScopes, timeoutSeconds, callback);
}

private static void getPropositionsInternal(
@NonNull final List<DecisionScope> decisionScopes,
final double timeoutSeconds,
@NonNull final AdobeCallback<Map<DecisionScope, OptimizeProposition>> callback) {
if (OptimizeUtils.isNullOrEmpty(decisionScopes)) {
Log.warning(
OptimizeConstants.LOG_TAG,
Expand Down Expand Up @@ -282,11 +350,11 @@ public static void getPropositions(
.setEventData(eventData)
.build();

// Increased default response callback timeout to 10s to ensure prior update propositions
// requests have enough time to complete.
long timeoutMillis = (long) (timeoutSeconds * OptimizeConstants.TIMEOUT_CONVERSION_FACTOR);

MobileCore.dispatchEventWithResponseCallback(
event,
OptimizeConstants.GET_RESPONSE_CALLBACK_TIMEOUT,
timeoutMillis,
new AdobeCallbackWithError<Event>() {
@Override
public void fail(final AdobeError adobeError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

class OptimizeConstants {
static final String LOG_TAG = "Optimize";
static final String EXTENSION_VERSION = "3.1.0";
static final String EXTENSION_VERSION = "3.2.2";
static final String EXTENSION_NAME = "com.adobe.optimize";
static final String FRIENDLY_NAME = "Optimize";
static final long DEFAULT_RESPONSE_CALLBACK_TIMEOUT = 500L;
static final long GET_RESPONSE_CALLBACK_TIMEOUT = 10000L;
static final long EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT = 10000L;
static final double GET_RESPONSE_CALLBACK_TIMEOUT = 10;
static final double EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT = 10;
static final long TIMEOUT_CONVERSION_FACTOR = 1000;

static final String ACTIVITY_ID = "activityId";
static final String XDM_ACTIVITY_ID = "xdm:activityId";
Expand Down Expand Up @@ -64,6 +64,7 @@ static final class EventSource {
static final String NOTIFICATION = "com.adobe.eventSource.notification";
static final String EDGE_PERSONALIZATION_DECISIONS = "personalization:decisions";
static final String CONTENT_COMPLETE = "com.adobe.eventSource.contentComplete";
static final String DEBUG = "com.adobe.eventSource.debug";

private EventSource() {}
}
Expand All @@ -74,6 +75,7 @@ static final class EventDataKeys {
static final String DECISION_SCOPE_NAME = "name";
static final String XDM = "xdm";
static final String DATA = "data";
static final String TIMEOUT = "timeout";
static final String PROPOSITIONS = "propositions";
static final String RESPONSE_ERROR = "responseerror";
static final String PROPOSITION_INTERACTIONS = "propositioninteractions";
Expand Down
Loading

0 comments on commit f927b25

Please sign in to comment.