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);
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations