Search in sources :

Example 1 with DeliveryRequest

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

the class GeoParamsCollator method collateParams.

public Map<String, Object> collateParams(TargetDeliveryRequest deliveryRequest, RequestDetails requestDetails) {
    Map<String, Object> params = new HashMap<>();
    Context context = deliveryRequest.getDeliveryRequest().getContext();
    if (context == null || context.getGeo() == null) {
        params.putAll(DEFAULT_GEO_PARAMS);
        return params;
    }
    Geo geo = context.getGeo();
    params.put(GEO_LATITUDE, geo.getLatitude());
    params.put(GEO_LONGITUDE, geo.getLongitude());
    params.put(GEO_CITY, StringUtils.isEmpty(geo.getCity()) ? "" : geo.getCity().toUpperCase().replace(" ", ""));
    params.put(GEO_REGION, StringUtils.isEmpty(geo.getStateCode()) ? "" : geo.getStateCode().toUpperCase());
    params.put(GEO_COUNTRY, StringUtils.isEmpty(geo.getCountryCode()) ? "" : geo.getCountryCode().toUpperCase());
    return params;
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) Geo(com.adobe.target.delivery.v1.model.Geo) HashMap(java.util.HashMap)

Example 2 with DeliveryRequest

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

the class UserParamsCollator method extractUserAgent.

private String extractUserAgent(TargetDeliveryRequest deliveryRequest) {
    Context context = deliveryRequest.getDeliveryRequest().getContext();
    if (context == null) {
        return null;
    }
    String userAgent = context.getUserAgent();
    if (StringUtils.isEmpty(userAgent)) {
        return null;
    }
    return userAgent;
}
Also used : Context(com.adobe.target.delivery.v1.model.Context)

Example 3 with DeliveryRequest

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

the class DefaultTargetService method executeNotification.

@Override
public ResponseStatus executeNotification(TargetDeliveryRequest deliveryRequest) {
    TimingTool timer = new TimingTool();
    timer.timeStart(TIMING_EXECUTE_REQUEST);
    NotificationService.setBeaconToFalse(deliveryRequest.getDeliveryRequest());
    TargetDeliveryResponse targetDeliveryResponse;
    Telemetry telemetry = telemetryService.getTelemetry();
    if (!telemetry.getEntries().isEmpty()) {
        deliveryRequest.getDeliveryRequest().setTelemetry(telemetry);
    }
    ResponseWrapper response = callDeliveryApi(deliveryRequest);
    targetDeliveryResponse = getTargetDeliveryResponse(deliveryRequest, response.getHttpResponse());
    telemetryService.addTelemetry(deliveryRequest, timer, targetDeliveryResponse, response.getParsingTime(), response.getResponseSize());
    return new ResponseStatus(response.getHttpResponse().getStatus(), response.getHttpResponse().getStatusText());
}
Also used : TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) ResponseStatus(com.adobe.target.edge.client.http.ResponseStatus) ResponseWrapper(com.adobe.target.edge.client.http.ResponseWrapper) Telemetry(com.adobe.target.delivery.v1.model.Telemetry)

Example 4 with DeliveryRequest

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

the class DefaultTargetService method executeRequestAsync.

@Override
public CompletableFuture<TargetDeliveryResponse> executeRequestAsync(TargetDeliveryRequest deliveryRequest) {
    TimingTool timer = new TimingTool();
    timer.timeStart(TIMING_EXECUTE_REQUEST);
    Telemetry telemetry = telemetryService.getTelemetry();
    if (!telemetry.getEntries().isEmpty()) {
        deliveryRequest.getDeliveryRequest().setTelemetry(telemetry);
    }
    CompletableFuture<ResponseWrapper<DeliveryResponse>> responseCompletableFuture = callDeliveryApiAsync(deliveryRequest);
    return responseCompletableFuture.thenApply(response -> {
        TargetDeliveryResponse targetDeliveryResponse = getTargetDeliveryResponse(deliveryRequest, response.getHttpResponse());
        telemetryService.addTelemetry(deliveryRequest, timer, targetDeliveryResponse, response.getParsingTime(), response.getResponseSize());
        return targetDeliveryResponse;
    });
}
Also used : TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) ResponseWrapper(com.adobe.target.edge.client.http.ResponseWrapper) Telemetry(com.adobe.target.delivery.v1.model.Telemetry)

Example 5 with DeliveryRequest

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

the class DefaultTargetService method getTargetDeliveryResponse.

private TargetDeliveryResponse getTargetDeliveryResponse(TargetDeliveryRequest deliveryRequest, HttpResponse<DeliveryResponse> response) {
    DeliveryResponse deliveryResponse = retrieveDeliveryResponse(response);
    updateStickyLocationHint(deliveryResponse);
    return new TargetDeliveryResponse(deliveryRequest, deliveryResponse, response.getStatus(), response.getStatusText());
}
Also used : TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) DeliveryResponse(com.adobe.target.delivery.v1.model.DeliveryResponse)

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