use of com.ibm.watson.assistant.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;
}
use of com.ibm.watson.assistant.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;
}
use of com.ibm.watson.assistant.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);
}
}
}
}
use of com.ibm.watson.assistant.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());
}
use of com.ibm.watson.assistant.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);
}
Aggregations