Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,35 +171,14 @@ internal class LaunchRulesConsequence(
return processedConsequences
}

fun getReevaluableRules(rules: MutableList<LaunchRule>): MutableList<LaunchRule?> {
val revaluableRules: MutableList<LaunchRule?> = java.util.ArrayList<LaunchRule?>()
for (rule in rules) {
if (rule.meta.reEvaluate && rule.hasReevaluableSupportedConsequence) {
revaluableRules.add(rule)
}
}
return revaluableRules
}
fun getReevaluableRules(rules: List<LaunchRule>): List<LaunchRule> =
rules.filter { it.meta.reEvaluate && it.hasReevaluableSupportedConsequence }

fun getRulesToHoldForReevaluation(rules: MutableList<LaunchRule>): MutableList<LaunchRule?> {
val rulesToHold: MutableList<LaunchRule?> = ArrayList()
for (rule in rules) {
if (rule.hasReevaluableSupportedConsequence) {
rulesToHold.add(rule)
}
}
return rulesToHold
}
fun getRulesToHoldForReevaluation(rules: List<LaunchRule>): List<LaunchRule> =
rules.filter { it.hasReevaluableSupportedConsequence }

private val LaunchRule.hasReevaluableSupportedConsequence: Boolean
get() {
for (consequence in this.consequenceList) {
if (REEVALUABLE_CONSEQUENCE_TYPES.contains(consequence.type)) {
return true
}
}
return false
}
get() = consequenceList.any { it.type in REEVALUABLE_CONSEQUENCE_TYPES }

/**
* Replace tokens inside the provided [RuleConsequence] with the right value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@

public class LaunchRulesEngine {

private RuleReevaluationInterceptor reevaluationInterceptor;

@VisibleForTesting static final String RULES_ENGINE_NAME = "name";
private final String name;
private final RulesEngine<LaunchRule> ruleRulesEngine;
private final ExtensionApi extensionApi;
private final LaunchRulesConsequence launchRulesConsequence;
private final List<Event> cachedEvents = new ArrayList<>();
private boolean initialRulesReceived = false;
private RuleReevaluationInterceptor reevaluationInterceptor;

public LaunchRulesEngine(@NonNull final String name, @NonNull final ExtensionApi extensionApi) {
this(
Expand Down Expand Up @@ -162,6 +161,17 @@ private Event processAndIntercept(final Event event) {
final ArrayList<LaunchRule> rulesToProcess = new ArrayList<>(matchedRules);
rulesToProcess.removeAll(rulesToHold);
Event processedEvent = launchRulesConsequence.process(event, rulesToProcess);
triggerReEvaluation(
processedEvent, revaluableRules, rulesToProcess, reevaluationInterceptor);
return processedEvent;
}

private void triggerReEvaluation(
final Event processedEvent,
final List<LaunchRule> revaluableRules,
final List<LaunchRule> processedRules,
final RuleReevaluationInterceptor reevaluationInterceptor) {
final LaunchTokenFinder tokenFinder = new LaunchTokenFinder(processedEvent, extensionApi);
reevaluationInterceptor.onReevaluationTriggered(
processedEvent,
revaluableRules,
Expand All @@ -172,11 +182,10 @@ private Event processAndIntercept(final Event event) {
if (success) {
final ArrayList<LaunchRule> newlyMatchedRules =
new ArrayList<>(ruleRulesEngine.evaluate(tokenFinder));
newlyMatchedRules.removeAll(rulesToProcess);
newlyMatchedRules.removeAll(processedRules);
launchRulesConsequence.process(processedEvent, newlyMatchedRules);
}
});
return processedEvent;
}

List<LaunchRule> getRules() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Adobe. All rights reserved.
Copyright 2026 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import com.adobe.marketing.mobile.Event
*/
interface RuleReevaluationInterceptor {
fun onReevaluationTriggered(
event: Event?,
revaluableRules: List<LaunchRule?>?,
callback: AdobeCallback<Boolean>?
event: Event,
revaluableRules: List<LaunchRule?>,
callback: AdobeCallback<Boolean>
)
}
Loading