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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.ironoc.rules.engine</groupId>
<artifactId>simple-rules-engine</artifactId>
<version>2.4-SNAPSHOT</version>
<version>2.5-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/ironoc/rules/engine/ApiApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ static void main(String... args) {

@EventListener
public void processPostDeploy(PostDeployEvent event) {
runtimeService.startProcessInstanceByKey("loanApproval");
runtimeService.startProcessInstanceByKey("Rules_matcher");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import java.util.Objects;

@Component
public class FeatureDelegate implements JavaDelegate {
public class CountryDelegate implements JavaDelegate {

private static final Logger LOGGER = LoggerFactory.getLogger(FeatureDelegate.class);
private static final Logger LOGGER = LoggerFactory.getLogger(CountryDelegate.class);

public static final String VAR_COUNTRY = "country";

Expand All @@ -21,4 +21,4 @@ public void execute(DelegateExecution execution) {
String country = Objects.toString(execution.getVariable(VAR_COUNTRY), "").trim();
LOGGER.info("Country captured='{}' (matching is performed in RulesAggregatorDelegate via RulesService).", country);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void execute(DelegateExecution execution) {
if (skip || !featureEnabled) {
matchedRules = new ArrayList<>();
} else {
String country = Objects.toString(execution.getVariable(FeatureDelegate.VAR_COUNTRY), "").trim();
String country = Objects.toString(execution.getVariable(CountryDelegate.VAR_COUNTRY), "").trim();
String appVersion = Objects.toString(execution.getVariable(AppVersionDelegate.VAR_APP_VERSION), "").trim();
String tier = Objects.toString(execution.getVariable(TierDelegate.VAR_TIER), "").trim();

Expand All @@ -73,4 +73,4 @@ public void execute(DelegateExecution execution) {
throw new IllegalStateException("Failed to serialize matched rules to JSON", e);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.ironoc.rules.engine.enums;

public enum FeatureType {
public enum FeatureFlag {

TIER, APPVERSION, COUNTRY
}
10 changes: 5 additions & 5 deletions src/main/java/net/ironoc/rules/engine/service/RulesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.ironoc.rules.engine.domain.ApiResponse;
import net.ironoc.rules.engine.dto.Feature;
import net.ironoc.rules.engine.dto.Rule;
import net.ironoc.rules.engine.enums.FeatureType;
import net.ironoc.rules.engine.enums.FeatureFlag;
import net.ironoc.rules.engine.enums.RuleGroup;
import net.ironoc.rules.engine.enums.RuleOperator;
import org.camunda.bpm.engine.delegate.DelegateExecution;
Expand Down Expand Up @@ -93,16 +93,16 @@ protected List<Rule> rulesMatcher(String country, String appVersion, String tier
Rule rule = this.objectMapper.convertValue(ruleMap, Rule.class);
RuleOperator ruleOperator = RuleOperator.fromStr(rule.op());
// validate features (check for matching rules)
validateStringMatch(country, rule, ruleOperator, ruleMatch, FeatureType.COUNTRY);
validateStringMatch(country, rule, ruleOperator, ruleMatch, FeatureFlag.COUNTRY);
validateAppVersionMatch(appVersion, rule, ruleOperator, ruleMatch);
validateStringMatch(tier, rule, ruleOperator, ruleMatch, FeatureType.TIER);
validateStringMatch(tier, rule, ruleOperator, ruleMatch, FeatureFlag.TIER);
}
}
return ruleMatch;
}

private void validateStringMatch(String inputStr, Rule rule, RuleOperator ruleOperator, List<Rule> ruleMatch,
FeatureType featureType) {
FeatureFlag featureType) {
if (rule.attr().equalsIgnoreCase(featureType.name())) {
switch (ruleOperator) {
case RuleOperator.IN:
Expand All @@ -119,7 +119,7 @@ private void validateStringMatch(String inputStr, Rule rule, RuleOperator ruleOp
}

private void validateAppVersionMatch(String appVersion, Rule rule, RuleOperator ruleOperator, List<Rule> ruleMatch) {
if (rule.attr().equalsIgnoreCase(FeatureType.APPVERSION.name())) {
if (rule.attr().equalsIgnoreCase(FeatureFlag.APPVERSION.name())) {
switch (ruleOperator) {
case RuleOperator.GTE:
case RuleOperator.GT:
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/processes/rules-matcher.bpmn
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<bpmn2:outgoing>Flow_03tvbfd</bpmn2:outgoing>
</bpmn2:serviceTask>

<bpmn2:serviceTask id="Activity_0sdwngs" name="Country Code Valid / Supported?" camunda:class="net.ironoc.rules.engine.delegate.FeatureDelegate">
<bpmn2:serviceTask id="Activity_0sdwngs" name="Country Code Valid / Supported?" camunda:class="net.ironoc.rules.engine.delegate.CountryDelegate">
<bpmn2:incoming>Flow_03tvbfd</bpmn2:incoming>
<bpmn2:outgoing>Flow_0df9t6r</bpmn2:outgoing>
</bpmn2:serviceTask>
Expand Down Expand Up @@ -303,4 +303,4 @@
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>
</bpmn2:definitions>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.ironoc.rules.engine.domain.ApiResponse;
import net.ironoc.rules.engine.dto.Feature;
import net.ironoc.rules.engine.dto.RuleGroups;
import net.ironoc.rules.engine.enums.FeatureType;
import net.ironoc.rules.engine.enums.FeatureFlag;
import net.ironoc.rules.engine.service.FeatureDetailService;
import net.ironoc.rules.engine.service.RulesService;
import org.camunda.bpm.engine.RuntimeService;
Expand Down Expand Up @@ -111,7 +111,7 @@ void evaluateFlags_matchesFromAllAndAny_returnsOkAndCombinedList() {
assertNotNull(response.getBody());
assertEquals(2, response.getBody().rules().size());

assertTrue(response.getBody().rules().stream().anyMatch(r -> FeatureType.COUNTRY.name().equalsIgnoreCase(r.attr())));
assertTrue(response.getBody().rules().stream().anyMatch(r -> FeatureType.TIER.name().equalsIgnoreCase(r.attr())));
assertTrue(response.getBody().rules().stream().anyMatch(r -> FeatureFlag.COUNTRY.name().equalsIgnoreCase(r.attr())));
assertTrue(response.getBody().rules().stream().anyMatch(r -> FeatureFlag.TIER.name().equalsIgnoreCase(r.attr())));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import net.ironoc.rules.engine.dto.Rule;
import net.ironoc.rules.engine.enums.FeatureType;
import net.ironoc.rules.engine.enums.FeatureFlag;
import net.ironoc.rules.engine.enums.RuleOperator;
import org.junit.jupiter.api.Test;
import org.springframework.core.env.Environment;
Expand Down Expand Up @@ -37,7 +37,7 @@ void rulesMatcher_countryIn_matches() {
List<Rule> matches = service.rulesMatcher("ES", "10", "FREE", rules);

assertEquals(1, matches.size());
assertEquals(FeatureType.COUNTRY.name(), matches.getFirst().attr());
assertEquals(FeatureFlag.COUNTRY.name(), matches.getFirst().attr());
assertEquals(RuleOperator.IN.name(), matches.getFirst().op());
}

Expand All @@ -56,7 +56,7 @@ void rulesMatcher_appVersionGte_matches() {
List<Rule> matches = service.rulesMatcher("ES", "12", "FREE", rules);

assertEquals(1, matches.size());
assertEquals(FeatureType.APPVERSION.name(), matches.getFirst().attr());
assertEquals(FeatureFlag.APPVERSION.name(), matches.getFirst().attr());
assertEquals(RuleOperator.GTE.name(), matches.getFirst().op());
}

Expand All @@ -76,4 +76,4 @@ void rulesMatcher_countryWithUnsupportedOperator_doesNotMatch() {

assertTrue(matches.isEmpty());
}
}
}
Loading