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());
}
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);
}
Aggregations