Search in sources :

Example 1 with MboxRequest

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;
}
Also used : PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) MboxRequest(com.adobe.target.delivery.v1.model.MboxRequest) ArrayList(java.util.ArrayList)

Example 2 with MboxRequest

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;
}
Also used : PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) MboxRequest(com.adobe.target.delivery.v1.model.MboxRequest) HashSet(java.util.HashSet)

Example 3 with MboxRequest

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());
}
Also used : ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) MboxRequest(com.adobe.target.delivery.v1.model.MboxRequest) ArrayList(java.util.ArrayList) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet) OnDeviceDecisioningEvaluation(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation) Test(org.junit.jupiter.api.Test)

Example 4 with MboxRequest

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));
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) TargetTestDeliveryRequestUtils.getContext(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext) TargetTestDeliveryRequestUtils.getMboxExecuteRequest(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) MboxRequest(com.adobe.target.delivery.v1.model.MboxRequest) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Test(org.junit.jupiter.api.Test)

Example 5 with MboxRequest

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");
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) TargetTestDeliveryRequestUtils.getContext(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext) PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) TargetTestDeliveryRequestUtils.getMboxExecuteRequest(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) MboxRequest(com.adobe.target.delivery.v1.model.MboxRequest) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) TelemetryEntry(com.adobe.target.delivery.v1.model.TelemetryEntry) Telemetry(com.adobe.target.delivery.v1.model.Telemetry) Test(org.junit.jupiter.api.Test)

Aggregations

MboxRequest (com.adobe.target.delivery.v1.model.MboxRequest)11 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)10 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)10 Test (org.junit.jupiter.api.Test)9 Context (com.adobe.target.delivery.v1.model.Context)6 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)6 TargetTestDeliveryRequestUtils.getContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext)6 TargetTestDeliveryRequestUtils.getMboxExecuteRequest (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest)5 ArrayList (java.util.ArrayList)4 Telemetry (com.adobe.target.delivery.v1.model.Telemetry)3 OnDeviceDecisioningEvaluation (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation)3 OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)3 TelemetryEntry (com.adobe.target.delivery.v1.model.TelemetryEntry)2 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)2 TimingTool (com.adobe.target.edge.client.utils.TimingTool)2 DeliveryRequest (com.adobe.target.delivery.v1.model.DeliveryRequest)1 Notification (com.adobe.target.delivery.v1.model.Notification)1 HashSet (java.util.HashSet)1