use of com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet in project target-java-sdk by adobe.
the class DefaultRuleLoader method start.
@Override
public synchronized void start(final ClientConfig clientConfig, TelemetryService telemetryService) {
if (!clientConfig.isOnDeviceDecisioningEnabled()) {
return;
}
if (started) {
return;
}
ObjectMapper mapper = new JacksonObjectMapper();
byte[] artifactPayload = clientConfig.getOnDeviceArtifactPayload();
if (artifactPayload != null) {
String payload = new String(artifactPayload, StandardCharsets.UTF_8);
OnDeviceDecisioningRuleSet ruleSet = mapper.readValue(payload, new GenericType<OnDeviceDecisioningRuleSet>() {
});
String invalidMessage = invalidRuleSetMessage(ruleSet, null);
if (invalidMessage == null) {
setLatestRules(ruleSet);
OnDeviceDecisioningHandler handler = clientConfig.getOnDeviceDecisioningHandler();
if (handler != null && !succeeded) {
succeeded = true;
handler.onDeviceDecisioningReady();
}
} else {
logger.warn(invalidMessage);
TargetExceptionHandler handler = clientConfig.getExceptionHandler();
if (handler != null) {
handler.handleException(new TargetClientException(invalidMessage));
}
}
}
started = true;
retries = 0;
if (unirestInstance != null) {
unirestInstance.config().socketTimeout(clientConfig.getSocketTimeout()).connectTimeout(clientConfig.getConnectTimeout()).concurrency(clientConfig.getMaxConnectionsTotal(), clientConfig.getMaxConnectionsPerHost()).automaticRetries(clientConfig.isEnabledRetries()).enableCookieManagement(false).setObjectMapper(mapper).setDefaultHeader("Accept", "application/json");
if (clientConfig.isProxyEnabled()) {
ClientProxyConfig proxyConfig = clientConfig.getProxyConfig();
if (proxyConfig.isAuthProxy()) {
unirestInstance.config().proxy(proxyConfig.getHost(), proxyConfig.getPort(), proxyConfig.getUsername(), proxyConfig.getPassword());
} else {
unirestInstance.config().proxy(proxyConfig.getHost(), proxyConfig.getPort());
}
}
}
this.clientConfig = clientConfig;
this.telemetryService = telemetryService;
this.scheduleTimer(0);
}
use of com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet 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