use of com.adobe.target.delivery.v1.model.MboxRequest in project target-java-sdk by adobe.
the class OnDeviceDecisioningEvaluator method allMboxNames.
private List<String> allMboxNames(TargetDeliveryRequest request, OnDeviceDecisioningRuleSet ruleSet) {
if (request == null || ruleSet == null) {
return Collections.emptyList();
}
List<String> mboxNames = new ArrayList<>();
String globalMbox = ruleSet.getGlobalMbox();
PrefetchRequest prefetch = request.getDeliveryRequest().getPrefetch();
if (prefetch != null) {
if (prefetch.getPageLoad() != null) {
mboxNames.add(globalMbox);
}
mboxNames.addAll(prefetch.getMboxes().stream().map(MboxRequest::getName).collect(Collectors.toList()));
}
ExecuteRequest execute = request.getDeliveryRequest().getExecute();
if (execute != null) {
if (execute.getPageLoad() != null) {
mboxNames.add(globalMbox);
}
mboxNames.addAll(execute.getMboxes().stream().map(MboxRequest::getName).collect(Collectors.toList()));
}
return mboxNames;
}
use of com.adobe.target.delivery.v1.model.MboxRequest 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.delivery.v1.model.MboxRequest in project target-java-sdk by adobe.
the class OnDeviceDecisioningEvaluatorTest method testUnknownMbox.
@Test
public void testUnknownMbox() throws JsonProcessingException, NoSuchFieldException {
OnDeviceDecisioningRuleSet ruleSet = new OnDeviceDecisioningRuleSet();
List<String> mboxes = new ArrayList<>();
mboxes.add("test");
FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("localMboxes"), mboxes);
FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("remoteMboxes"), new ArrayList<>());
String serializedRuleSet = objectMapper.writeValueAsString(ruleSet);
RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoader(serializedRuleSet);
evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
TargetDeliveryRequest request = TargetDeliveryRequest.builder().execute(new ExecuteRequest().addMboxesItem(new MboxRequest().name("test")).addMboxesItem(new MboxRequest().name("test2"))).build();
OnDeviceDecisioningEvaluation evaluation = evaluator.evaluateLocalExecution(request);
assertFalse(evaluation.isAllLocal());
List<String> remoteMboxes = new ArrayList<>();
remoteMboxes.add("test2");
assertEquals(remoteMboxes, evaluation.getRemoteMBoxes());
assertNull(evaluation.getRemoteViews());
}
use of com.adobe.target.delivery.v1.model.MboxRequest in project target-java-sdk by adobe.
the class TelemetryServiceTest method testTelemetryForHybrid.
/**
* This test is executed on-device for this Hybrid request.
*
* @throws NoSuchFieldException
* @throws IOException
*/
@Test
void testTelemetryForHybrid() throws NoSuchFieldException, IOException {
setup(true, DecisioningMethod.HYBRID, "testTelemetryForHybrid");
fileRuleLoader("DECISIONING_PAYLOAD_ALL_MATCHES.json", localService);
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(new Context().channel(ChannelType.WEB)).execute(new ExecuteRequest().addMboxesItem(new MboxRequest().index(0).name("allmatches"))).decisioningMethod(DecisioningMethod.HYBRID).build();
targetJavaClient.getOffers(targetDeliveryRequest);
verify(telemetryServiceSpy, times(2)).getTelemetry();
verify(telemetryServiceSpy, times(1)).addTelemetry(any(TargetDeliveryRequest.class), any(TimingTool.class), any(TargetDeliveryResponse.class));
verify(telemetryServiceSpy, times(2)).addTelemetry(any(TargetDeliveryRequest.class), any(TimingTool.class), any(TargetDeliveryResponse.class), any(Double.class), any(Long.class));
}
use of com.adobe.target.delivery.v1.model.MboxRequest in project target-java-sdk by adobe.
the class TelemetryServiceTest method testTelemetrySentOnPrefetch.
/**
* Check telemetryEntry in prefetch call
*
* @throws NoSuchFieldException
* @throws IOException
*/
@Test
void testTelemetrySentOnPrefetch() throws NoSuchFieldException, IOException {
setup(true, DecisioningMethod.ON_DEVICE, "testTelemetrySentOnPrefetch");
long timestamp = System.currentTimeMillis();
TargetService targetServiceMock = mock(TargetService.class, RETURNS_DEFAULTS);
NotificationService notificationService = new NotificationService(targetServiceMock, clientConfig, clusterLocator);
FieldSetter.setField(localService, localService.getClass().getDeclaredField("notificationService"), notificationService);
fileRuleLoader("DECISIONING_PAYLOAD_ALL_MATCHES.json", localService);
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(new Context().channel(ChannelType.WEB)).execute(new ExecuteRequest().addMboxesItem(new MboxRequest().index(0).name("allmatches"))).prefetch(new PrefetchRequest().addMboxesItem(new MboxRequest().index(0).name("TEST_PREFETCH"))).decisioningMethod(DecisioningMethod.ON_DEVICE).build();
targetJavaClient.getOffers(targetDeliveryRequest);
Telemetry telemetry = telemetryServiceSpy.getTelemetry();
assertNotNull(telemetry);
TelemetryEntry telemetryEntry = telemetry.getEntries().get(1);
assertTrue(telemetryEntry.getTimestamp() > timestamp);
assertTrue(telemetryEntry.getExecution() > 0);
assertTrue(telemetryEntry.getRequestId().length() > 0);
assertEquals(telemetryEntry.getFeatures().getDecisioningMethod(), "on-device");
}
Aggregations