use of com.adobe.target.delivery.v1.model.RequestDetails in project target-java-sdk by adobe.
the class GeoParamsCollator method collateParams.
public Map<String, Object> collateParams(TargetDeliveryRequest deliveryRequest, RequestDetails requestDetails) {
Map<String, Object> params = new HashMap<>();
Context context = deliveryRequest.getDeliveryRequest().getContext();
if (context == null || context.getGeo() == null) {
params.putAll(DEFAULT_GEO_PARAMS);
return params;
}
Geo geo = context.getGeo();
params.put(GEO_LATITUDE, geo.getLatitude());
params.put(GEO_LONGITUDE, geo.getLongitude());
params.put(GEO_CITY, StringUtils.isEmpty(geo.getCity()) ? "" : geo.getCity().toUpperCase().replace(" ", ""));
params.put(GEO_REGION, StringUtils.isEmpty(geo.getStateCode()) ? "" : geo.getStateCode().toUpperCase());
params.put(GEO_COUNTRY, StringUtils.isEmpty(geo.getCountryCode()) ? "" : geo.getCountryCode().toUpperCase());
return params;
}
use of com.adobe.target.delivery.v1.model.RequestDetails 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.RequestDetails 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.RequestDetails in project target-java-sdk by adobe.
the class CustomParamsCollatorTest method testCollator.
@Test
public void testCollator() {
VisitorProvider.init("testOrgId");
Map<String, String> params = new HashMap<String, String>() {
{
put("foo", "bar");
put("BAZ", "BUZ");
}
};
RequestDetails pageLoad = new RequestDetails().parameters(params);
TargetDeliveryRequest request = TargetDeliveryRequest.builder().execute(new ExecuteRequest().pageLoad(pageLoad)).build();
CustomParamsCollator collator = new CustomParamsCollator();
Map<String, Object> result = collator.collateParams(request, pageLoad);
assertEquals("bar", result.get("foo"));
assertEquals("bar", result.get("foo" + CustomParamsCollator.LOWER_CASE_POSTFIX));
assertEquals("BUZ", result.get("BAZ"));
assertEquals("buz", result.get("BAZ" + CustomParamsCollator.LOWER_CASE_POSTFIX));
}
use of com.adobe.target.delivery.v1.model.RequestDetails in project target-java-sdk by adobe.
the class GeoParamsCollatorTest method testCollator.
@Test
public void testCollator() {
VisitorProvider.init("testOrgId");
RequestDetails pageLoad = new RequestDetails();
Geo geo = new Geo();
geo.setCity("san francisco");
geo.setStateCode("ca");
geo.setCountryCode("us");
geo.setLatitude(37.74f);
geo.setLongitude(-122.24f);
TargetDeliveryRequest request = TargetDeliveryRequest.builder().execute(new ExecuteRequest().pageLoad(pageLoad)).context(new Context().geo(geo)).build();
GeoParamsCollator collator = new GeoParamsCollator();
Map<String, Object> result = collator.collateParams(request, pageLoad);
assertEquals("SANFRANCISCO", result.get(GeoParamsCollator.GEO_CITY));
assertEquals("CA", result.get(GeoParamsCollator.GEO_REGION));
assertEquals("US", result.get(GeoParamsCollator.GEO_COUNTRY));
assertEquals(37.74f, (Float) result.get(GeoParamsCollator.GEO_LATITUDE), 0.01);
assertEquals(-122.24f, (Float) result.get(GeoParamsCollator.GEO_LONGITUDE), 0.01);
}
Aggregations