Search in sources :

Example 1 with Context

use of com.adobe.target.delivery.v1.model.Context 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 Context

use of com.adobe.target.delivery.v1.model.Context in project target-java-sdk by adobe.

the class UserParamsCollator method extractUserAgent.

private String extractUserAgent(TargetDeliveryRequest deliveryRequest) {
    Context context = deliveryRequest.getDeliveryRequest().getContext();
    if (context == null) {
        return null;
    }
    String userAgent = context.getUserAgent();
    if (StringUtils.isEmpty(userAgent)) {
        return null;
    }
    return userAgent;
}
Also used : Context(com.adobe.target.delivery.v1.model.Context)

Example 3 with Context

use of com.adobe.target.delivery.v1.model.Context in project target-java-sdk by adobe.

the class OnDeviceDecisioningService method geoLookupIfNeeded.

private void geoLookupIfNeeded(TargetDeliveryRequest deliveryRequest, boolean doGeoLookup) {
    if (!doGeoLookup) {
        return;
    }
    Context context = deliveryRequest.getDeliveryRequest().getContext();
    if (context != null) {
        Geo geo = context.getGeo();
        if (geo != null) {
            if (StringUtils.isNotEmpty(geo.getIpAddress()) && StringUtils.isEmpty(geo.getCity()) && StringUtils.isEmpty(geo.getStateCode()) && StringUtils.isEmpty(geo.getCountryCode()) && geo.getLatitude() == null && geo.getLongitude() == null) {
                Geo resolvedGeo = this.geoClient.lookupGeo(geo.getIpAddress());
                deliveryRequest.getDeliveryRequest().getContext().setGeo(resolvedGeo);
            }
        }
    }
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) Geo(com.adobe.target.delivery.v1.model.Geo)

Example 4 with Context

use of com.adobe.target.delivery.v1.model.Context 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());
}
Also used : TargetTestDeliveryRequestUtils.getContext(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext) Context(com.adobe.target.delivery.v1.model.Context) PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) TargetTestDeliveryRequestUtils.getMboxExecuteRequest(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetRequestException(com.adobe.target.edge.client.exception.TargetRequestException) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Test(org.junit.jupiter.api.Test)

Example 5 with Context

use of com.adobe.target.delivery.v1.model.Context 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

Context (com.adobe.target.delivery.v1.model.Context)24 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)22 Test (org.junit.jupiter.api.Test)19 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)18 TargetTestDeliveryRequestUtils.getContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext)17 TargetTestDeliveryRequestUtils.getMboxExecuteRequest (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest)15 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)14 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)13 TimingTool (com.adobe.target.edge.client.utils.TimingTool)12 Property (com.adobe.target.delivery.v1.model.Property)8 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)6 MboxRequest (com.adobe.target.delivery.v1.model.MboxRequest)6 TelemetryEntry (com.adobe.target.delivery.v1.model.TelemetryEntry)6 TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse)6 TargetTestDeliveryRequestUtils.getTestDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse)6 Telemetry (com.adobe.target.delivery.v1.model.Telemetry)4 Test (org.junit.Test)4 Geo (com.adobe.target.delivery.v1.model.Geo)3 Notification (com.adobe.target.delivery.v1.model.Notification)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3