use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.
the class DefaultTargetClient method addMBoxesToRequest.
private static TargetDeliveryRequest addMBoxesToRequest(TargetDeliveryRequest targetRequest, String... mboxes) {
if (targetRequest == null || targetRequest.getDeliveryRequest() == null) {
targetRequest = TargetDeliveryRequest.builder().decisioningMethod(DecisioningMethod.HYBRID).build();
}
int idx = 0;
Set<String> existingMBoxNames = new HashSet<>();
DeliveryRequest deliveryRequest = targetRequest.getDeliveryRequest();
PrefetchRequest prefetchRequest = deliveryRequest.getPrefetch();
if (prefetchRequest != null && prefetchRequest.getMboxes() != null) {
for (MboxRequest mb : prefetchRequest.getMboxes()) {
existingMBoxNames.add(mb.getName());
}
}
ExecuteRequest executeRequest = deliveryRequest.getExecute();
if (executeRequest != null) {
List<MboxRequest> executeMboxes = executeRequest.getMboxes();
if (executeMboxes != null) {
for (MboxRequest mb : executeMboxes) {
if (mb.getIndex() >= idx) {
idx = mb.getIndex() + 1;
}
existingMBoxNames.add(mb.getName());
}
}
}
for (String mbox : mboxes) {
if (!existingMBoxNames.contains(mbox)) {
if (executeRequest == null) {
executeRequest = new ExecuteRequest();
targetRequest.getDeliveryRequest().setExecute(executeRequest);
}
executeRequest.addMboxesItem(new MboxRequest().index(idx++).name(mbox));
}
}
return targetRequest;
}
use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.
the class TargetDeliveryRequestLocalMboxTest method testTargetDeliveryAttributesLocalOnlyPartial.
@Test
@SuppressWarnings("unchecked")
void testTargetDeliveryAttributesLocalOnlyPartial() throws IOException, NoSuchFieldException {
fileRuleLoader("DECISIONING_PAYLOAD_RECOMMENDATIONS.json", localService);
TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916874", DecisioningMethod.ON_DEVICE, "daterange-mbox");
targetDeliveryRequest.getDeliveryRequest().getPrefetch().addMboxesItem(new MboxRequest().index(2).name("recommendations"));
TargetDeliveryResponse response = targetJavaClient.getOffers(targetDeliveryRequest);
assertNotNull(response);
assertEquals(206, response.getStatus());
verify(defaultTargetHttpClient, never()).execute(any(Map.class), any(String.class), eq(targetDeliveryRequest), any(Class.class));
verify(defaultTargetHttpClient, atMostOnce()).execute(any(Map.class), any(String.class), any(TargetDeliveryRequest.class), any(Class.class));
}
use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.
the class TargetDeliveryRequestLocalMboxTest method testTargetDeliveryLocalRequestTimeRange.
@Test
void testTargetDeliveryLocalRequestTimeRange() throws IOException, NoSuchFieldException {
fileRuleLoader("DECISIONING_PAYLOAD_TIMEFRAME.json", localService);
TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916873", DecisioningMethod.HYBRID, "daterange-mbox");
ParamsCollator specificTimeCollator = TargetTestDeliveryRequestUtils.getSpecificTimeCollator(1582830000000L);
FieldSetter.setField(localService, localService.getClass().getDeclaredField("timeParamsCollator"), specificTimeCollator);
TargetDeliveryResponse targetDeliveryResponse = targetJavaClient.getOffers(targetDeliveryRequest);
List<Option> prefetchOptions = extractOptions(targetDeliveryRequest, targetDeliveryResponse, "daterange-mbox");
verifyHTMLContent(prefetchOptions, "<strong>date range 1 (feb 27-29)</strong>", "wQY/V1IOYec8T4fAT5ww7unJlneZxJu5VqGhXCosHhWCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==");
}
use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.
the class TargetDeliveryRequestLocalMboxTest method testTargetDeliveryLocalRequestAllMatchesNotOverriden.
@Test
@SuppressWarnings("unchecked")
void testTargetDeliveryLocalRequestAllMatchesNotOverriden() throws IOException, NoSuchFieldException {
fileRuleLoader("DECISIONING_PAYLOAD_ALL_MATCHES.json", localService);
TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916874", DecisioningMethod.ON_DEVICE, "allmatches");
PrefetchRequest prefetchRequest = targetDeliveryRequest.getDeliveryRequest().getPrefetch();
MboxRequest mboxRequest = prefetchRequest.getMboxes().get(0);
mboxRequest.setParameters(new HashMap<String, String>() {
{
put("foo", "bar");
}
});
TargetDeliveryResponse targetDeliveryResponse = targetJavaClient.getOffers(targetDeliveryRequest);
List<Option> prefetchOptions = extractOptions(targetDeliveryRequest, targetDeliveryResponse, "allmatches");
assertEquals(1, prefetchOptions.size());
Option option1 = prefetchOptions.get(0);
assertEquals(OptionType.JSON, option1.getType());
Map<String, Object> preContent1 = (Map<String, Object>) option1.getContent();
assertEquals(2, preContent1.get("allmatches"));
assertEquals("b", preContent1.get("allmatches2_exp"));
assertEquals("aNT5qgpj/qd5U7cLpV7p05NWHtnQtQrJfmRrQugEa2qCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==", option1.getEventToken());
}
use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.
the class TargetDeliveryRequestLocalMboxTest method extractOptions.
@SuppressWarnings("unchecked")
private List<Option> extractOptions(TargetDeliveryRequest targetDeliveryRequest, TargetDeliveryResponse targetDeliveryResponse, String prefetchMbox) {
DeliveryResponse response = targetDeliveryResponse.getResponse();
assertNotNull(response);
PrefetchResponse preResponse = response.getPrefetch();
assertNotNull(preResponse);
List<PrefetchMboxResponse> preMboxes = preResponse.getMboxes();
assertNotNull(preMboxes);
List<Option> prefetchOptions = null;
if (prefetchMbox != null) {
assertEquals(1, preMboxes.size());
PrefetchMboxResponse preMboxResponse = preMboxes.get(0);
assertEquals(prefetchMbox, preMboxResponse.getName());
assertEquals(1, preMboxResponse.getIndex());
prefetchOptions = preMboxResponse.getOptions();
} else {
assertEquals(0, preMboxes.size());
}
ExecuteResponse execResponse = response.getExecute();
assertNotNull(execResponse);
List<MboxResponse> mboxes = execResponse.getMboxes();
assertNotNull(mboxes);
verify(defaultTargetHttpClient, never()).execute(any(Map.class), any(String.class), eq(targetDeliveryRequest), any(Class.class));
verify(defaultTargetHttpClient, atMostOnce()).execute(any(Map.class), any(String.class), any(TargetDeliveryRequest.class), any(Class.class));
return prefetchOptions;
}
Aggregations