Search in sources :

Example 6 with DeliveryRequest

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

the class DefaultTargetService method executeNotificationAsync.

@Override
public CompletableFuture<ResponseStatus> executeNotificationAsync(TargetDeliveryRequest deliveryRequest) {
    TimingTool timer = new TimingTool();
    timer.timeStart(TIMING_EXECUTE_REQUEST);
    NotificationService.setBeaconToFalse(deliveryRequest.getDeliveryRequest());
    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 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 7 with DeliveryRequest

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

the class OnDeviceDecisioningService method geoLookupIfNeeded.

private void geoLookupIfNeeded(TargetDeliveryRequest deliveryRequest, boolean doGeoLookup) {
    if (!doGeoLookup) {
        return;
    }
    Context context = deliveryRequest.getDeliveryRequest().getContext();
    if (context != null) {
        Geo geo = context.getGeo();
        if (geo != null) {
            if (StringUtils.isNotEmpty(geo.getIpAddress()) && StringUtils.isEmpty(geo.getCity()) && StringUtils.isEmpty(geo.getStateCode()) && StringUtils.isEmpty(geo.getCountryCode()) && geo.getLatitude() == null && geo.getLongitude() == null) {
                Geo resolvedGeo = this.geoClient.lookupGeo(geo.getIpAddress());
                deliveryRequest.getDeliveryRequest().getContext().setGeo(resolvedGeo);
            }
        }
    }
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) Geo(com.adobe.target.delivery.v1.model.Geo)

Example 8 with DeliveryRequest

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

the class OnDeviceDecisioningService method buildDeliveryResponse.

private TargetDeliveryResponse buildDeliveryResponse(TargetDeliveryRequest deliveryRequest, String requestId) {
    OnDeviceDecisioningEvaluation localEvaluation = evaluateLocalExecution(deliveryRequest);
    int status = localEvaluation.isAllLocal() ? HttpStatus.SC_OK : HttpStatus.SC_PARTIAL_CONTENT;
    DeliveryResponse deliveryResponse = new DeliveryResponse().client(clientConfig.getClient()).requestId(requestId).id(deliveryRequest.getDeliveryRequest().getId()).status(status);
    PrefetchResponse prefetchResponse = new PrefetchResponse();
    ExecuteResponse executeResponse = new ExecuteResponse();
    deliveryResponse.setPrefetch(prefetchResponse);
    deliveryResponse.setExecute(executeResponse);
    TargetDeliveryResponse targetResponse = new TargetDeliveryResponse(deliveryRequest, deliveryResponse, status, localEvaluation.isAllLocal() ? "Local-decisioning response" : localEvaluation.getReason());
    ResponseStatus responseStatus = targetResponse.getResponseStatus();
    responseStatus.setGlobalMbox(localEvaluation.getGlobalMbox());
    responseStatus.setRemoteMboxes(localEvaluation.getRemoteMBoxes());
    responseStatus.setRemoteViews(localEvaluation.getRemoteViews());
    return targetResponse;
}
Also used : TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) PrefetchResponse(com.adobe.target.delivery.v1.model.PrefetchResponse) ResponseStatus(com.adobe.target.edge.client.http.ResponseStatus) ExecuteResponse(com.adobe.target.delivery.v1.model.ExecuteResponse) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) DeliveryResponse(com.adobe.target.delivery.v1.model.DeliveryResponse) OnDeviceDecisioningEvaluation(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation)

Example 9 with DeliveryRequest

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

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

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