Search in sources :

Example 1 with VisitorId

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

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

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

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

the class OnDeviceDecisioningService method getOrCreateVisitorId.

private String getOrCreateVisitorId(TargetDeliveryRequest deliveryRequest, TargetDeliveryResponse targetResponse) {
    String vid = null;
    VisitorId visitorId = deliveryRequest.getDeliveryRequest().getId();
    if (visitorId != null) {
        vid = StringUtils.firstNonBlank(visitorId.getMarketingCloudVisitorId(), removeLocationHint(visitorId.getTntId()), visitorId.getThirdPartyId());
    }
    // set our own tntId there in an earlier call
    if (vid == null && targetResponse.getResponse().getId() != null) {
        vid = removeLocationHint(targetResponse.getResponse().getId().getTntId());
    }
    if (vid != null) {
        return vid;
    }
    // If vid still null, create new tntId and use that and set it in the response
    String newTntId = generateTntId();
    if (visitorId == null) {
        visitorId = new VisitorId().tntId(newTntId);
    } else {
        visitorId.setTntId(newTntId);
    }
    targetResponse.getResponse().setId(visitorId);
    return removeLocationHint(newTntId);
}
Also used : VisitorId(com.adobe.target.delivery.v1.model.VisitorId)

Example 5 with VisitorId

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

the class TargetDeliveryRequestBuilder method createVisitorId.

private void createVisitorId() {
    if (request.getId() != null) {
        return;
    }
    if (isEmpty(tntId) && isEmpty(marketingCloudVisitorId) && isEmpty(thirdPartyId)) {
        return;
    }
    VisitorId visitorId = new VisitorId().tntId(tntId).marketingCloudVisitorId(marketingCloudVisitorId).thirdPartyId(thirdPartyId).customerIds(targetCustomerIds);
    request.id(visitorId);
}
Also used : VisitorId(com.adobe.target.delivery.v1.model.VisitorId)

Aggregations

VisitorId (com.adobe.target.delivery.v1.model.VisitorId)3 Notification (com.adobe.target.delivery.v1.model.Notification)2 RequestDetails (com.adobe.target.delivery.v1.model.RequestDetails)2 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)2 Context (com.adobe.target.delivery.v1.model.Context)1 DeliveryRequest (com.adobe.target.delivery.v1.model.DeliveryRequest)1 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)1 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)1 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)1 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)1 OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)1 TargetTestDeliveryRequestUtils.getLocalContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getLocalContext)1 TimingTool (com.adobe.target.edge.client.utils.TimingTool)1