Search in sources :

Example 1 with RequestDetails

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;
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) Geo(com.adobe.target.delivery.v1.model.Geo) HashMap(java.util.HashMap)

Example 2 with RequestDetails

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);
    }
}
Also used : RequestDetails(com.adobe.target.delivery.v1.model.RequestDetails)

Example 3 with RequestDetails

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;
}
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 4 with RequestDetails

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));
}
Also used : ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) HashMap(java.util.HashMap) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) RequestDetails(com.adobe.target.delivery.v1.model.RequestDetails) Test(org.junit.jupiter.api.Test)

Example 5 with RequestDetails

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);
}
Also used : Geo(com.adobe.target.delivery.v1.model.Geo) Context(com.adobe.target.delivery.v1.model.Context) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) RequestDetails(com.adobe.target.delivery.v1.model.RequestDetails) Test(org.junit.jupiter.api.Test)

Aggregations

RequestDetails (com.adobe.target.delivery.v1.model.RequestDetails)6 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)5 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)4 Test (org.junit.jupiter.api.Test)4 Context (com.adobe.target.delivery.v1.model.Context)3 Geo (com.adobe.target.delivery.v1.model.Geo)2 HashMap (java.util.HashMap)2 Address (com.adobe.target.delivery.v1.model.Address)1 DeliveryRequest (com.adobe.target.delivery.v1.model.DeliveryRequest)1 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)1 Notification (com.adobe.target.delivery.v1.model.Notification)1 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)1 OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)1 TimingTool (com.adobe.target.edge.client.utils.TimingTool)1