Search in sources :

Example 1 with OnDeviceDecisioningEvaluation

use of com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation in project target-java-sdk by adobe.

the class OnDeviceDecisioningService method buildDeliveryResponse.

private TargetDeliveryResponse buildDeliveryResponse(TargetDeliveryRequest deliveryRequest, String requestId) {
    OnDeviceDecisioningEvaluation localEvaluation = evaluateLocalExecution(deliveryRequest);
    int status = localEvaluation.isAllLocal() ? HttpStatus.SC_OK : HttpStatus.SC_PARTIAL_CONTENT;
    DeliveryResponse deliveryResponse = new DeliveryResponse().client(clientConfig.getClient()).requestId(requestId).id(deliveryRequest.getDeliveryRequest().getId()).status(status);
    PrefetchResponse prefetchResponse = new PrefetchResponse();
    ExecuteResponse executeResponse = new ExecuteResponse();
    deliveryResponse.setPrefetch(prefetchResponse);
    deliveryResponse.setExecute(executeResponse);
    TargetDeliveryResponse targetResponse = new TargetDeliveryResponse(deliveryRequest, deliveryResponse, status, localEvaluation.isAllLocal() ? "Local-decisioning response" : localEvaluation.getReason());
    ResponseStatus responseStatus = targetResponse.getResponseStatus();
    responseStatus.setGlobalMbox(localEvaluation.getGlobalMbox());
    responseStatus.setRemoteMboxes(localEvaluation.getRemoteMBoxes());
    responseStatus.setRemoteViews(localEvaluation.getRemoteViews());
    return targetResponse;
}
Also used : TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) PrefetchResponse(com.adobe.target.delivery.v1.model.PrefetchResponse) ResponseStatus(com.adobe.target.edge.client.http.ResponseStatus) ExecuteResponse(com.adobe.target.delivery.v1.model.ExecuteResponse) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) DeliveryResponse(com.adobe.target.delivery.v1.model.DeliveryResponse) OnDeviceDecisioningEvaluation(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation)

Example 2 with OnDeviceDecisioningEvaluation

use of com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation 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 3 with OnDeviceDecisioningEvaluation

use of com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation in project target-java-sdk by adobe.

the class OnDeviceDecisioningEvaluatorTest method testNoRuleSet.

@Test
public void testNoRuleSet() {
    RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoader(null);
    evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
    TargetDeliveryRequest request = TargetDeliveryRequest.builder().build();
    OnDeviceDecisioningEvaluation evaluation = evaluator.evaluateLocalExecution(request);
    assertFalse(evaluation.isAllLocal());
    assertNull(evaluation.getRemoteMBoxes());
    assertNull(evaluation.getRemoteViews());
}
Also used : TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) OnDeviceDecisioningEvaluation(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation) Test(org.junit.jupiter.api.Test)

Example 4 with OnDeviceDecisioningEvaluation

use of com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation in project target-java-sdk by adobe.

the class OnDeviceDecisioningEvaluatorTest method testLocalAndRemoteView.

@Test
public void testLocalAndRemoteView() throws JsonProcessingException, NoSuchFieldException {
    OnDeviceDecisioningRuleSet ruleSet = new OnDeviceDecisioningRuleSet();
    List<String> views = new ArrayList<>();
    views.add("test");
    views.add("test2");
    FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("localViews"), views);
    FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("remoteViews"), views);
    String serializedRuleSet = objectMapper.writeValueAsString(ruleSet);
    RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoader(serializedRuleSet);
    evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
    TargetDeliveryRequest request = TargetDeliveryRequest.builder().prefetch(new PrefetchRequest().addViewsItem(new ViewRequest().name("test")).addViewsItem(new ViewRequest().name("test2"))).build();
    OnDeviceDecisioningEvaluation evaluation = evaluator.evaluateLocalExecution(request);
    assertFalse(evaluation.isAllLocal());
    List<String> remoteViews = evaluation.getRemoteViews();
    remoteViews.sort(Comparator.naturalOrder());
    assertEquals(views, remoteViews);
    assertNull(evaluation.getRemoteMBoxes());
}
Also used : PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) ArrayList(java.util.ArrayList) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) ViewRequest(com.adobe.target.delivery.v1.model.ViewRequest) 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 5 with OnDeviceDecisioningEvaluation

use of com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation in project target-java-sdk by adobe.

the class OnDeviceDecisioningEvaluatorTest method testNullRequest.

@Test
public void testNullRequest() throws JsonProcessingException {
    OnDeviceDecisioningRuleSet ruleSet = new OnDeviceDecisioningRuleSet();
    String serializedRuleSet = objectMapper.writeValueAsString(ruleSet);
    RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoader(serializedRuleSet);
    evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
    OnDeviceDecisioningEvaluation evaluation = evaluator.evaluateLocalExecution(null);
    assertFalse(evaluation.isAllLocal());
    assertNull(evaluation.getRemoteMBoxes());
    assertNull(evaluation.getRemoteViews());
}
Also used : OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet) OnDeviceDecisioningEvaluation(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation) Test(org.junit.jupiter.api.Test)

Aggregations

OnDeviceDecisioningEvaluation (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation)12 OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)10 Test (org.junit.jupiter.api.Test)10 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)9 ArrayList (java.util.ArrayList)9 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)5 ViewRequest (com.adobe.target.delivery.v1.model.ViewRequest)5 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)3 MboxRequest (com.adobe.target.delivery.v1.model.MboxRequest)3 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)1 ExecuteResponse (com.adobe.target.delivery.v1.model.ExecuteResponse)1 PrefetchResponse (com.adobe.target.delivery.v1.model.PrefetchResponse)1 ResponseStatus (com.adobe.target.edge.client.http.ResponseStatus)1 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)1