Search in sources :

Example 11 with DeliveryRequest

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

the class TelemetryService method addTelemetry.

public void addTelemetry(TargetDeliveryRequest deliveryRequest, TimingTool timer, TargetDeliveryResponse targetDeliveryResponse, double parsingTime, long responseSize) {
    TelemetryEntry telemetryEntry = createTelemetryEntry(deliveryRequest, targetDeliveryResponse, timer.timeEnd(TIMING_EXECUTE_REQUEST));
    if (telemetryEntry == null) {
        return;
    }
    telemetryEntry.setParsing(parsingTime);
    TelemetryRequest telemetryRequest = new TelemetryRequest();
    telemetryRequest.setResponseSize(responseSize);
    telemetryEntry.setRequest(telemetryRequest);
    storedTelemetries.add(telemetryEntry);
}
Also used : TelemetryRequest(com.adobe.target.delivery.v1.model.TelemetryRequest) TelemetryEntry(com.adobe.target.delivery.v1.model.TelemetryEntry)

Example 12 with DeliveryRequest

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

the class DefaultTargetClient method updatePropertyToken.

private void updatePropertyToken(TargetDeliveryRequest targetRequest) {
    if (StringUtils.isEmpty(this.defaultPropertyToken)) {
        return;
    }
    DeliveryRequest deliveryRequest = targetRequest.getDeliveryRequest();
    Property property = deliveryRequest.getProperty();
    if (property != null && property.getToken() != null) {
        return;
    }
    if (property == null) {
        property = new Property();
        deliveryRequest.setProperty(property);
    }
    property.setToken(this.defaultPropertyToken);
}
Also used : TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) Property(com.adobe.target.delivery.v1.model.Property)

Example 13 with DeliveryRequest

use of com.adobe.target.delivery.v1.model.DeliveryRequest 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 14 with DeliveryRequest

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

the class DefaultTargetHttpClientTest method testExecuteAsync.

@Test
void testExecuteAsync() throws NoSuchFieldException {
    ClientConfig clientConfig = ClientConfig.builder().organizationId(TEST_ORG_ID).telemetryEnabled(false).build();
    DefaultTargetHttpClient defaultTargetHttpClient = new DefaultTargetHttpClient(clientConfig);
    UnirestInstance unirestInstance = Mockito.mock(UnirestInstance.class, Mockito.RETURNS_DEEP_STUBS);
    FieldSetter.setField(defaultTargetHttpClient, defaultTargetHttpClient.getClass().getDeclaredField("unirestInstance"), unirestInstance);
    Map<String, Object> queryParams = new HashMap<>();
    String url = "/testUrl";
    DeliveryRequest deliveryRequest = new DeliveryRequest();
    when(unirestInstance.post(eq(url)).queryString(eq(queryParams)).body(eq(deliveryRequest)).asObjectAsync(ArgumentMatchers.<Function<RawResponse, Object>>any()).thenApply(ArgumentMatchers.<Function<HttpResponse<Object>, CompletableFuture<ResponseWrapper<Object>>>>any())).thenAnswer(invocation -> {
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        Function<HttpResponse, Object> function = (Function<HttpResponse, Object>) invocation.getArguments()[0];
        function.apply(httpResponse);
        return null;
    });
    CompletableFuture<ResponseWrapper<MockRawResponse>> completableFuture = defaultTargetHttpClient.executeAsync(queryParams, url, deliveryRequest, MockRawResponse.class);
    assertNotNull(completableFuture);
}
Also used : DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) HashMap(java.util.HashMap) HttpResponse(kong.unirest.HttpResponse) Function(java.util.function.Function) UnirestInstance(kong.unirest.UnirestInstance) CompletableFuture(java.util.concurrent.CompletableFuture) ClientConfig(com.adobe.target.edge.client.ClientConfig) Test(org.junit.jupiter.api.Test)

Example 15 with DeliveryRequest

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

the class TelemetryServiceTest method testTelemetryForServerSide.

/**
 * Test case to call get offers for server side, in first request we capture the telemetry & in
 * next call we send it with any getOffers() call or sendNotifications() call
 *
 * @throws NoSuchFieldException
 */
@Test
void testTelemetryForServerSide() throws NoSuchFieldException {
    setup(true, DecisioningMethod.SERVER_SIDE, "testTelemetryForServerSide");
    Context context = getContext();
    PrefetchRequest prefetchRequest = getPrefetchViewsRequest();
    ExecuteRequest executeRequest = getMboxExecuteRequest();
    String nonDefaultToken = "non-default-token";
    TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).prefetch(prefetchRequest).execute(executeRequest).property(new Property().token(nonDefaultToken)).decisioningMethod(DecisioningMethod.SERVER_SIDE).build();
    TargetDeliveryResponse targetDeliveryResponse1 = targetJavaClient.getOffers(targetDeliveryRequest);
    assertNull(targetDeliveryResponse1.getRequest().getTelemetry());
    // In next call we see telemetry data added to the deliveryRequest
    TargetDeliveryResponse targetDeliveryResponse2 = targetJavaClient.getOffers(targetDeliveryRequest);
    verify(telemetryServiceSpy, atLeast(2)).getTelemetry();
    verify(telemetryServiceSpy, times(2)).addTelemetry(any(TargetDeliveryRequest.class), any(TimingTool.class), any(TargetDeliveryResponse.class), any(Double.class), any(Long.class));
    assertEquals(1, telemetryServiceSpy.getTelemetry().getEntries().size());
    assertNotNull(targetDeliveryResponse2);
    assertNotNull(targetDeliveryResponse2.getRequest());
    assertNotNull(targetDeliveryResponse2.getRequest().getTelemetry());
    assertEquals(1, targetDeliveryResponse2.getRequest().getTelemetry().getEntries().size());
}
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) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Property(com.adobe.target.delivery.v1.model.Property) Test(org.junit.jupiter.api.Test)

Aggregations

DeliveryRequest (com.adobe.target.delivery.v1.model.DeliveryRequest)9 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)8 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)8 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)6 TimingTool (com.adobe.target.edge.client.utils.TimingTool)6 Test (org.junit.jupiter.api.Test)5 Context (com.adobe.target.delivery.v1.model.Context)4 Telemetry (com.adobe.target.delivery.v1.model.Telemetry)4 HashMap (java.util.HashMap)4 ResponseStatus (com.adobe.target.edge.client.http.ResponseStatus)3 ResponseWrapper (com.adobe.target.edge.client.http.ResponseWrapper)3 Map (java.util.Map)3 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)2 Geo (com.adobe.target.delivery.v1.model.Geo)2 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)2 Property (com.adobe.target.delivery.v1.model.Property)2 RequestDetails (com.adobe.target.delivery.v1.model.RequestDetails)2 TelemetryEntry (com.adobe.target.delivery.v1.model.TelemetryEntry)2 ClientConfig (com.adobe.target.edge.client.ClientConfig)2 TargetTestDeliveryRequestUtils.getTestDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse)2