use of com.adobe.target.delivery.v1.model.Notification 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.Notification 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.Notification 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.Notification in project target-java-sdk by adobe.
the class TelemetryServiceTest method testTelemetryForServerSideSendNotificationNullResponse.
/**
* Test case for calling sendNotifications() and getting an http timeout. In this case Delivery
* API will return a null response body, and the SDK will throw a RuntimeException, and not
* collect telemetry.
*
* @throws NoSuchFieldException
*/
@Test
void testTelemetryForServerSideSendNotificationNullResponse() throws NoSuchFieldException {
setup(true, DecisioningMethod.SERVER_SIDE, "testTelemetryForServerSideSendNotificationNullResponse");
Mockito.lenient().doReturn(getNoContentDeliveryResponse()).when(defaultTargetHttpClient).execute(any(Map.class), any(String.class), any(DeliveryRequest.class), any(Class.class));
Context context = getContext();
List<Notification> notifications = new ArrayList<>();
Notification notification = new Notification().id("12345").impressionId("12345").mbox(new NotificationMbox().name("test-mbox").state("11111")).type(MetricType.DISPLAY).timestamp(System.currentTimeMillis());
notifications.add(notification);
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).notifications(notifications).build();
assertThrows(RuntimeException.class, () -> targetJavaClient.sendNotifications(targetDeliveryRequest));
verify(telemetryServiceSpy, never()).addTelemetry(any(TargetDeliveryRequest.class), any(TimingTool.class), any(TargetDeliveryResponse.class), any(Double.class), any(Long.class));
}
use of com.adobe.target.delivery.v1.model.Notification in project target-java-sdk by adobe.
the class TelemetryServiceTest method testTelemetryNotSentExecute.
/**
* When telemetryEnabled flag is set to false verify we don't store telemetry data
*
* @throws NoSuchFieldException
* @throws IOException
*/
@Test
void testTelemetryNotSentExecute() throws NoSuchFieldException, IOException {
setup(false, DecisioningMethod.ON_DEVICE, "testTelemetryNotSentExecute");
TargetService targetServiceMock = mock(TargetService.class, RETURNS_DEFAULTS);
NotificationService notificationService = new NotificationService(targetServiceMock, clientConfig, clusterLocator);
FieldSetter.setField(localService, localService.getClass().getDeclaredField("notificationService"), notificationService);
fileRuleLoader("DECISIONING_PAYLOAD_ALL_MATCHES.json", localService);
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(new Context().channel(ChannelType.WEB)).execute(new ExecuteRequest().addMboxesItem(new MboxRequest().index(0).name("allmatches"))).prefetch(new PrefetchRequest().addMboxesItem(new MboxRequest().index(0).name("TEST_PREFETCH"))).decisioningMethod(DecisioningMethod.ON_DEVICE).build();
targetJavaClient.getOffers(targetDeliveryRequest);
ArgumentCaptor<TargetDeliveryRequest> captor = ArgumentCaptor.forClass(TargetDeliveryRequest.class);
verify(targetServiceMock, timeout(1000)).executeNotificationAsync(captor.capture());
Telemetry telemetry = captor.getValue().getDeliveryRequest().getTelemetry();
List<Notification> notifications = captor.getValue().getDeliveryRequest().getNotifications();
assertNull(telemetry);
assertEquals(notifications.size(), 1);
}
Aggregations