use of com.adobe.target.edge.client.model.TargetDeliveryRequest 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.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.
the class TargetDeliveryAttributesTest method testTargetDeliveryAttributesAllMatches.
@Test
@SuppressWarnings("unchecked")
void testTargetDeliveryAttributesAllMatches() throws IOException, NoSuchFieldException {
String mbox = "allmatches";
ArrayList<String> mboxes = new ArrayList<String>() {
{
add(mbox);
}
};
ClientConfig clientConfig = ClientConfig.builder().client("targettesting").organizationId(TEST_ORG_ID).onDeviceEnvironment("test").defaultDecisioningMethod(DecisioningMethod.ON_DEVICE).onDeviceAllMatchingRulesMboxes(mboxes).build();
TelemetryService telemetryService = new TelemetryService(clientConfig);
DefaultTargetService targetService = new DefaultTargetService(clientConfig, telemetryService);
localService = new OnDeviceDecisioningService(clientConfig, targetService, telemetryService);
fileRuleLoader("DECISIONING_PAYLOAD_ALL_MATCHES.json", localService);
FieldSetter.setField(targetJavaClient, targetJavaClient.getClass().getDeclaredField("localService"), localService);
FieldSetter.setField(targetService, targetService.getClass().getDeclaredField("targetHttpClient"), defaultTargetHttpClient);
FieldSetter.setField(targetJavaClient, targetJavaClient.getClass().getDeclaredField("targetService"), targetService);
Context context = getLocalContext();
PrefetchRequest prefetchRequest = getMboxPrefetchLocalRequest(mbox);
VisitorId visitorId = new VisitorId().tntId("38734fba-262c-4722-b4a3-ac0a93916873");
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).prefetch(prefetchRequest).id(visitorId).decisioningMethod(DecisioningMethod.ON_DEVICE).build();
Attributes attrs = targetJavaClient.getAttributes(targetDeliveryRequest, mbox);
assertNotNull(attrs);
assertNotNull(attrs.getResponse());
assertEquals(200, attrs.getResponse().getStatus());
verify(defaultTargetHttpClient, atMostOnce()).execute(any(Map.class), any(String.class), any(TargetDeliveryRequest.class), any(Class.class));
assertEquals(2, attrs.getInteger(mbox, "allmatches", 0));
assertEquals("a", attrs.getString(mbox, "allmatches1_exp"));
assertEquals("a", attrs.getString(mbox, "allmatches2_exp"));
}
use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.
the class TargetDeliveryAttributesTest method testTargetDeliveryAttributesPageload.
@Test
void testTargetDeliveryAttributesPageload() {
TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916874");
DeliveryRequest deliveryRequest = targetDeliveryRequest.getDeliveryRequest();
deliveryRequest.getPrefetch().setPageLoad(new RequestDetails());
deliveryRequest.getPrefetch().setMboxes(Collections.emptyList());
deliveryRequest.setExecute(null);
Attributes attrs = targetJavaClient.getAttributes(targetDeliveryRequest);
validateInitialResponse(targetDeliveryRequest, attrs);
assertTrue(attrs.getBoolean("target-global-mbox", "test", false));
assertEquals("a", attrs.getString("target-global-mbox", "experience"));
assertEquals(12.99, attrs.getDouble("target-global-mbox", "price", 0d), 0.0001);
assertEquals("a", attrs.toMboxMap("target-global-mbox").get("experience"));
assertEquals("a", attrs.toMap().get("target-global-mbox").get("experience"));
}
use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.
the class TargetDeliveryExceptionTest method testTargetDeliveryRequest.
@Test
void testTargetDeliveryRequest() {
Context context = getContext();
PrefetchRequest prefetchRequest = getPrefetchViewsRequest();
ExecuteRequest executeRequest = getMboxExecuteRequest();
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).prefetch(prefetchRequest).execute(executeRequest).build();
TargetRequestException exception = assertThrows(TargetRequestException.class, () -> {
TargetDeliveryResponse targetDeliveryResponse = targetJavaClient.getOffers(targetDeliveryRequest);
});
assertNotNull(exception);
assertNotNull(exception.getRequest());
assertNotNull(exception.getRequest().getSessionId());
}
use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.
the class DefaultTargetClient method updatePropertyToken.
private void updatePropertyToken(TargetDeliveryRequest targetRequest) {
if (StringUtils.isEmpty(this.defaultPropertyToken)) {
return;
}
DeliveryRequest deliveryRequest = targetRequest.getDeliveryRequest();
Property property = deliveryRequest.getProperty();
if (property != null && property.getToken() != null) {
return;
}
if (property == null) {
property = new Property();
deliveryRequest.setProperty(property);
}
property.setToken(this.defaultPropertyToken);
}
Aggregations