Search in sources :

Example 1 with Notification

use of com.adobe.target.delivery.v1.model.Notification in project target-java-sdk by adobe.

the class OnDeviceDecisioningService method handleDetails.

private void handleDetails(List<RequestDetails> detailsList, Map<String, Object> requestContext, TargetDeliveryRequest deliveryRequest, String visitorId, Set<String> responseTokens, TraceHandler traceHandler, OnDeviceDecisioningRuleSet ruleSet, PrefetchResponse prefetchResponse, ExecuteResponse executeResponse, List<Notification> notifications) {
    for (RequestDetails details : detailsList) {
        Map<String, Object> detailsContext = new HashMap<>(requestContext);
        collateParams(detailsContext, DETAILS_PARAMS_COLLATORS, deliveryRequest, details);
        this.decisionHandler.executeDetails(deliveryRequest, this.onDeviceAllMatchingRulesMboxes, detailsContext, visitorId, responseTokens, traceHandler, ruleSet, details, prefetchResponse, executeResponse, notifications);
    }
}
Also used : RequestDetails(com.adobe.target.delivery.v1.model.RequestDetails)

Example 2 with Notification

use of com.adobe.target.delivery.v1.model.Notification in project target-java-sdk by adobe.

the class OnDeviceDecisioningService method executeRequest.

public TargetDeliveryResponse executeRequest(TargetDeliveryRequest deliveryRequest) {
    TimingTool timer = new TimingTool();
    timer.timeStart(TIMING_EXECUTE_REQUEST);
    DeliveryRequest delivRequest = deliveryRequest.getDeliveryRequest();
    String requestId = delivRequest.getRequestId();
    if (requestId == null) {
        requestId = UUID.randomUUID().toString();
    }
    OnDeviceDecisioningRuleSet ruleSet = this.ruleLoader.getLatestRules();
    if (ruleSet == null) {
        DeliveryResponse deliveryResponse = new DeliveryResponse().client(clientConfig.getClient()).requestId(requestId).id(delivRequest.getId()).status(HttpStatus.SC_SERVICE_UNAVAILABLE);
        return new TargetDeliveryResponse(deliveryRequest, deliveryResponse, HttpStatus.SC_SERVICE_UNAVAILABLE, "Local-decisioning rules not available");
    }
    Map<String, Object> requestContext = new HashMap<>(timeParamsCollator.collateParams(deliveryRequest, null));
    geoLookupIfNeeded(deliveryRequest, ruleSet.isGeoTargetingEnabled());
    collateParams(requestContext, REQUEST_PARAMS_COLLATORS, deliveryRequest, null);
    TraceHandler traceHandler = null;
    if (delivRequest.getTrace() != null) {
        traceHandler = new TraceHandler(this.clientConfig, this.ruleLoader, this.mapper, ruleSet, deliveryRequest);
    }
    Set<String> responseTokens = new HashSet<>(ruleSet.getResponseTokens());
    TargetDeliveryResponse targetResponse = buildDeliveryResponse(deliveryRequest, requestId);
    String visitorId = getOrCreateVisitorId(deliveryRequest, targetResponse);
    List<RequestDetails> prefetchRequests = detailsFromPrefetch(delivRequest);
    handleDetails(prefetchRequests, requestContext, deliveryRequest, visitorId, responseTokens, traceHandler, ruleSet, targetResponse.getResponse().getPrefetch(), null, null);
    List<RequestDetails> executeRequests = detailsFromExecute(delivRequest);
    List<Notification> notifications = new ArrayList<>();
    handleDetails(executeRequests, requestContext, deliveryRequest, visitorId, responseTokens, traceHandler, ruleSet, null, targetResponse.getResponse().getExecute(), notifications);
    telemetryService.addTelemetry(deliveryRequest, timer, targetResponse);
    notificationService.buildNotifications(deliveryRequest, targetResponse, notifications);
    if (this.clientConfig.isLogRequests()) {
        logger.debug(targetResponse.toString());
    }
    return targetResponse;
}
Also used : TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) DeliveryResponse(com.adobe.target.delivery.v1.model.DeliveryResponse) RequestDetails(com.adobe.target.delivery.v1.model.RequestDetails) Notification(com.adobe.target.delivery.v1.model.Notification) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse)

Example 3 with Notification

use of com.adobe.target.delivery.v1.model.Notification in project target-java-sdk by adobe.

the class DefaultTargetServiceTest method getDeliveryRequest.

private TargetDeliveryRequest getDeliveryRequest() {
    Context context = getLocalContext();
    PrefetchRequest prefetchRequest = getMboxPrefetchLocalRequest("testoffer");
    ExecuteRequest executeRequest = getMboxExecuteLocalRequest("testoffer2");
    VisitorId visitorId = new VisitorId().tntId("38734fba-262c-4722-b4a3-ac0a93916873");
    Notification notification = new Notification();
    notification.setId(UUID.randomUUID().toString());
    notification.setImpressionId(UUID.randomUUID().toString());
    notification.setType(MetricType.DISPLAY);
    notification.setTimestamp(System.currentTimeMillis());
    notification.setTokens(Collections.singletonList("IbG2Jz2xmHaqX7Ml/YRxRGqipfsIHvVzTQxHolz2IpSCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q=="));
    TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).prefetch(prefetchRequest).execute(executeRequest).id(visitorId).notifications(Collections.singletonList(notification)).build();
    return targetDeliveryRequest;
}
Also used : TargetTestDeliveryRequestUtils.getLocalContext(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getLocalContext) Context(com.adobe.target.delivery.v1.model.Context) PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) VisitorId(com.adobe.target.delivery.v1.model.VisitorId) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Notification(com.adobe.target.delivery.v1.model.Notification)

Example 4 with Notification

use of com.adobe.target.delivery.v1.model.Notification in project target-java-sdk by adobe.

the class TelemetryServiceTest method testTelemetryForServerSideSendNotificationNullResponse.

/**
 * Test case for calling sendNotifications() and getting an http timeout. In this case Delivery
 * API will return a null response body, and the SDK will throw a RuntimeException, and not
 * collect telemetry.
 *
 * @throws NoSuchFieldException
 */
@Test
void testTelemetryForServerSideSendNotificationNullResponse() throws NoSuchFieldException {
    setup(true, DecisioningMethod.SERVER_SIDE, "testTelemetryForServerSideSendNotificationNullResponse");
    Mockito.lenient().doReturn(getNoContentDeliveryResponse()).when(defaultTargetHttpClient).execute(any(Map.class), any(String.class), any(DeliveryRequest.class), any(Class.class));
    Context context = getContext();
    List<Notification> notifications = new ArrayList<>();
    Notification notification = new Notification().id("12345").impressionId("12345").mbox(new NotificationMbox().name("test-mbox").state("11111")).type(MetricType.DISPLAY).timestamp(System.currentTimeMillis());
    notifications.add(notification);
    TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).notifications(notifications).build();
    assertThrows(RuntimeException.class, () -> targetJavaClient.sendNotifications(targetDeliveryRequest));
    verify(telemetryServiceSpy, never()).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) TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) NotificationMbox(com.adobe.target.delivery.v1.model.NotificationMbox) ArrayList(java.util.ArrayList) Notification(com.adobe.target.delivery.v1.model.Notification) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 5 with Notification

use of com.adobe.target.delivery.v1.model.Notification in project target-java-sdk by adobe.

the class TelemetryServiceTest method testTelemetryNotSentExecute.

/**
 * When telemetryEnabled flag is set to false verify we don't store telemetry data
 *
 * @throws NoSuchFieldException
 * @throws IOException
 */
@Test
void testTelemetryNotSentExecute() throws NoSuchFieldException, IOException {
    setup(false, DecisioningMethod.ON_DEVICE, "testTelemetryNotSentExecute");
    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);
    ArgumentCaptor<TargetDeliveryRequest> captor = ArgumentCaptor.forClass(TargetDeliveryRequest.class);
    verify(targetServiceMock, timeout(1000)).executeNotificationAsync(captor.capture());
    Telemetry telemetry = captor.getValue().getDeliveryRequest().getTelemetry();
    List<Notification> notifications = captor.getValue().getDeliveryRequest().getNotifications();
    assertNull(telemetry);
    assertEquals(notifications.size(), 1);
}
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) Telemetry(com.adobe.target.delivery.v1.model.Telemetry) Notification(com.adobe.target.delivery.v1.model.Notification) Test(org.junit.jupiter.api.Test)

Aggregations

TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)5 Notification (com.adobe.target.delivery.v1.model.Notification)4 Context (com.adobe.target.delivery.v1.model.Context)3 DeliveryRequest (com.adobe.target.delivery.v1.model.DeliveryRequest)3 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)2 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)2 RequestDetails (com.adobe.target.delivery.v1.model.RequestDetails)2 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)2 TargetTestDeliveryRequestUtils.getContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext)2 TimingTool (com.adobe.target.edge.client.utils.TimingTool)2 Test (org.junit.jupiter.api.Test)2 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)1 MboxRequest (com.adobe.target.delivery.v1.model.MboxRequest)1 NotificationMbox (com.adobe.target.delivery.v1.model.NotificationMbox)1 Telemetry (com.adobe.target.delivery.v1.model.Telemetry)1 VisitorId (com.adobe.target.delivery.v1.model.VisitorId)1 OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)1 TargetTestDeliveryRequestUtils.getLocalContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getLocalContext)1 TargetTestDeliveryRequestUtils.getMboxExecuteRequest (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest)1 ArrayList (java.util.ArrayList)1