Search in sources :

Example 6 with ExecuteRequest

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

the class DefaultTargetClient method addMBoxesToRequest.

private static TargetDeliveryRequest addMBoxesToRequest(TargetDeliveryRequest targetRequest, String... mboxes) {
    if (targetRequest == null || targetRequest.getDeliveryRequest() == null) {
        targetRequest = TargetDeliveryRequest.builder().decisioningMethod(DecisioningMethod.HYBRID).build();
    }
    int idx = 0;
    Set<String> existingMBoxNames = new HashSet<>();
    DeliveryRequest deliveryRequest = targetRequest.getDeliveryRequest();
    PrefetchRequest prefetchRequest = deliveryRequest.getPrefetch();
    if (prefetchRequest != null && prefetchRequest.getMboxes() != null) {
        for (MboxRequest mb : prefetchRequest.getMboxes()) {
            existingMBoxNames.add(mb.getName());
        }
    }
    ExecuteRequest executeRequest = deliveryRequest.getExecute();
    if (executeRequest != null) {
        List<MboxRequest> executeMboxes = executeRequest.getMboxes();
        if (executeMboxes != null) {
            for (MboxRequest mb : executeMboxes) {
                if (mb.getIndex() >= idx) {
                    idx = mb.getIndex() + 1;
                }
                existingMBoxNames.add(mb.getName());
            }
        }
    }
    for (String mbox : mboxes) {
        if (!existingMBoxNames.contains(mbox)) {
            if (executeRequest == null) {
                executeRequest = new ExecuteRequest();
                targetRequest.getDeliveryRequest().setExecute(executeRequest);
            }
            executeRequest.addMboxesItem(new MboxRequest().index(idx++).name(mbox));
        }
    }
    return targetRequest;
}
Also used : PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) MboxRequest(com.adobe.target.delivery.v1.model.MboxRequest) HashSet(java.util.HashSet)

Example 7 with ExecuteRequest

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

the class OnDeviceDecisioningEvaluatorTest method testUnknownMbox.

@Test
public void testUnknownMbox() throws JsonProcessingException, NoSuchFieldException {
    OnDeviceDecisioningRuleSet ruleSet = new OnDeviceDecisioningRuleSet();
    List<String> mboxes = new ArrayList<>();
    mboxes.add("test");
    FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("localMboxes"), mboxes);
    FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("remoteMboxes"), new ArrayList<>());
    String serializedRuleSet = objectMapper.writeValueAsString(ruleSet);
    RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoader(serializedRuleSet);
    evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
    TargetDeliveryRequest request = TargetDeliveryRequest.builder().execute(new ExecuteRequest().addMboxesItem(new MboxRequest().name("test")).addMboxesItem(new MboxRequest().name("test2"))).build();
    OnDeviceDecisioningEvaluation evaluation = evaluator.evaluateLocalExecution(request);
    assertFalse(evaluation.isAllLocal());
    List<String> remoteMboxes = new ArrayList<>();
    remoteMboxes.add("test2");
    assertEquals(remoteMboxes, evaluation.getRemoteMBoxes());
    assertNull(evaluation.getRemoteViews());
}
Also used : ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) MboxRequest(com.adobe.target.delivery.v1.model.MboxRequest) ArrayList(java.util.ArrayList) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet) OnDeviceDecisioningEvaluation(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation) Test(org.junit.jupiter.api.Test)

Example 8 with ExecuteRequest

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

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

Example 10 with ExecuteRequest

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

the class TimeParamsCollatorTest method testCollator.

@Test
public void testCollator() {
    VisitorProvider.init("testOrgId");
    TimeParamsCollator collator = mock(TimeParamsCollator.class, CALLS_REAL_METHODS);
    long now = 1592433971000L;
    Mockito.doReturn(now).when(collator).currentTimestamp();
    RequestDetails pageLoad = new RequestDetails();
    TargetDeliveryRequest request = TargetDeliveryRequest.builder().execute(new ExecuteRequest().pageLoad(pageLoad)).build();
    Map<String, Object> result = collator.collateParams(request, pageLoad);
    assertEquals(now, result.get(TimeParamsCollator.CURRENT_TIMESTAMP));
    assertEquals("3", result.get(TimeParamsCollator.CURRENT_DAY));
    assertEquals("2246", result.get(TimeParamsCollator.CURRENT_TIME));
}
Also used : 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

ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)27 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)26 Test (org.junit.jupiter.api.Test)22 Context (com.adobe.target.delivery.v1.model.Context)19 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)15 TargetTestDeliveryRequestUtils.getContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext)15 TargetTestDeliveryRequestUtils.getMboxExecuteRequest (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest)15 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)14 TimingTool (com.adobe.target.edge.client.utils.TimingTool)13 MboxRequest (com.adobe.target.delivery.v1.model.MboxRequest)10 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)8 Property (com.adobe.target.delivery.v1.model.Property)8 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 RequestDetails (com.adobe.target.delivery.v1.model.RequestDetails)5 Telemetry (com.adobe.target.delivery.v1.model.Telemetry)5 OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)4 ArrayList (java.util.ArrayList)4 Notification (com.adobe.target.delivery.v1.model.Notification)3