Search in sources :

Example 16 with OnDeviceDecisioningRuleSet

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);
}
Also used : ClientProxyConfig(com.adobe.target.edge.client.ClientProxyConfig) TargetClientException(com.adobe.target.edge.client.exception.TargetClientException) JacksonObjectMapper(com.adobe.target.edge.client.http.JacksonObjectMapper) TargetExceptionHandler(com.adobe.target.edge.client.exception.TargetExceptionHandler) JacksonObjectMapper(com.adobe.target.edge.client.http.JacksonObjectMapper) OnDeviceDecisioningHandler(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningHandler) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)

Example 17 with OnDeviceDecisioningRuleSet

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

OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)17 Test (org.junit.jupiter.api.Test)11 OnDeviceDecisioningEvaluation (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation)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 TargetClientException (com.adobe.target.edge.client.exception.TargetClientException)4 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)3 MboxRequest (com.adobe.target.delivery.v1.model.MboxRequest)3 ClientConfig (com.adobe.target.edge.client.ClientConfig)3 TargetExceptionHandler (com.adobe.target.edge.client.exception.TargetExceptionHandler)2 OnDeviceDecisioningHandler (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningHandler)2 TimingTool (com.adobe.target.edge.client.utils.TimingTool)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 DeliveryRequest (com.adobe.target.delivery.v1.model.DeliveryRequest)1 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)1 Notification (com.adobe.target.delivery.v1.model.Notification)1 RequestDetails (com.adobe.target.delivery.v1.model.RequestDetails)1 ClientProxyConfig (com.adobe.target.edge.client.ClientProxyConfig)1