Search in sources :

Example 11 with OnDeviceDecisioningEvaluation

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

the class OnDeviceDecisioningEvaluatorTest method testAllLocalNoRemoteAllViews.

@Test
public void testAllLocalNoRemoteAllViews() throws JsonProcessingException, NoSuchFieldException {
    OnDeviceDecisioningRuleSet ruleSet = new OnDeviceDecisioningRuleSet();
    List<String> localViews = new ArrayList<>();
    localViews.add("test");
    localViews.add("test2");
    FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("localViews"), localViews);
    FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("remoteViews"), new ArrayList<String>());
    String serializedRuleSet = objectMapper.writeValueAsString(ruleSet);
    RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoader(serializedRuleSet);
    evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
    TargetDeliveryRequest request = TargetDeliveryRequest.builder().prefetch(new PrefetchRequest().addViewsItem(new ViewRequest())).build();
    OnDeviceDecisioningEvaluation evaluation = evaluator.evaluateLocalExecution(request);
    assertTrue(evaluation.isAllLocal());
    assertNull(evaluation.getRemoteMBoxes());
    assertNull(evaluation.getRemoteViews());
}
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 12 with OnDeviceDecisioningEvaluation

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

the class OnDeviceDecisioningEvaluator method evaluateLocalExecution.

/**
 * Use to determine if the given request can be fully executed locally or not and why.
 *
 * @param deliveryRequest request to examine
 * @return LocalExecutionResult
 */
public OnDeviceDecisioningEvaluation evaluateLocalExecution(TargetDeliveryRequest deliveryRequest) {
    if (deliveryRequest == null) {
        return new OnDeviceDecisioningEvaluation(false, "Given request cannot be null", null, null, null);
    }
    OnDeviceDecisioningRuleSet ruleSet = this.ruleLoader.getLatestRules();
    if (ruleSet == null) {
        return new OnDeviceDecisioningEvaluation(false, "Local-decisioning rule set not yet available", null, null, null);
    }
    List<String> remoteMboxes = computeRemoteMboxes(deliveryRequest, ruleSet);
    List<String> remoteViews = computeRemoteViews(deliveryRequest, ruleSet);
    if (!remoteMboxes.isEmpty() || !remoteViews.isEmpty()) {
        StringBuilder reason = new StringBuilder("remote activities in: ");
        boolean haveRemoteMboxes = !remoteMboxes.isEmpty();
        if (haveRemoteMboxes) {
            reason.append(String.format("mboxes %s", remoteMboxes));
        }
        if (!remoteViews.isEmpty()) {
            if (haveRemoteMboxes) {
                reason.append(", ");
            }
            reason.append(String.format("views %s", remoteViews));
        }
        return new OnDeviceDecisioningEvaluation(false, reason.toString(), ruleSet.getGlobalMbox(), remoteMboxes.isEmpty() ? null : new ArrayList<>(remoteMboxes), remoteViews.isEmpty() ? null : new ArrayList<>(remoteViews));
    }
    return new OnDeviceDecisioningEvaluation(true, null, ruleSet.getGlobalMbox(), null, null);
}
Also used : ArrayList(java.util.ArrayList) OnDeviceDecisioningEvaluation(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)

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