diff --git a/drools-ansible-rulebook-integration-api/pom.xml b/drools-ansible-rulebook-integration-api/pom.xml index 05409e28..2012bd28 100644 --- a/drools-ansible-rulebook-integration-api/pom.xml +++ b/drools-ansible-rulebook-integration-api/pom.xml @@ -5,7 +5,7 @@ drools-ansible-rulebook-integration org.drools - 1.0.6-SNAPSHOT + 1.0.7-SNAPSHOT 4.0.0 diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/RulesExecutor.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/RulesExecutor.java index 88f98b05..5df57a3f 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/RulesExecutor.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/RulesExecutor.java @@ -4,7 +4,7 @@ import org.drools.ansible.rulebook.integration.api.rulesengine.RulesEvaluator; import org.drools.ansible.rulebook.integration.api.rulesengine.RulesExecutorSession; import org.drools.ansible.rulebook.integration.api.rulesengine.SessionStats; -import org.drools.base.facttemplates.Fact; +import org.kie.api.prototype.PrototypeFactInstance; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.Match; import org.slf4j.Logger; @@ -90,7 +90,7 @@ public Collection getAllFacts() { } public List> getAllFactsAsMap() { - return getAllFacts().stream().map(Fact.class::cast).map(Fact::asMap).collect(Collectors.toList()); + return getAllFacts().stream().map(PrototypeFactInstance.class::cast).map(PrototypeFactInstance::asMap).collect(Collectors.toList()); } public String getAllFactsAsJson() { diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/RuleGenerationContext.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/RuleGenerationContext.java index 8bcb768a..30d0ea15 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/RuleGenerationContext.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/RuleGenerationContext.java @@ -1,16 +1,5 @@ package org.drools.ansible.rulebook.integration.api.domain; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Deque; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Function; - import org.drools.ansible.rulebook.integration.api.RuleConfigurationOption; import org.drools.ansible.rulebook.integration.api.RuleConfigurationOptions; import org.drools.ansible.rulebook.integration.api.domain.actions.Action; @@ -18,19 +7,31 @@ import org.drools.ansible.rulebook.integration.api.domain.temporal.TimeConstraint; import org.drools.ansible.rulebook.integration.api.rulesengine.RulesExecutionController; import org.drools.model.Drools; -import org.drools.model.PrototypeDSL; -import org.drools.model.PrototypeVariable; import org.drools.model.Rule; import org.drools.model.RuleItemBuilder; import org.drools.model.Variable; +import org.drools.model.prototype.PrototypeDSL; +import org.drools.model.prototype.PrototypeVariable; import org.drools.model.view.ViewItem; -import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.getPrototype; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; + +import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.getPrototypeEvent; +import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.getPrototypeFact; import static org.drools.model.DSL.execute; import static org.drools.model.DSL.on; import static org.drools.model.PatternDSL.rule; -import static org.drools.model.PrototypeDSL.protoPattern; -import static org.drools.model.PrototypeDSL.variable; +import static org.drools.model.prototype.PrototypeDSL.protoPattern; +import static org.drools.model.prototype.PrototypeDSL.variable; public class RuleGenerationContext { @@ -72,8 +73,8 @@ public void addOptions(Iterable options) { this.options.addOptions(options); } - public PrototypeDSL.PrototypePatternDef getOrCreatePattern(String binding, String name) { - return patterns.computeIfAbsent(binding, b -> protoPattern(variable(getPrototype(name), b))); + public PrototypeDSL.PrototypePatternDef getOrCreatePattern(String binding, String name, boolean event) { + return patterns.computeIfAbsent(binding, b -> protoPattern(variable(event ? getPrototypeEvent(name) : getPrototypeFact(name), b))); } public PrototypeVariable getPatternVariable(String binding) { diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/AstCondition.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/AstCondition.java index 3afab1b4..9b93b9c0 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/AstCondition.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/AstCondition.java @@ -1,17 +1,17 @@ package org.drools.ansible.rulebook.integration.api.domain.conditions; -import java.util.ArrayList; -import java.util.List; - import org.drools.ansible.rulebook.integration.api.domain.RuleGenerationContext; import org.drools.ansible.rulebook.integration.api.domain.temporal.OnceWithinDefinition; import org.drools.ansible.rulebook.integration.api.rulesmodel.ParsedCondition; import org.drools.model.Index; -import org.drools.model.PrototypeDSL; -import org.drools.model.PrototypeExpression; +import org.drools.model.prototype.PrototypeDSL; +import org.drools.model.prototype.PrototypeExpression; import org.drools.model.view.CombinedExprViewItem; import org.drools.model.view.ViewItem; +import java.util.ArrayList; +import java.util.List; + import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.DEFAULT_PROTOTYPE_NAME; public class AstCondition implements Condition { @@ -145,7 +145,7 @@ protected PrototypeDSL.PrototypePatternDef getPattern(RuleGenerationContext rule protected PrototypeDSL.PrototypePatternDef getPattern(RuleGenerationContext ruleContext, String binding) { if (pattern == null) { - pattern = ruleContext.getOrCreatePattern(binding, DEFAULT_PROTOTYPE_NAME); + pattern = ruleContext.getOrCreatePattern(binding, DEFAULT_PROTOTYPE_NAME, ruleContext.getTimeConstraint().isPresent()); } return pattern; } @@ -273,7 +273,7 @@ SingleCondition withPatternBinding(RuleGenerationContext ruleContext, String pat if (parent != null) { parent.beforeBinding(); } - this.pattern = ruleContext.getOrCreatePattern(patternBinding, DEFAULT_PROTOTYPE_NAME); + this.pattern = ruleContext.getOrCreatePattern(patternBinding, DEFAULT_PROTOTYPE_NAME, ruleContext.getTimeConstraint().isPresent()); if (parent != null) { parent.afterBinding(); } diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/Condition.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/Condition.java index 62972a6a..3223d338 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/Condition.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/Condition.java @@ -1,8 +1,7 @@ package org.drools.ansible.rulebook.integration.api.domain.conditions; -import org.drools.model.PrototypeDSL; -import org.drools.model.view.ViewItem; import org.drools.ansible.rulebook.integration.api.domain.RuleGenerationContext; +import org.drools.model.view.ViewItem; public interface Condition { ViewItem toPattern(RuleGenerationContext ruleContext); diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/ConditionExpression.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/ConditionExpression.java index bd6a302a..3a36e3a0 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/ConditionExpression.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/ConditionExpression.java @@ -1,23 +1,20 @@ package org.drools.ansible.rulebook.integration.api.domain.conditions; +import org.drools.ansible.rulebook.integration.api.domain.RuleGenerationContext; +import org.drools.ansible.rulebook.integration.protoextractor.prototype.ExtractorPrototypeExpressionUtils; +import org.drools.model.prototype.PrototypeDSL; +import org.drools.model.prototype.PrototypeExpression; +import org.drools.model.prototype.PrototypeVariable; + import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; -import org.drools.ansible.rulebook.integration.api.domain.RuleGenerationContext; -import org.drools.ansible.rulebook.integration.protoextractor.prototype.ExtractorPrototypeExpression; -import org.drools.ansible.rulebook.integration.protoextractor.prototype.ExtractorPrototypeExpressionUtils; -import org.drools.model.PrototypeDSL; -import org.drools.model.PrototypeExpression; -import org.drools.model.PrototypeVariable; - import static org.drools.ansible.rulebook.integration.api.domain.conditions.ConditionParseUtil.isEventOrFact; import static org.drools.ansible.rulebook.integration.api.domain.conditions.ConditionParseUtil.isKnownType; import static org.drools.ansible.rulebook.integration.api.domain.conditions.ConditionParseUtil.toJsonValue; -import static org.drools.model.PrototypeDSL.fieldName2PrototypeExpression; -import static org.drools.model.PrototypeExpression.fixedValue; -import static org.drools.model.PrototypeExpression.prototypeField; +import static org.drools.model.prototype.PrototypeExpression.fixedValue; public class ConditionExpression { diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/ConditionParseUtil.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/ConditionParseUtil.java index 04959337..76be0c9c 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/ConditionParseUtil.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/ConditionParseUtil.java @@ -1,13 +1,13 @@ package org.drools.ansible.rulebook.integration.api.domain.conditions; +import org.drools.ansible.rulebook.integration.api.io.JsonMapper; +import org.kie.api.prototype.Prototype; + import java.util.Collection; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import org.drools.ansible.rulebook.integration.api.io.JsonMapper; -import org.drools.model.Prototype; - public class ConditionParseUtil { private static final Set KNOWN_TYPES = Set.of("Integer", "Float", "String", "Boolean", "NullType"); diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/MapCondition.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/MapCondition.java index 31c046bf..9b34c77c 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/MapCondition.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/MapCondition.java @@ -27,7 +27,7 @@ import static org.drools.ansible.rulebook.integration.api.domain.conditions.ConditionExpression.map2Expr; import static org.drools.ansible.rulebook.integration.api.domain.conditions.ConditionExpression.mapEntry2Expr; -import static org.drools.model.PrototypeExpression.fixedValue; +import static org.drools.model.prototype.PrototypeExpression.fixedValue; public class MapCondition implements Condition { diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/SimpleCondition.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/SimpleCondition.java index a234d908..f16274d4 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/SimpleCondition.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/conditions/SimpleCondition.java @@ -1,17 +1,17 @@ package org.drools.ansible.rulebook.integration.api.domain.conditions; -import java.util.Arrays; -import java.util.List; - +import org.drools.ansible.rulebook.integration.api.domain.RuleGenerationContext; +import org.drools.ansible.rulebook.integration.api.rulesmodel.ParsedCondition; import org.drools.model.Index; import org.drools.model.PatternDSL; -import org.drools.model.PrototypeDSL; -import org.drools.model.PrototypeExpression; -import org.drools.model.PrototypeVariable; +import org.drools.model.prototype.PrototypeDSL; +import org.drools.model.prototype.PrototypeExpression; +import org.drools.model.prototype.PrototypeVariable; import org.drools.model.view.CombinedExprViewItem; import org.drools.model.view.ViewItem; -import org.drools.ansible.rulebook.integration.api.domain.RuleGenerationContext; -import org.drools.ansible.rulebook.integration.api.rulesmodel.ParsedCondition; + +import java.util.Arrays; +import java.util.List; import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.DEFAULT_PROTOTYPE_NAME; @@ -212,7 +212,7 @@ private static ViewItem scopingCondition2Pattern(RuleGenerationContext ruleConte private static ViewItem singleCondition2Pattern(RuleGenerationContext ruleContext, SimpleCondition condition) { ParsedCondition parsedCondition = condition.parse(); - var pattern = ruleContext.getOrCreatePattern(condition.getPatternBinding(ruleContext), DEFAULT_PROTOTYPE_NAME); + var pattern = ruleContext.getOrCreatePattern(condition.getPatternBinding(ruleContext), DEFAULT_PROTOTYPE_NAME, ruleContext.getTimeConstraint().isPresent()); if (condition.beta()) { pattern.expr(parsedCondition.getLeft(), parsedCondition.getOperator(), ruleContext.getPatternVariable(condition.otherBinding()), parsedCondition.getRight()); } else { diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/ExistsField.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/ExistsField.java index 5ac288f5..fc4df189 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/ExistsField.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/ExistsField.java @@ -2,13 +2,13 @@ import org.drools.ansible.rulebook.integration.api.domain.RuleGenerationContext; import org.drools.ansible.rulebook.integration.api.rulesmodel.ParsedCondition; -import org.drools.model.Prototype; +import org.kie.api.prototype.Prototype; import java.util.Map; import java.util.function.BiPredicate; import static org.drools.ansible.rulebook.integration.api.domain.conditions.ConditionExpression.map2Expr; -import static org.drools.model.PrototypeExpression.thisPrototype; +import static org.drools.model.prototype.PrototypeExpression.thisPrototype; public enum ExistsField implements RulebookOperator, ConditionFactory { diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/NegatedExistsField.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/NegatedExistsField.java index 4d317679..62d522c4 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/NegatedExistsField.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/NegatedExistsField.java @@ -4,10 +4,10 @@ import org.drools.ansible.rulebook.integration.api.domain.conditions.ConditionExpression; import org.drools.ansible.rulebook.integration.api.rulesmodel.ParsedCondition; import org.drools.model.functions.Function1; -import org.drools.model.PrototypeExpression; -import org.drools.model.PrototypeVariable; -import org.drools.model.Prototype; -import org.drools.model.PrototypeFact; +import org.drools.model.prototype.PrototypeExpression; +import org.drools.model.prototype.PrototypeVariable; +import org.kie.api.prototype.Prototype; +import org.kie.api.prototype.PrototypeFactInstance; import java.util.Collection; import java.util.Map; @@ -15,7 +15,7 @@ import java.util.function.BiPredicate; import static org.drools.ansible.rulebook.integration.api.domain.conditions.ConditionExpression.map2Expr; -import static org.drools.model.PrototypeExpression.thisPrototype; +import static org.drools.model.prototype.PrototypeExpression.thisPrototype; public enum NegatedExistsField implements RulebookOperator, ConditionFactory { @@ -49,7 +49,7 @@ private PrototypeExpressionWithAdmittedUndefined(PrototypeExpression delegate) { } @Override - public Function1 asFunction(Prototype prototype) { + public Function1 asFunction(Prototype prototype) { return delegate.asFunction(prototype).andThen( result -> result == Prototype.UNDEFINED_VALUE ? ADMITTED_UNDEFINED_VALUE : result ); } diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SearchMatchesConstraint.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SearchMatchesConstraint.java index d4d2df41..9994fa40 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SearchMatchesConstraint.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SearchMatchesConstraint.java @@ -13,7 +13,7 @@ import static org.drools.ansible.rulebook.integration.api.domain.conditions.ConditionExpression.map2Expr; import static org.drools.ansible.rulebook.integration.api.domain.conditions.ConditionParseUtil.isRegexOperator; -import static org.drools.model.PrototypeExpression.fixedValue; +import static org.drools.model.prototype.PrototypeExpression.fixedValue; public enum SearchMatchesConstraint implements RulebookOperator, ConditionFactory { diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SelectAttrConstraint.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SelectAttrConstraint.java index f03ab5b1..8cf5b318 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SelectAttrConstraint.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SelectAttrConstraint.java @@ -4,7 +4,7 @@ import org.drools.ansible.rulebook.integration.api.domain.conditions.ConditionExpression; import org.drools.ansible.rulebook.integration.api.rulesmodel.ParsedCondition; import org.drools.model.ConstraintOperator; -import org.drools.model.Prototype; +import org.kie.api.prototype.Prototype; import java.util.Collection; import java.util.Map; @@ -16,7 +16,7 @@ import static org.drools.ansible.rulebook.integration.api.domain.conditions.ConditionParseUtil.mapToStringValue; import static org.drools.ansible.rulebook.integration.api.domain.conditions.ConditionParseUtil.toJsonValue; import static org.drools.ansible.rulebook.integration.api.domain.constraints.Operators.toOperatorPredicate; -import static org.drools.model.PrototypeExpression.fixedValue; +import static org.drools.model.prototype.PrototypeExpression.fixedValue; public enum SelectAttrConstraint implements RulebookOperator, ConditionFactory { diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SelectConstraint.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SelectConstraint.java index 52f39b63..980329fd 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SelectConstraint.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SelectConstraint.java @@ -6,9 +6,9 @@ import org.drools.ansible.rulebook.integration.api.rulesmodel.ParsedCondition; import org.drools.ansible.rulebook.integration.protoextractor.prototype.ExtractorPrototypeExpressionUtils; import org.drools.model.ConstraintOperator; -import org.drools.model.Prototype; -import org.drools.model.PrototypeDSL; -import org.drools.model.PrototypeVariable; +import org.drools.model.prototype.PrototypeDSL; +import org.drools.model.prototype.PrototypeVariable; +import org.kie.api.prototype.Prototype; import java.util.Collection; import java.util.Map; @@ -19,7 +19,7 @@ import static org.drools.ansible.rulebook.integration.api.domain.conditions.ConditionParseUtil.mapToStringValue; import static org.drools.ansible.rulebook.integration.api.domain.conditions.ConditionParseUtil.toJsonValue; import static org.drools.ansible.rulebook.integration.api.domain.constraints.Operators.toOperatorPredicate; -import static org.drools.model.PrototypeExpression.fixedValue; +import static org.drools.model.prototype.PrototypeExpression.fixedValue; public enum SelectConstraint implements RulebookOperator, ConditionFactory { diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/OnceAbstractTimeConstraint.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/OnceAbstractTimeConstraint.java index 66659a99..474de2d3 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/OnceAbstractTimeConstraint.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/OnceAbstractTimeConstraint.java @@ -4,22 +4,19 @@ import org.drools.ansible.rulebook.integration.protoextractor.ExtractorUtils; import org.drools.ansible.rulebook.integration.protoextractor.ast.ExtractorNode; import org.drools.ansible.rulebook.integration.protoextractor.prototype.ExtractorPrototypeExpression; -import org.drools.ansible.rulebook.integration.protoextractor.prototype.ExtractorPrototypeExpressionUtils; -import org.drools.base.facttemplates.Fact; import org.drools.model.Index; -import org.drools.model.PrototypeDSL; -import org.drools.model.PrototypeExpression; -import org.drools.model.PrototypeFact; -import org.drools.model.PrototypeVariable; +import org.drools.model.prototype.PrototypeDSL; +import org.drools.model.prototype.PrototypeExpression; +import org.drools.model.prototype.PrototypeVariable; +import org.kie.api.prototype.PrototypeFactInstance; import java.util.List; import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.SYNTHETIC_PROTOTYPE_NAME; -import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.getPrototype; -import static org.drools.model.PrototypeDSL.protoPattern; -import static org.drools.model.PrototypeDSL.variable; -import static org.drools.model.PrototypeExpression.fixedValue; -import static org.drools.model.PrototypeExpression.prototypeField; +import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.getPrototypeEvent; +import static org.drools.model.prototype.PrototypeDSL.protoPattern; +import static org.drools.model.prototype.PrototypeDSL.variable; +import static org.drools.model.prototype.PrototypeExpression.prototypeField; public abstract class OnceAbstractTimeConstraint implements TimeConstraint { @@ -46,7 +43,7 @@ protected PrototypeVariable getControlVariable() { } protected PrototypeDSL.PrototypePatternDef createControlPattern() { - PrototypeDSL.PrototypePatternDef controlPattern = protoPattern(variable(getPrototype(SYNTHETIC_PROTOTYPE_NAME))); + PrototypeDSL.PrototypePatternDef controlPattern = protoPattern(variable(getPrototypeEvent(SYNTHETIC_PROTOTYPE_NAME))); for (GroupByAttribute unique : groupByAttributes) { controlPattern.expr( prototypeField(unique.getKey()), // intentional, the control fact has the "group by" key string as-is (not structured), so we reference it for the left part Index.ConstraintType.EQUAL, @@ -95,11 +92,7 @@ public PrototypeExpression asPrototypeExpression() { return new ExtractorPrototypeExpression(extractor); } - public Object evalExtractorOnFact(PrototypeFact fact) { - return evalExtractorOnFact((Fact) fact); - } - - public Object evalExtractorOnFact(Fact fact) { + public Object evalExtractorOnFact(PrototypeFactInstance fact) { return ExtractorUtils.getValueFrom(extractor, fact.asMap()); } diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/OnceAfterDefinition.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/OnceAfterDefinition.java index ec2fe7a5..3cc5eaf3 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/OnceAfterDefinition.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/OnceAfterDefinition.java @@ -3,17 +3,17 @@ import org.drools.ansible.rulebook.integration.api.domain.RuleGenerationContext; import org.drools.ansible.rulebook.integration.api.rulesengine.EmptyMatchDecorator; import org.drools.ansible.rulebook.integration.api.rulesengine.RegisterOnlyAgendaFilter; -import org.drools.base.facttemplates.Event; -import org.drools.base.facttemplates.Fact; import org.drools.model.Drools; import org.drools.model.Index; -import org.drools.model.Prototype; -import org.drools.model.PrototypeDSL; -import org.drools.model.PrototypeVariable; import org.drools.model.Rule; import org.drools.model.RuleItemBuilder; import org.drools.model.Variable; +import org.drools.model.prototype.PrototypeDSL; +import org.drools.model.prototype.PrototypeVariable; import org.drools.model.view.ViewItem; +import org.kie.api.prototype.PrototypeEvent; +import org.kie.api.prototype.PrototypeEventInstance; +import org.kie.api.prototype.PrototypeFactInstance; import org.kie.api.runtime.rule.Match; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,7 +29,7 @@ import static org.drools.ansible.rulebook.integration.api.rulesengine.RegisterOnlyAgendaFilter.RULE_TYPE_TAG; import static org.drools.ansible.rulebook.integration.api.rulesengine.RegisterOnlyAgendaFilter.SYNTHETIC_RULE_TAG; import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.SYNTHETIC_PROTOTYPE_NAME; -import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.getPrototype; +import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.getPrototypeEvent; import static org.drools.ansible.rulebook.integration.api.rulesmodel.RulesModelUtil.writeMetaDataOnEvent; import static org.drools.model.DSL.accFunction; import static org.drools.model.DSL.accumulate; @@ -37,9 +37,8 @@ import static org.drools.model.DSL.not; import static org.drools.model.DSL.on; import static org.drools.model.PatternDSL.rule; -import static org.drools.model.PrototypeDSL.protoPattern; -import static org.drools.model.PrototypeDSL.variable; -import static org.drools.modelcompiler.facttemplate.FactFactory.createMapBasedEvent; +import static org.drools.model.prototype.PrototypeDSL.protoPattern; +import static org.drools.model.prototype.PrototypeDSL.variable; /** * Collects and groups events within a time window. The rule fires only once at the end of the time window with a list of @@ -110,7 +109,7 @@ public class OnceAfterDefinition extends OnceAbstractTimeConstraint { public static final String KEYWORD = "once_after"; - private final Prototype controlPrototype = getPrototype(SYNTHETIC_PROTOTYPE_NAME); + private final PrototypeEvent controlPrototype = getPrototypeEvent(SYNTHETIC_PROTOTYPE_NAME); private final PrototypeVariable controlVar1 = variable( controlPrototype, "c1" ); private final PrototypeVariable controlVar2 = variable( controlPrototype, "c2" ); private final Variable resultsVar = declarationOf( List.class, "results" ); @@ -121,23 +120,23 @@ public class OnceAfterDefinition extends OnceAbstractTimeConstraint { private static Match transformOnceAfterMatch(Match match) { EmptyMatchDecorator rewrittenMatch = new EmptyMatchDecorator(match); - Collection results = ((Collection) match.getDeclarationValue("results")); + Collection results = ((Collection) match.getDeclarationValue("results")); if (results.size() == 1) { rewrittenMatch.withBoundObject("m", controlFact2Event(results.iterator().next())); } else { int i = 0; - for (Fact fact : results) { + for (PrototypeFactInstance fact : results) { rewrittenMatch.withBoundObject("m_" + i++, controlFact2Event(fact)); } } return rewrittenMatch; } - private static Object controlFact2Event(Fact fact) { + private static Object controlFact2Event(PrototypeFactInstance fact) { Map ruleEngineMeta = new HashMap(); ruleEngineMeta.put("once_after_time_window", fact.get("once_after_time_window")); ruleEngineMeta.put("events_in_window", fact.get("events_in_window")); - return writeMetaDataOnEvent((Fact) fact.get("event"), ruleEngineMeta); + return writeMetaDataOnEvent((PrototypeFactInstance) fact.get("event"), ruleEngineMeta); } public OnceAfterDefinition(TimeAmount timeAmount, List groupByAttributes) { @@ -193,14 +192,14 @@ public List getControlRules(RuleGenerationContext ruleContext) { guardedPattern, not( createControlPattern() ), on(getPatternVariable()).execute((drools, event) -> { - Event controlEvent = createMapBasedEvent( controlPrototype ); + PrototypeEventInstance controlEvent = controlPrototype.newInstance(); for (GroupByAttribute unique : groupByAttributes) { - controlEvent.set(unique.getKey(), unique.evalExtractorOnFact(event)); + controlEvent.put(unique.getKey(), unique.evalExtractorOnFact(event)); } - controlEvent.set("drools_rule_name", ruleName); - controlEvent.set( "event", event ); - controlEvent.set( "once_after_time_window", timeAmount.toString() ); - controlEvent.set( "events_in_window", 1 ); + controlEvent.put("drools_rule_name", ruleName); + controlEvent.put( "event", event ); + controlEvent.put( "once_after_time_window", timeAmount.toString() ); + controlEvent.put( "events_in_window", 1 ); drools.insert(controlEvent); drools.delete(event); }) @@ -213,13 +212,13 @@ public List getControlRules(RuleGenerationContext ruleContext) { protoPattern(controlVar1).expr( "drools_rule_name", Index.ConstraintType.EQUAL, ruleName ), not( protoPattern(controlVar2).expr( "end_once_after", Index.ConstraintType.EQUAL, ruleName ) ), on(controlVar1).execute((drools, c1) -> { - Event startControlEvent = createMapBasedEvent( controlPrototype ) + PrototypeEventInstance startControlEvent = controlPrototype.newInstance() .withExpiration(timeAmount.getAmount(), timeAmount.getTimeUnit()); - startControlEvent.set( "start_once_after", ruleName ); + startControlEvent.put( "start_once_after", ruleName ); drools.insert(startControlEvent); - Event endControlEvent = createMapBasedEvent( controlPrototype ); - endControlEvent.set( "end_once_after", ruleName ); + PrototypeEventInstance endControlEvent = controlPrototype.newInstance(); + endControlEvent.put( "end_once_after", ruleName ); drools.insert(endControlEvent); if (log.isInfoEnabled()) { @@ -235,7 +234,7 @@ public List getControlRules(RuleGenerationContext ruleContext) { guardedPattern, createControlPattern(), on(getPatternVariable(), getControlVariable()).execute((drools, event, control) -> { - control.set( "events_in_window", ((int) control.get("events_in_window")) + 1 ); + control.put( "events_in_window", ((int) control.get("events_in_window")) + 1 ); drools.delete(event); }) ) diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/OnceWithinDefinition.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/OnceWithinDefinition.java index aff4bb26..ef40bba6 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/OnceWithinDefinition.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/OnceWithinDefinition.java @@ -1,15 +1,15 @@ package org.drools.ansible.rulebook.integration.api.domain.temporal; import org.drools.ansible.rulebook.integration.api.domain.RuleGenerationContext; -import org.drools.base.facttemplates.Event; -import org.drools.base.facttemplates.Fact; import org.drools.model.Drools; import org.drools.model.DroolsEntryPoint; -import org.drools.model.PrototypeDSL; import org.drools.model.Rule; import org.drools.model.Variable; +import org.drools.model.prototype.PrototypeDSL; import org.drools.model.view.CombinedExprViewItem; import org.drools.model.view.ViewItem; +import org.kie.api.prototype.PrototypeEventInstance; +import org.kie.api.prototype.PrototypeFactInstance; import java.util.Collections; import java.util.HashMap; @@ -20,12 +20,11 @@ import static org.drools.ansible.rulebook.integration.api.domain.temporal.TimeAmount.parseTimeAmount; import static org.drools.ansible.rulebook.integration.api.rulesengine.RegisterOnlyAgendaFilter.SYNTHETIC_RULE_TAG; import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.SYNTHETIC_PROTOTYPE_NAME; -import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.getPrototype; +import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.getPrototypeEvent; import static org.drools.ansible.rulebook.integration.api.rulesmodel.RulesModelUtil.writeMetaDataOnEvent; import static org.drools.model.DSL.not; import static org.drools.model.DSL.on; import static org.drools.model.PatternDSL.rule; -import static org.drools.modelcompiler.facttemplate.FactFactory.createMapBasedEvent; /** * Coalesce events within a time window: if the same event is sent multiple times only one of them in a given time window @@ -86,13 +85,13 @@ public Variable[] getTimeConstraintConsequenceVariables() { @Override public void executeTimeConstraintConsequence(Drools drools, Object... facts) { - Event controlEvent = createMapBasedEvent( getPrototype(SYNTHETIC_PROTOTYPE_NAME) ) + PrototypeEventInstance controlEvent = getPrototypeEvent(SYNTHETIC_PROTOTYPE_NAME).newInstance() .withExpiration(timeAmount.getAmount(), timeAmount.getTimeUnit()); - Fact fact = (Fact) facts[0]; + PrototypeFactInstance fact = (PrototypeFactInstance) facts[0]; for (GroupByAttribute unique : groupByAttributes) { - controlEvent.set(unique.getKey(), unique.evalExtractorOnFact(fact)); + controlEvent.put(unique.getKey(), unique.evalExtractorOnFact(fact)); } - controlEvent.set("drools_rule_name", ruleName); + controlEvent.put("drools_rule_name", ruleName); drools.insert(controlEvent); drools.delete(fact); diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/TimeWindowDefinition.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/TimeWindowDefinition.java index 0a7557aa..17c8dfcc 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/TimeWindowDefinition.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/TimeWindowDefinition.java @@ -1,12 +1,12 @@ package org.drools.ansible.rulebook.integration.api.domain.temporal; +import org.drools.model.prototype.PrototypeDSL; +import org.drools.model.prototype.PrototypeVariable; +import org.drools.model.view.ViewItem; + import java.util.ArrayList; import java.util.List; -import org.drools.model.PrototypeDSL; -import org.drools.model.PrototypeVariable; -import org.drools.model.view.ViewItem; - import static org.drools.ansible.rulebook.integration.api.domain.temporal.TimeAmount.parseTimeAmount; import static org.drools.model.DSL.after; diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/TimedOutDefinition.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/TimedOutDefinition.java index 0ba688f8..54c456e3 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/TimedOutDefinition.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/domain/temporal/TimedOutDefinition.java @@ -4,16 +4,16 @@ import org.drools.ansible.rulebook.integration.api.rulesengine.EmptyMatchDecorator; import org.drools.ansible.rulebook.integration.api.rulesengine.RegisterOnlyAgendaFilter; import org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory; -import org.drools.base.facttemplates.Event; -import org.drools.base.facttemplates.Fact; import org.drools.model.Drools; import org.drools.model.Index; -import org.drools.model.Prototype; -import org.drools.model.PrototypeVariable; import org.drools.model.Rule; import org.drools.model.RuleItemBuilder; import org.drools.model.Variable; +import org.drools.model.prototype.PrototypeVariable; import org.drools.model.view.ViewItem; +import org.kie.api.prototype.PrototypeEvent; +import org.kie.api.prototype.PrototypeEventInstance; +import org.kie.api.prototype.PrototypeFactInstance; import org.kie.api.runtime.rule.Match; import org.kie.api.runtime.rule.RuleContext; @@ -24,7 +24,7 @@ import static org.drools.ansible.rulebook.integration.api.rulesengine.RegisterOnlyAgendaFilter.RULE_TYPE_TAG; import static org.drools.ansible.rulebook.integration.api.rulesengine.RegisterOnlyAgendaFilter.SYNTHETIC_RULE_TAG; import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.SYNTHETIC_PROTOTYPE_NAME; -import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.getPrototype; +import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.getPrototypeEvent; import static org.drools.model.DSL.accFunction; import static org.drools.model.DSL.accumulate; import static org.drools.model.DSL.after; @@ -33,11 +33,10 @@ import static org.drools.model.DSL.on; import static org.drools.model.PatternDSL.pattern; import static org.drools.model.PatternDSL.rule; -import static org.drools.model.PrototypeDSL.protoPattern; -import static org.drools.model.PrototypeDSL.variable; -import static org.drools.model.PrototypeExpression.prototypeField; -import static org.drools.model.PrototypeExpression.thisPrototype; -import static org.drools.modelcompiler.facttemplate.FactFactory.createMapBasedEvent; +import static org.drools.model.prototype.PrototypeDSL.protoPattern; +import static org.drools.model.prototype.PrototypeDSL.variable; +import static org.drools.model.prototype.PrototypeExpression.prototypeField; +import static org.drools.model.prototype.PrototypeExpression.thisPrototype; /** * Only a subset of the events is matched and a timeout expires before all the conditions are satisfied @@ -160,20 +159,20 @@ public class TimedOutDefinition implements TimeConstraint { private final List patterns = new ArrayList<>(); - private final Prototype controlPrototype = getPrototype(SYNTHETIC_PROTOTYPE_NAME); + private final PrototypeEvent controlPrototype = getPrototypeEvent(SYNTHETIC_PROTOTYPE_NAME); private final PrototypeVariable controlVar1 = variable( controlPrototype, "c1" ); private final PrototypeVariable controlVar2 = variable( controlPrototype, "c2" ); - private final PrototypeVariable eventVar = variable(getPrototype(PrototypeFactory.DEFAULT_PROTOTYPE_NAME), "e"); + private final PrototypeVariable eventVar = variable(getPrototypeEvent(PrototypeFactory.DEFAULT_PROTOTYPE_NAME), "e"); static { RegisterOnlyAgendaFilter.registerMatchTransformer(KEYWORD, TimedOutDefinition::transformTimedOutMatch); } private static Match transformTimedOutMatch(Match match) { - Fact fact = (Fact)match.getObjects().get(0); + PrototypeFactInstance fact = (PrototypeFactInstance)match.getObjects().get(0); Object startEvent = fact.get("event"); - fact.set("event", null); + fact.put("event", null); return new EmptyMatchDecorator(match).withBoundObject(fact.get("binding").toString(), startEvent); } @@ -240,11 +239,11 @@ public List getControlRules(RuleGenerationContext ruleContext) { not( protoPattern(controlVar1) .expr( "rulename", Index.ConstraintType.EQUAL, name ) ), on(patterns.get(i).getFirstVariable()).execute((drools, t1) -> { - Event controlEvent = createMapBasedEvent( controlPrototype ) + PrototypeEventInstance controlEvent = controlPrototype.newInstance() .withExpiration(timeAmount.getAmount(), timeAmount.getTimeUnit()); - controlEvent.set( "rulename", name ); - controlEvent.set( "event", t1 ); - controlEvent.set( "binding", ((RuleContext) drools).getMatch().getDeclarationIds().get(0) ); + controlEvent.put( "rulename", name ); + controlEvent.put( "event", t1 ); + controlEvent.put( "binding", ((RuleContext) drools).getMatch().getDeclarationIds().get(0) ); ((Drools) drools).insert(controlEvent); }) ) @@ -257,11 +256,11 @@ public List getControlRules(RuleGenerationContext ruleContext) { not( protoPattern(controlVar1).expr( "rulename", Index.ConstraintType.EQUAL, startTag ) ), protoPattern(controlVar2).expr( p -> ((String)p.get("rulename")).startsWith(rulePrefix) ), on(controlVar2).execute((drools, firstEvent) -> { - Event controlEvent = createMapBasedEvent( controlPrototype ) + PrototypeEventInstance controlEvent = controlPrototype.newInstance() .withExpiration(timeAmount.getAmount(), timeAmount.getTimeUnit()); - controlEvent.set( "rulename", startTag ); - controlEvent.set( "event", firstEvent.get("event") ); - controlEvent.set( "binding", firstEvent.get("binding") ); + controlEvent.put( "rulename", startTag ); + controlEvent.put( "event", firstEvent.get("event") ); + controlEvent.put( "binding", firstEvent.get("binding") ); drools.insert(controlEvent); }) ) @@ -275,9 +274,9 @@ public List getControlRules(RuleGenerationContext ruleContext) { accFunction(org.drools.core.base.accumulators.CountAccumulateFunction::new).as(resultCount)), pattern(resultCount).expr(count -> count == patterns.size()), on(resultCount).execute((drools, count) -> { - Event controlEvent = createMapBasedEvent( controlPrototype ) + PrototypeEventInstance controlEvent = controlPrototype.newInstance() .withExpiration(timeAmount.getAmount(), timeAmount.getTimeUnit()); - controlEvent.set( "rulename", endTag ); + controlEvent.put( "rulename", endTag ); drools.insert(controlEvent); }) ) diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesengine/AbstractRulesEvaluator.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesengine/AbstractRulesEvaluator.java index 9e29cc03..576fef1f 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesengine/AbstractRulesEvaluator.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesengine/AbstractRulesEvaluator.java @@ -5,8 +5,8 @@ import org.drools.ansible.rulebook.integration.api.io.JsonMapper; import org.drools.ansible.rulebook.integration.api.io.Response; import org.drools.ansible.rulebook.integration.api.io.RuleExecutorChannel; -import org.drools.base.facttemplates.Fact; import org.drools.core.common.InternalFactHandle; +import org.kie.api.prototype.PrototypeFactInstance; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.Match; import org.slf4j.Logger; @@ -132,7 +132,7 @@ private List retractMatchingFacts(Map json, boolean allow () -> rulesExecutorSession.deleteAllMatchingFacts(json, allowPartialMatch, keysToExclude), (fhs, matches) -> { for (int i = 0; i < matches.size(); i++) { - Map jsonFact = ((Fact) fhs.get(matches.size() == fhs.size() ? i : 0).getObject()).asMap(); + Map jsonFact = ((PrototypeFactInstance) fhs.get(matches.size() == fhs.size() ? i : 0).getObject()).asMap(); matches.set(i, enrichMatchWithFact(matches.get(i), jsonFact)); } }); @@ -171,7 +171,7 @@ protected List process(Map factMap, boolean processEventI if (log.isDebugEnabled()) { for (InternalFactHandle fh : fhs) { if (fh.isDisconnected()) { - String factAsString = fhs.size() == 1 ? JsonMapper.toJson(factMap) : JsonMapper.toJson(((Fact)fh.getObject()).asMap()); + String factAsString = fhs.size() == 1 ? JsonMapper.toJson(factMap) : JsonMapper.toJson(((PrototypeFactInstance)fh.getObject()).asMap()); log.debug((processEventInsertion ? "Event " : "Fact ") + factAsString + " didn't match any rule and has been immediately discarded"); } } diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesengine/RulesExecutorSession.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesengine/RulesExecutorSession.java index 37497b00..ad39479e 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesengine/RulesExecutorSession.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesengine/RulesExecutorSession.java @@ -2,8 +2,8 @@ import org.drools.ansible.rulebook.integration.api.domain.RulesSet; import org.drools.core.common.InternalFactHandle; -import org.drools.base.facttemplates.Event; -import org.drools.base.facttemplates.Fact; +import org.kie.api.prototype.PrototypeEventInstance; +import org.kie.api.prototype.PrototypeFactInstance; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.ObjectFilter; import org.kie.api.runtime.rule.AgendaFilter; @@ -11,7 +11,12 @@ import org.kie.api.runtime.rule.Match; import org.kie.api.time.SessionPseudoClock; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.function.BiPredicate; import java.util.stream.Collectors; @@ -62,9 +67,9 @@ Collection getObjects(ObjectFilter filter) { } InternalFactHandle insert(Map factMap, boolean event) { - Fact fact = mapToFact(factMap, event); + PrototypeFactInstance fact = mapToFact(factMap, event); if (event) { - ((Event) fact).withExpiration(rulesSet.getEventsTtl().getAmount(), rulesSet.getEventsTtl().getTimeUnit()); + ((PrototypeEventInstance) fact).withExpiration(rulesSet.getEventsTtl().getAmount(), rulesSet.getEventsTtl().getTimeUnit()); } InternalFactHandle fh = (InternalFactHandle) kieSession.insert(fact); if (event) { @@ -82,7 +87,7 @@ List deleteAllMatchingFacts(Map toBeRetracte (wmFact, retract) -> wmFact.entrySet().containsAll(retract.entrySet()) : (wmFact, retract) -> areFactsEqual(wmFact, retract, keysToExclude); - Collection fhs = kieSession.getFactHandles(o -> o instanceof Fact && factsComparator.test( ((Fact) o).asMap(), toBeRetracted ) ); + Collection fhs = kieSession.getFactHandles(o -> o instanceof PrototypeFactInstance && factsComparator.test( ((PrototypeFactInstance) o).asMap(), toBeRetracted ) ); return new ArrayList<>( fhs ).stream().peek( kieSession::delete ).map( InternalFactHandle.class::cast ).collect(Collectors.toList()); } diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesengine/SessionStats.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesengine/SessionStats.java index 9dcbd397..cd37aeaf 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesengine/SessionStats.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesengine/SessionStats.java @@ -1,7 +1,7 @@ package org.drools.ansible.rulebook.integration.api.rulesengine; import com.fasterxml.jackson.annotation.JsonInclude; -import org.drools.base.facttemplates.Fact; +import org.kie.api.prototype.PrototypeFactInstance; import java.time.Instant; import java.util.Collection; @@ -49,9 +49,9 @@ public SessionStats(SessionStatsCollector stats, RulesExecutorSession session, b this.eventsMatched = stats.getMatchedEvents(); this.eventsSuppressed = this.eventsProcessed - this.eventsMatched; - Collection facts = (Collection) session.getObjects(Fact.class::isInstance); + Collection facts = (Collection) session.getObjects(PrototypeFactInstance.class::isInstance); this.permanentStorageCount = facts.size(); - Stream factStream = permanentStorageCount > Runtime.getRuntime().availableProcessors() * 2 ? facts.parallelStream() : facts.stream(); + Stream factStream = permanentStorageCount > Runtime.getRuntime().availableProcessors() * 2 ? facts.parallelStream() : facts.stream(); this.permanentStorageSize = factStream.mapToInt(f -> f.asMap().toString().getBytes().length).sum(); this.asyncResponses = stats.getAsyncResponses(); diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/BetaParsedCondition.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/BetaParsedCondition.java index f328c914..2cb5011e 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/BetaParsedCondition.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/BetaParsedCondition.java @@ -1,9 +1,9 @@ package org.drools.ansible.rulebook.integration.api.rulesmodel; import org.drools.model.ConstraintOperator; -import org.drools.model.PrototypeDSL; -import org.drools.model.PrototypeExpression; -import org.drools.model.PrototypeVariable; +import org.drools.model.prototype.PrototypeDSL; +import org.drools.model.prototype.PrototypeExpression; +import org.drools.model.prototype.PrototypeVariable; import org.drools.model.view.ViewItem; import org.drools.ansible.rulebook.integration.api.domain.RuleGenerationContext; diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/ParsedCondition.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/ParsedCondition.java index 104fbdbe..75c9c9b7 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/ParsedCondition.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/ParsedCondition.java @@ -4,13 +4,12 @@ import org.drools.ansible.rulebook.integration.api.domain.constraints.NegationOperator; import org.drools.ansible.rulebook.integration.protoextractor.prototype.ExtractorPrototypeExpressionUtils; import org.drools.model.ConstraintOperator; -import org.drools.model.PrototypeDSL; -import org.drools.model.PrototypeExpression; +import org.drools.model.prototype.PrototypeDSL; +import org.drools.model.prototype.PrototypeExpression; import org.drools.model.view.ViewItem; import static org.drools.model.DSL.not; -import static org.drools.model.PrototypeExpression.fixedValue; -import static org.drools.model.PrototypeExpression.prototypeField; +import static org.drools.model.prototype.PrototypeExpression.fixedValue; public class ParsedCondition { diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/PrototypeFactory.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/PrototypeFactory.java index 0e2fc5a3..707bd30a 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/PrototypeFactory.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/PrototypeFactory.java @@ -1,11 +1,12 @@ package org.drools.ansible.rulebook.integration.api.rulesmodel; +import org.drools.model.prototype.PrototypeDSL; +import org.kie.api.prototype.PrototypeEvent; +import org.kie.api.prototype.PrototypeFact; + import java.util.HashMap; import java.util.Map; -import org.drools.model.Prototype; -import org.drools.model.PrototypeDSL; - public class PrototypeFactory { public static final String DEFAULT_PROTOTYPE_NAME = "DROOLS_PROTOTYPE"; @@ -13,9 +14,14 @@ public class PrototypeFactory { private PrototypeFactory() { } - private static final Map prototypes = new HashMap<>(); + private static final Map prototypeFacts = new HashMap<>(); + private static final Map prototypeEvents = new HashMap<>(); + + public static PrototypeFact getPrototypeFact(String name) { + return prototypeFacts.computeIfAbsent(name, PrototypeDSL::prototypeFact); + } - public static Prototype getPrototype(String name) { - return prototypes.computeIfAbsent(name, PrototypeDSL::prototype); + public static PrototypeEvent getPrototypeEvent(String name) { + return prototypeEvents.computeIfAbsent(name, PrototypeDSL::prototypeEvent); } } diff --git a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/RulesModelUtil.java b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/RulesModelUtil.java index b89e4fe3..4a2e23fb 100644 --- a/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/RulesModelUtil.java +++ b/drools-ansible-rulebook-integration-api/src/main/java/org/drools/ansible/rulebook/integration/api/rulesmodel/RulesModelUtil.java @@ -1,15 +1,14 @@ package org.drools.ansible.rulebook.integration.api.rulesmodel; import org.drools.ansible.rulebook.integration.api.io.JsonMapper; -import org.drools.base.facttemplates.Fact; +import org.kie.api.prototype.PrototypeFactInstance; import java.util.HashMap; import java.util.Map; import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.DEFAULT_PROTOTYPE_NAME; -import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.getPrototype; -import static org.drools.modelcompiler.facttemplate.FactFactory.createMapBasedEvent; -import static org.drools.modelcompiler.facttemplate.FactFactory.createMapBasedFact; +import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.getPrototypeEvent; +import static org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory.getPrototypeFact; public class RulesModelUtil { public static final String META_FIELD = "meta"; @@ -17,14 +16,15 @@ public class RulesModelUtil { private RulesModelUtil() { } - public static Fact mapToFact(Map factMap, boolean event) { - Fact fact = event ? createMapBasedEvent( getPrototype(DEFAULT_PROTOTYPE_NAME), factMap ) : createMapBasedFact( getPrototype(DEFAULT_PROTOTYPE_NAME), factMap ); + public static PrototypeFactInstance mapToFact(Map factMap, boolean event) { + PrototypeFactInstance fact = event ? getPrototypeEvent(DEFAULT_PROTOTYPE_NAME).newInstance() : getPrototypeFact(DEFAULT_PROTOTYPE_NAME).newInstance(); + factMap.forEach(fact::put); return fact; } public static Object factToMap(Object fact) { - if (fact instanceof Fact) { - return ((Fact) fact).asMap(); + if (fact instanceof PrototypeFactInstance) { + return ((PrototypeFactInstance) fact).asMap(); } return fact; } @@ -33,8 +33,8 @@ public static Map asFactMap(String json) { return JsonMapper.readValueAsMapOfStringAndObject(json); } - public static Fact writeMetaDataOnEvent(Fact event, Map ruleEngineMeta) { - Map map = (Map) event.asMap(); + public static PrototypeFactInstance writeMetaDataOnEvent(PrototypeFactInstance event, Map ruleEngineMeta) { + Map map = event.asMap(); Map meta = (Map) map.computeIfAbsent(META_FIELD, x -> new HashMap<>()); meta.put(RULE_ENGINE_META_FIELD, ruleEngineMeta); return event; diff --git a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/AdditionTest.java b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/AdditionTest.java index fb03d574..637a5772 100644 --- a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/AdditionTest.java +++ b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/AdditionTest.java @@ -1,14 +1,14 @@ package org.drools.ansible.rulebook.integration.api; -import java.util.List; - import org.drools.ansible.rulebook.integration.api.domain.RulesSet; import org.drools.ansible.rulebook.integration.protoextractor.prototype.ExtractorPrototypeExpressionUtils; import org.drools.model.Index; import org.junit.Test; import org.kie.api.runtime.rule.Match; -import static org.drools.model.PrototypeExpression.fixedValue; +import java.util.List; + +import static org.drools.model.prototype.PrototypeExpression.fixedValue; import static org.junit.Assert.assertEquals; public class AdditionTest { diff --git a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/AlphaTest.java b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/AlphaTest.java index 20d959c8..89aa633a 100644 --- a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/AlphaTest.java +++ b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/AlphaTest.java @@ -2,8 +2,7 @@ import org.drools.ansible.rulebook.integration.api.rulesmodel.PrototypeFactory; import org.drools.base.definitions.InternalKnowledgePackage; -import org.drools.base.facttemplates.FactTemplate; -import org.drools.base.facttemplates.FactTemplateObjectType; +import org.drools.base.prototype.PrototypeObjectType; import org.drools.base.rule.IndexableConstraint; import org.drools.base.util.index.ConstraintTypeOperator; import org.drools.core.reteoo.AlphaNode; @@ -12,10 +11,9 @@ import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.Rete; import org.drools.kiesession.rulebase.InternalKnowledgeBase; -import org.drools.model.Prototype; -import org.drools.modelcompiler.facttemplate.FactFactory; import org.junit.Test; import org.kie.api.definition.rule.Rule; +import org.kie.api.prototype.PrototypeFact; import org.kie.api.runtime.rule.Match; import java.util.List; @@ -77,10 +75,9 @@ private void assertConstraintType(Rete rete, String ruleName, ConstraintTypeOper boolean asserted = false; assertEquals("expecting only 1 pkg.", 1, rete.getRuleBase().getPackages().length); InternalKnowledgePackage ipkg = rete.getRuleBase().getPackages()[0]; - Prototype default_proto = PrototypeFactory.getPrototype(PrototypeFactory.DEFAULT_PROTOTYPE_NAME); - FactTemplate factTemplate = FactFactory.prototypeToFactTemplate(default_proto, ipkg); + PrototypeFact default_proto = PrototypeFactory.getPrototypeFact(PrototypeFactory.DEFAULT_PROTOTYPE_NAME); EntryPointNode epn = rete.getEntryPointNodes().values().iterator().next(); - ObjectTypeNode otn = epn.getObjectTypeNodes().get(new FactTemplateObjectType(factTemplate)); + ObjectTypeNode otn = epn.getObjectTypeNodes().get(new PrototypeObjectType(default_proto)); ObjectSink[] sinks = otn.getObjectSinkPropagator().getSinks(); for (ObjectSink objectSink : sinks) { AlphaNode alphaNode = (AlphaNode) objectSink; diff --git a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/LogicalOperatorsTest.java b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/LogicalOperatorsTest.java index eef65e45..b2689b12 100644 --- a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/LogicalOperatorsTest.java +++ b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/LogicalOperatorsTest.java @@ -1,8 +1,5 @@ package org.drools.ansible.rulebook.integration.api; -import java.util.List; -import java.util.Map; - import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -10,12 +7,15 @@ import org.drools.ansible.rulebook.integration.api.domain.RulesSet; import org.drools.ansible.rulebook.integration.protoextractor.prototype.ExtractorPrototypeExpressionUtils; import org.drools.model.Index; -import org.drools.model.PrototypeFact; import org.junit.Test; +import org.kie.api.prototype.PrototypeFactInstance; import org.kie.api.runtime.rule.Match; +import java.util.List; +import java.util.Map; + import static org.drools.ansible.rulebook.integration.api.ObjectMapperFactory.createMapper; -import static org.drools.model.PrototypeExpression.fixedValue; +import static org.drools.model.prototype.PrototypeExpression.fixedValue; import static org.junit.Assert.assertEquals; public class LogicalOperatorsTest { @@ -347,7 +347,7 @@ public void testNegate() { Match match = matchedRules.get(0); assertEquals( "r1", match.getRule().getName() ); - assertEquals( 2, ((PrototypeFact)match.getDeclarationValue("m")).get("i") ); + assertEquals( 2, ((PrototypeFactInstance)match.getDeclarationValue("m")).get("i") ); matchedRules = rulesExecutor.processFacts( "{ \"i\":14 }" ).join(); assertEquals( 1, matchedRules.size() ); diff --git a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/OnceAfterTest.java b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/OnceAfterTest.java index 9c6e8ba4..61b7487c 100644 --- a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/OnceAfterTest.java +++ b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/OnceAfterTest.java @@ -4,8 +4,8 @@ import org.drools.ansible.rulebook.integration.api.rulesmodel.RulesModelUtil; import org.drools.ansible.rulebook.integration.protoextractor.ExtractorParser; import org.drools.ansible.rulebook.integration.protoextractor.ExtractorUtils; -import org.drools.base.facttemplates.Fact; import org.junit.Test; +import org.kie.api.prototype.PrototypeFactInstance; import org.kie.api.runtime.rule.Match; import java.util.List; @@ -100,7 +100,7 @@ public void testOnceAfterWithOr() { assertEquals("r1", matchedRules.get(0).getRule().getName()); for (int i = 0; i < 3; i++) { - Fact fact = (Fact) matchedRules.get(0).getDeclarationValue("m_" + i); + PrototypeFactInstance fact = (PrototypeFactInstance) matchedRules.get(0).getDeclarationValue("m_" + i); String host = evalAgainstFact(fact, "meta.hosts").toString(); assertTrue( host.equals( "h1" ) || host.equals( "h2" ) ); String level = evalAgainstFact(fact, "alert.level").toString(); @@ -120,7 +120,7 @@ public void testOnceAfterWithOr() { assertEquals(1, matchedRules.size()); assertEquals("r1", matchedRules.get(0).getRule().getName()); - Fact fact = (Fact) matchedRules.get(0).getDeclarationValue("m"); + PrototypeFactInstance fact = (PrototypeFactInstance) matchedRules.get(0).getDeclarationValue("m"); String host = evalAgainstFact(fact, "meta.hosts").toString(); assertTrue(host.equals("h1")); String level = evalAgainstFact(fact, "alert.level").toString(); @@ -135,7 +135,7 @@ public void testOnceAfterWithOr() { rulesExecutor.dispose(); } - private static Object evalAgainstFact(Fact fact, String expr) { + private static Object evalAgainstFact(PrototypeFactInstance fact, String expr) { return ExtractorUtils.getValueFrom(ExtractorParser.parse(expr), fact.asMap()); } diff --git a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/OnceWithinTest.java b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/OnceWithinTest.java index 1549a860..ff7482e0 100644 --- a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/OnceWithinTest.java +++ b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/OnceWithinTest.java @@ -2,8 +2,8 @@ import org.drools.ansible.rulebook.integration.api.domain.temporal.TimeAmount; import org.drools.ansible.rulebook.integration.api.rulesmodel.RulesModelUtil; -import org.drools.base.facttemplates.Fact; import org.junit.Test; +import org.kie.api.prototype.PrototypeFactInstance; import org.kie.api.runtime.rule.Match; import java.util.List; @@ -125,7 +125,7 @@ private void onceWithinTest(String json) { List matchedRules = rulesExecutor.processEvents("{ \"sensu\": { \"process\": { \"type\":\"alert\" }, \"host\":\"h1\" } }").join(); assertEquals(1, matchedRules.size()); - Fact fact = (Fact) matchedRules.get(0).getDeclarationValue("singleton"); + PrototypeFactInstance fact = (PrototypeFactInstance) matchedRules.get(0).getDeclarationValue("singleton"); Map map = (Map) fact.asMap(); Map ruleEngineMeta = (Map) ((Map)map.get(RulesModelUtil.META_FIELD)).get(RulesModelUtil.RULE_ENGINE_META_FIELD); assertEquals( new TimeAmount(10, TimeUnit.SECONDS).toString(), ruleEngineMeta.get("once_within_time_window") ); diff --git a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/ProcessEventTest.java b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/ProcessEventTest.java index c8fde021..5a8fcca6 100644 --- a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/ProcessEventTest.java +++ b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/ProcessEventTest.java @@ -5,8 +5,8 @@ import java.util.stream.Collectors; import org.drools.base.reteoo.InitialFactImpl; -import org.drools.model.PrototypeFact; import org.junit.Test; +import org.kie.api.prototype.PrototypeFactInstance; import org.kie.api.runtime.rule.Match; import static org.junit.Assert.assertEquals; @@ -121,7 +121,7 @@ public void testEventShouldProduceMultipleMatchesForSameRule() { List hosts = matchedRules.stream() .flatMap( m -> m.getObjects().stream() ) - .map( PrototypeFact.class::cast) + .map( PrototypeFactInstance.class::cast) .filter( p -> p.has("host") ) .map( p -> p.get("host") ) .map( String.class::cast) diff --git a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/TimedOutTest.java b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/TimedOutTest.java index 9132550d..5e9e0307 100644 --- a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/TimedOutTest.java +++ b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/TimedOutTest.java @@ -3,8 +3,8 @@ import org.drools.ansible.rulebook.integration.api.domain.RulesSet; import org.drools.ansible.rulebook.integration.api.io.JsonMapper; import org.drools.ansible.rulebook.integration.api.rulesengine.SessionStats; -import org.drools.base.facttemplates.Fact; import org.junit.Test; +import org.kie.api.prototype.PrototypeFactInstance; import org.kie.api.runtime.rule.Match; import java.io.DataInputStream; @@ -180,7 +180,7 @@ public void testSimpleTimedOut() { assertEquals("r1", match.getRule().getName()); assertEquals( 1, match.getDeclarationIds().size() ); assertEquals( "m_1", match.getDeclarationIds().get(0) ); - assertEquals( 1, ((Fact) match.getDeclarationValue("m_1")).get("j") ); + assertEquals( 1, ((PrototypeFactInstance) match.getDeclarationValue("m_1")).get("j") ); SessionStats stats = rulesExecutor.dispose(); assertEquals(1, stats.getNumberOfRules()); diff --git a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SelectConstraintTest.java b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SelectConstraintTest.java index 89a7fd94..7c8a6810 100644 --- a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SelectConstraintTest.java +++ b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/domain/constraints/SelectConstraintTest.java @@ -16,17 +16,17 @@ package org.drools.ansible.rulebook.integration.api.domain.constraints; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.function.BiPredicate; - import org.drools.ansible.rulebook.integration.api.domain.RuleGenerationContext; import org.drools.ansible.rulebook.integration.api.rulesmodel.ParsedCondition; import org.drools.ansible.rulebook.integration.protoextractor.prototype.ExtractorPrototypeExpression; -import org.drools.model.PrototypeExpression; +import org.drools.model.prototype.PrototypeExpression; import org.junit.Test; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.function.BiPredicate; + import static org.assertj.core.api.Assertions.assertThat; import static org.drools.ansible.rulebook.integration.api.utils.TestUtils.createEventField; import static org.drools.ansible.rulebook.integration.api.utils.TestUtils.createLhsRhsMap; diff --git a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternAdditionTest.java b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternAdditionTest.java index 4c72cea8..2894b71e 100644 --- a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternAdditionTest.java +++ b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternAdditionTest.java @@ -16,14 +16,14 @@ package org.drools.ansible.rulebook.integration.api.toexecmodel; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - import org.drools.ansible.rulebook.integration.api.domain.conditions.MapCondition; -import org.drools.base.facttemplates.Event; import org.drools.model.functions.Predicate1; import org.junit.Test; +import org.kie.api.prototype.PrototypeEventInstance; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; import static org.drools.ansible.rulebook.integration.api.utils.TestUtils.createEventField; @@ -45,13 +45,13 @@ public void additionExpression() throws Exception { Map nestedFactMap1 = new HashMap<>(); nestedFactMap1.put("i", 1); nestedFactMap1.put("j", 2); - Event event1 = createNestedEvent(nestedFactMap1); + PrototypeEventInstance event1 = createNestedEvent(nestedFactMap1); assertThat(predicate.test(event1)).isFalse(); Map nestedFactMap2 = new HashMap<>(); nestedFactMap2.put("i", 2); nestedFactMap2.put("j", 1); - Event event2 = createNestedEvent(nestedFactMap2); + PrototypeEventInstance event2 = createNestedEvent(nestedFactMap2); assertThat(predicate.test(event2)).isTrue(); } } diff --git a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternLogicalOperatorsTest.java b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternLogicalOperatorsTest.java index f02eef41..563c31b6 100644 --- a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternLogicalOperatorsTest.java +++ b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternLogicalOperatorsTest.java @@ -16,14 +16,14 @@ package org.drools.ansible.rulebook.integration.api.toexecmodel; -import java.util.LinkedHashMap; - import org.drools.ansible.rulebook.integration.api.domain.conditions.MapCondition; -import org.drools.base.facttemplates.Event; import org.drools.model.Constraint; import org.drools.model.constraints.OrConstraints; import org.drools.model.functions.Predicate1; import org.junit.Test; +import org.kie.api.prototype.PrototypeEventInstance; + +import java.util.LinkedHashMap; import static org.assertj.core.api.Assertions.assertThat; import static org.drools.ansible.rulebook.integration.api.utils.TestUtils.createEventField; @@ -47,13 +47,13 @@ public void andExpression() throws Exception { // toPattern and extract its predicate Predicate1.Impl predicate = toPatternAndGetFirstPredicate(mapCondition); - Event event1 = createIJEvent(1, 1); + PrototypeEventInstance event1 = createIJEvent(1, 1); assertThat(predicate.test(event1)).isFalse(); - Event event2 = createIJEvent(1, 2); + PrototypeEventInstance event2 = createIJEvent(1, 2); assertThat(predicate.test(event2)).isFalse(); - Event event3 = createIJEvent(2, 2); + PrototypeEventInstance event3 = createIJEvent(2, 2); assertThat(predicate.test(event3)).isTrue(); } @@ -77,15 +77,15 @@ public void orExpression() throws Exception { Predicate1.Impl firstPredicate = extractFirstPredicate((OrConstraints) constraint); Predicate1.Impl secondPredicate = extractSecondPredicate((OrConstraints) constraint); - Event event1 = createIJEvent(1, 1); + PrototypeEventInstance event1 = createIJEvent(1, 1); assertThat(firstPredicate.test(event1)).isFalse(); assertThat(secondPredicate.test(event1)).isFalse(); - Event event2 = createIJEvent(1, 2); + PrototypeEventInstance event2 = createIJEvent(1, 2); assertThat(firstPredicate.test(event2)).isFalse(); assertThat(secondPredicate.test(event2)).isTrue(); - Event event3 = createIJEvent(2, 2); + PrototypeEventInstance event3 = createIJEvent(2, 2); assertThat(firstPredicate.test(event3)).isTrue(); assertThat(secondPredicate.test(event3)).isTrue(); } diff --git a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternRelationalOperatorsTest.java b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternRelationalOperatorsTest.java index f9444dbf..e4fe0aaa 100644 --- a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternRelationalOperatorsTest.java +++ b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternRelationalOperatorsTest.java @@ -16,13 +16,13 @@ package org.drools.ansible.rulebook.integration.api.toexecmodel; -import java.math.BigDecimal; -import java.util.LinkedHashMap; - import org.drools.ansible.rulebook.integration.api.domain.conditions.MapCondition; -import org.drools.base.facttemplates.Event; import org.drools.model.functions.Predicate1; import org.junit.Test; +import org.kie.api.prototype.PrototypeEventInstance; + +import java.math.BigDecimal; +import java.util.LinkedHashMap; import static org.assertj.core.api.Assertions.assertThat; import static org.drools.ansible.rulebook.integration.api.utils.TestUtils.createEventField; @@ -42,10 +42,10 @@ public void equalsExpression() throws Exception { // toPattern and extract its predicate Predicate1.Impl predicate = toPatternAndGetFirstPredicate(mapCondition); - Event event1 = createIJEvent(1, 2); + PrototypeEventInstance event1 = createIJEvent(1, 2); assertThat(predicate.test(event1)).isFalse(); - Event event2 = createIJEvent(2, 2); + PrototypeEventInstance event2 = createIJEvent(2, 2); assertThat(predicate.test(event2)).isTrue(); } @@ -61,16 +61,16 @@ public void equalsExpression_BigDecimalDifferentScale() throws Exception { // toPattern and extract its predicate Predicate1.Impl predicate = toPatternAndGetFirstPredicate(mapCondition); - Event event1 = createIEvent(0); + PrototypeEventInstance event1 = createIEvent(0); assertThat(predicate.test(event1)).isFalse(); - Event event2 = createIEvent(1); + PrototypeEventInstance event2 = createIEvent(1); assertThat(predicate.test(event2)).isTrue(); - Event event3 = createIEvent(new BigDecimal("1.0")); + PrototypeEventInstance event3 = createIEvent(new BigDecimal("1.0")); assertThat(predicate.test(event3)).isTrue(); - Event event4 = createIEvent(new BigDecimal("1.00")); // different scale + PrototypeEventInstance event4 = createIEvent(new BigDecimal("1.00")); // different scale assertThat(predicate.test(event4)).isTrue(); } @@ -86,10 +86,10 @@ public void notEqualsExpression() throws Exception { // toPattern and extract its predicate Predicate1.Impl predicate = toPatternAndGetFirstPredicate(mapCondition); - Event event1 = createIJEvent(1, 2); + PrototypeEventInstance event1 = createIJEvent(1, 2); assertThat(predicate.test(event1)).isTrue(); - Event event2 = createIJEvent(2, 2); + PrototypeEventInstance event2 = createIJEvent(2, 2); assertThat(predicate.test(event2)).isFalse(); } @@ -105,13 +105,13 @@ public void greaterThanExpression() throws Exception { // toPattern and extract its predicate Predicate1.Impl predicate = toPatternAndGetFirstPredicate(mapCondition); - Event event1 = createIJEvent(1, 2); + PrototypeEventInstance event1 = createIJEvent(1, 2); assertThat(predicate.test(event1)).isFalse(); - Event event2 = createIJEvent(2, 2); + PrototypeEventInstance event2 = createIJEvent(2, 2); assertThat(predicate.test(event2)).isFalse(); - Event event3 = createIJEvent(2, 1); + PrototypeEventInstance event3 = createIJEvent(2, 1); assertThat(predicate.test(event3)).isTrue(); } @@ -127,13 +127,13 @@ public void greaterThanOrEqualToExpression() throws Exception { // toPattern and extract its predicate Predicate1.Impl predicate = toPatternAndGetFirstPredicate(mapCondition); - Event event1 = createIJEvent(1, 2); + PrototypeEventInstance event1 = createIJEvent(1, 2); assertThat(predicate.test(event1)).isFalse(); - Event event2 = createIJEvent(2, 2); + PrototypeEventInstance event2 = createIJEvent(2, 2); assertThat(predicate.test(event2)).isTrue(); - Event event3 = createIJEvent(2, 1); + PrototypeEventInstance event3 = createIJEvent(2, 1); assertThat(predicate.test(event3)).isTrue(); } @@ -149,13 +149,13 @@ public void lessThanExpression() throws Exception { // toPattern and extract its predicate Predicate1.Impl predicate = toPatternAndGetFirstPredicate(mapCondition); - Event event1 = createIJEvent(1, 2); + PrototypeEventInstance event1 = createIJEvent(1, 2); assertThat(predicate.test(event1)).isTrue(); - Event event2 = createIJEvent(2, 2); + PrototypeEventInstance event2 = createIJEvent(2, 2); assertThat(predicate.test(event2)).isFalse(); - Event event3 = createIJEvent(2, 1); + PrototypeEventInstance event3 = createIJEvent(2, 1); assertThat(predicate.test(event3)).isFalse(); } @@ -171,13 +171,13 @@ public void lessThanOrEqualToExpression() throws Exception { // toPattern and extract its predicate Predicate1.Impl predicate = toPatternAndGetFirstPredicate(mapCondition); - Event event1 = createIJEvent(1, 2); + PrototypeEventInstance event1 = createIJEvent(1, 2); assertThat(predicate.test(event1)).isTrue(); - Event event2 = createIJEvent(2, 2); + PrototypeEventInstance event2 = createIJEvent(2, 2); assertThat(predicate.test(event2)).isTrue(); - Event event3 = createIJEvent(2, 1); + PrototypeEventInstance event3 = createIJEvent(2, 1); assertThat(predicate.test(event3)).isFalse(); } } diff --git a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternSelectTest.java b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternSelectTest.java index 81e86e6d..3e92aa94 100644 --- a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternSelectTest.java +++ b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/MapConditionToPatternSelectTest.java @@ -16,16 +16,16 @@ package org.drools.ansible.rulebook.integration.api.toexecmodel; +import org.drools.ansible.rulebook.integration.api.domain.conditions.MapCondition; +import org.drools.model.functions.Predicate1; +import org.junit.Test; +import org.kie.api.prototype.PrototypeEventInstance; + import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; -import org.drools.ansible.rulebook.integration.api.domain.conditions.MapCondition; -import org.drools.base.facttemplates.Event; -import org.drools.model.functions.Predicate1; -import org.junit.Test; - import static org.assertj.core.api.Assertions.assertThat; import static org.drools.ansible.rulebook.integration.api.utils.TestUtils.createEventField; import static org.drools.ansible.rulebook.integration.api.utils.TestUtils.createRhsWithOperatorAndValue; @@ -44,13 +44,13 @@ public void selectExpression() throws Exception { // toPattern and extract its predicate Predicate1.Impl predicate = toPatternAndGetFirstPredicate(mapCondition); - Event event1 = createEvent("levels", 25); + PrototypeEventInstance event1 = createEvent("levels", 25); assertThat(predicate.test(event1)).isFalse(); - Event event2 = createEvent("levels", 26); + PrototypeEventInstance event2 = createEvent("levels", 26); assertThat(predicate.test(event2)).isTrue(); - Event event3 = createEvent("levels", 10, 25, 26); + PrototypeEventInstance event3 = createEvent("levels", 10, 25, 26); assertThat(predicate.test(event3)).isTrue(); } @@ -66,13 +66,13 @@ public void selectNotExpression() throws Exception { // toPattern and extract its predicate Predicate1.Impl predicate = toPatternAndGetFirstPredicate(mapCondition); - Event event1 = createEvent("levels", 25); + PrototypeEventInstance event1 = createEvent("levels", 25); assertThat(predicate.test(event1)).isTrue(); - Event event2 = createEvent("levels", 26, 30); + PrototypeEventInstance event2 = createEvent("levels", 26, 30); assertThat(predicate.test(event2)).isFalse(); - Event event3 = createEvent("levels", 10, 25, 26); + PrototypeEventInstance event3 = createEvent("levels", 10, 25, 26); assertThat(predicate.test(event3)).isTrue(); } @@ -88,10 +88,10 @@ public void selectExpressionWithRegex() throws Exception { // toPattern and extract its predicate Predicate1.Impl predicate = toPatternAndGetFirstPredicate(mapCondition); - Event event1 = createEvent("addresses", "123 Main St, Bedrock, MI", "545 Spring St, Cresskill, NJ", "435 Wall Street, New York, NY"); + PrototypeEventInstance event1 = createEvent("addresses", "123 Main St, Bedrock, MI", "545 Spring St, Cresskill, NJ", "435 Wall Street, New York, NY"); assertThat(predicate.test(event1)).isTrue(); - Event event2 = createEvent("addresses", "545 Spring St, Cresskill, NJ", "435 Wall Street, New York, NY"); + PrototypeEventInstance event2 = createEvent("addresses", "545 Spring St, Cresskill, NJ", "435 Wall Street, New York, NY"); assertThat(predicate.test(event2)).isFalse(); } @@ -110,13 +110,13 @@ public void selectExpressionOnField() throws Exception { Map factMap1 = new HashMap<>(); factMap1.put("my_int1", 3); factMap1.put("my_list1", Arrays.asList(1, 3, 7)); - Event event1 = createEvent(factMap1); + PrototypeEventInstance event1 = createEvent(factMap1); assertThat(predicate.test(event1)).isTrue(); Map factMap2 = new HashMap<>(); factMap2.put("my_int1", 4); factMap2.put("my_list1", Arrays.asList(1, 3, 7)); - Event event2 = createEvent(factMap2); + PrototypeEventInstance event2 = createEvent(factMap2); assertThat(predicate.test(event2)).isFalse(); } } diff --git a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/SimpleConditionToPatternTest.java b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/SimpleConditionToPatternTest.java index 972fc862..ac8ce394 100644 --- a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/SimpleConditionToPatternTest.java +++ b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/SimpleConditionToPatternTest.java @@ -16,13 +16,13 @@ package org.drools.ansible.rulebook.integration.api.toexecmodel; -import java.util.HashMap; -import java.util.Map; - import org.drools.ansible.rulebook.integration.api.domain.conditions.SimpleCondition; -import org.drools.base.facttemplates.Event; import org.drools.model.functions.Predicate1; import org.junit.Test; +import org.kie.api.prototype.PrototypeEventInstance; + +import java.util.HashMap; +import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; @@ -36,15 +36,15 @@ public void simpleConditionLogicalOperator() throws Exception { // toPattern and extract its predicate Predicate1.Impl predicate = toPatternAndGetFirstPredicate(simpleCondition); - Event event1 = createSensuEvent(1); + PrototypeEventInstance event1 = createSensuEvent(1); assertThat(predicate.test(event1)).isTrue(); - Event event2 = createSensuEvent(2); + PrototypeEventInstance event2 = createSensuEvent(2); assertThat(predicate.test(event2)).isFalse(); } // create an Event which has nested field "sensu.data.i" - private Event createSensuEvent(Integer i) { + private PrototypeEventInstance createSensuEvent(Integer i) { Map iMap = new HashMap<>(); iMap.put("i", i); Map dataMap = new HashMap<>(); diff --git a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/ToPatternTestBase.java b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/ToPatternTestBase.java index 969bd40e..268d0c6c 100644 --- a/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/ToPatternTestBase.java +++ b/drools-ansible-rulebook-integration-api/src/test/java/org/drools/ansible/rulebook/integration/api/toexecmodel/ToPatternTestBase.java @@ -16,29 +16,29 @@ package org.drools.ansible.rulebook.integration.api.toexecmodel; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - import org.drools.ansible.rulebook.integration.api.domain.RuleGenerationContext; import org.drools.ansible.rulebook.integration.api.domain.conditions.Condition; import org.drools.ansible.rulebook.integration.api.rulesmodel.RulesModelUtil; -import org.drools.base.facttemplates.Event; import org.drools.model.Constraint; import org.drools.model.PatternDSL; -import org.drools.model.PrototypeDSL; import org.drools.model.constraints.OrConstraints; import org.drools.model.constraints.SingleConstraint1; import org.drools.model.functions.Predicate1; +import org.drools.model.prototype.PrototypeDSL; +import org.kie.api.prototype.PrototypeEventInstance; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; import static org.drools.ansible.rulebook.integration.api.utils.TestUtils.createSingleMap; public class ToPatternTestBase { // Create an Event with single field. Multiple values is converted to a List - protected Event createEvent(String fieldName, Object... fieldValues) { + protected PrototypeEventInstance createEvent(String fieldName, Object... fieldValues) { Object fieldValue; if (fieldValues.length == 1) { fieldValue = fieldValues[0]; @@ -50,27 +50,27 @@ protected Event createEvent(String fieldName, Object... fieldValues) { return createEvent(factMap); } - protected Event createNestedEvent(Map nestedFactMap) { + protected PrototypeEventInstance createNestedEvent(Map nestedFactMap) { Map factMap = new HashMap<>(); factMap.put("nested", nestedFactMap); return createEvent(factMap); } - protected Event createIEvent(Object i) { + protected PrototypeEventInstance createIEvent(Object i) { Map factMap = new HashMap<>(); factMap.put("i", i); return createEvent(factMap); } - protected Event createIJEvent(Object i, Object j) { + protected PrototypeEventInstance createIJEvent(Object i, Object j) { Map factMap = new HashMap<>(); factMap.put("i", i); factMap.put("j", j); return createEvent(factMap); } - protected Event createEvent(Map factMap) { - return (Event) RulesModelUtil.mapToFact(factMap, true); + protected PrototypeEventInstance createEvent(Map factMap) { + return (PrototypeEventInstance) RulesModelUtil.mapToFact(factMap, true); } protected LinkedHashMap createSelectExpression(LinkedHashMap lhsValueMap, LinkedHashMap rhsValueMap) { @@ -154,7 +154,7 @@ protected Constraint toPatternAndGetRootConstraint(Condition condition) { protected Constraint getRootConstraint(PatternDSL.PatternDefImpl pattern) { PatternDSL.CombinedPatternExprItem combinedItem = (PatternDSL.CombinedPatternExprItem) pattern.getItems().get(0); - return combinedItem.asConstraint((PatternDSL.PatternDefImpl) PrototypeDSL.protoPattern(PrototypeDSL.variable(PrototypeDSL.prototype("Fake")))); + return combinedItem.asConstraint((PatternDSL.PatternDefImpl) PrototypeDSL.protoPattern(PrototypeDSL.variable(PrototypeDSL.prototypeFact("Fake")))); } protected Predicate1.Impl extractFirstPredicate(OrConstraints constraint) { diff --git a/drools-ansible-rulebook-integration-benchmark/pom.xml b/drools-ansible-rulebook-integration-benchmark/pom.xml index 60a8ff5a..35bf813f 100644 --- a/drools-ansible-rulebook-integration-benchmark/pom.xml +++ b/drools-ansible-rulebook-integration-benchmark/pom.xml @@ -6,7 +6,7 @@ org.drools drools-ansible-rulebook-integration - 1.0.6-SNAPSHOT + 1.0.7-SNAPSHOT drools-ansible-rulebook-integration-benchmark diff --git a/drools-ansible-rulebook-integration-core-rest/pom.xml b/drools-ansible-rulebook-integration-core-rest/pom.xml index ca33bc18..1fe7d9d6 100644 --- a/drools-ansible-rulebook-integration-core-rest/pom.xml +++ b/drools-ansible-rulebook-integration-core-rest/pom.xml @@ -6,7 +6,7 @@ org.drools drools-ansible-rulebook-integration - 1.0.6-SNAPSHOT + 1.0.7-SNAPSHOT drools-ansible-rulebook-integration-core-rest diff --git a/drools-ansible-rulebook-integration-main/pom.xml b/drools-ansible-rulebook-integration-main/pom.xml index ef215074..afa5b86e 100644 --- a/drools-ansible-rulebook-integration-main/pom.xml +++ b/drools-ansible-rulebook-integration-main/pom.xml @@ -5,7 +5,7 @@ drools-ansible-rulebook-integration org.drools - 1.0.6-SNAPSHOT + 1.0.7-SNAPSHOT 4.0.0 diff --git a/drools-ansible-rulebook-integration-protoextractor/pom.xml b/drools-ansible-rulebook-integration-protoextractor/pom.xml index a60493a7..fe2b46ea 100644 --- a/drools-ansible-rulebook-integration-protoextractor/pom.xml +++ b/drools-ansible-rulebook-integration-protoextractor/pom.xml @@ -5,7 +5,7 @@ drools-ansible-rulebook-integration org.drools - 1.0.6-SNAPSHOT + 1.0.7-SNAPSHOT 4.0.0 @@ -18,6 +18,10 @@ org.drools drools-canonical-model + + org.drools + drools-model-prototype + org.drools drools-core diff --git a/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/CompleteExtractorPrototypeExpression.java b/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/CompleteExtractorPrototypeExpression.java index 7a9e3406..bce1188b 100644 --- a/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/CompleteExtractorPrototypeExpression.java +++ b/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/CompleteExtractorPrototypeExpression.java @@ -1,14 +1,14 @@ package org.drools.ansible.rulebook.integration.protoextractor.prototype; +import org.drools.ansible.rulebook.integration.protoextractor.ast.ExtractorNode; +import org.drools.model.prototype.PrototypeExpression.EvaluableExpression; +import org.drools.model.prototype.PrototypeVariable; +import org.kie.api.prototype.PrototypeFactInstance; + import java.util.Collection; import java.util.Collections; import java.util.Map; -import org.drools.ansible.rulebook.integration.protoextractor.ast.ExtractorNode; -import org.drools.model.PrototypeExpression.EvaluableExpression; -import org.drools.model.PrototypeFact; -import org.drools.model.PrototypeVariable; - public class CompleteExtractorPrototypeExpression extends ExtractorPrototypeExpression implements EvaluableExpression { private final PrototypeVariable protoVar; @@ -32,8 +32,8 @@ public Collection getPrototypeVariables() { } @Override - public Object evaluate(Map factsMap) { - PrototypeFact prototypeFact = factsMap.get(protoVar); + public Object evaluate(Map factsMap) { + PrototypeFactInstance prototypeFact = factsMap.get(protoVar); return asFunction(IGNORED).apply(prototypeFact); } diff --git a/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/ExtractorPrototypeExpression.java b/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/ExtractorPrototypeExpression.java index 7d663e88..39ab748a 100644 --- a/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/ExtractorPrototypeExpression.java +++ b/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/ExtractorPrototypeExpression.java @@ -1,27 +1,27 @@ package org.drools.ansible.rulebook.integration.protoextractor.prototype; +import org.drools.ansible.rulebook.integration.protoextractor.ExtractorUtils; +import org.drools.ansible.rulebook.integration.protoextractor.ast.ExtractorNode; +import org.drools.model.functions.Function1; +import org.drools.model.prototype.PrototypeDSL; +import org.drools.model.prototype.PrototypeExpression; +import org.kie.api.prototype.Prototype; +import org.kie.api.prototype.PrototypeFact; +import org.kie.api.prototype.PrototypeFactInstance; + import java.util.Collection; import java.util.Collections; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; -import org.drools.ansible.rulebook.integration.protoextractor.ExtractorUtils; -import org.drools.ansible.rulebook.integration.protoextractor.ast.ExtractorNode; -import org.drools.base.facttemplates.Fact; -import org.drools.model.Prototype; -import org.drools.model.PrototypeDSL; -import org.drools.model.PrototypeExpression; -import org.drools.model.PrototypeFact; -import org.drools.model.functions.Function1; - public class ExtractorPrototypeExpression implements PrototypeExpression { /** * This is okay for ansible-integration work as prototype do not define accessor programmatically, * but having prototype definition ignored in {@link #asFunction(Prototype)} call, ought to be revised * if porting this module into Drools and generalizing beyond usage in ansible-integration. */ - public static final Prototype IGNORED = PrototypeDSL.prototype("IGNORED"); + public static final PrototypeFact IGNORED = PrototypeDSL.prototypeFact("IGNORED"); protected final ExtractorNode extractorNode; protected final String computedFieldName; protected final Collection computedImpactedFields; @@ -33,9 +33,9 @@ public ExtractorPrototypeExpression(ExtractorNode extractorNode) { } @Override - public Function1 asFunction(Prototype prototype) { + public Function1 asFunction(Prototype prototype) { return pf -> { - Map asMap = ((Fact) pf).asMap(); + Map asMap = pf.asMap(); Object value = ExtractorUtils.getValueFrom(extractorNode, asMap); return value; }; diff --git a/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/ExtractorPrototypeExpressionUtils.java b/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/ExtractorPrototypeExpressionUtils.java index 51aa23f0..b253e545 100644 --- a/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/ExtractorPrototypeExpressionUtils.java +++ b/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/ExtractorPrototypeExpressionUtils.java @@ -2,8 +2,8 @@ import org.drools.ansible.rulebook.integration.protoextractor.ExtractorParser; import org.drools.ansible.rulebook.integration.protoextractor.ast.ExtractorNode; -import org.drools.model.PrototypeExpression; -import org.drools.model.PrototypeVariable; +import org.drools.model.prototype.PrototypeExpression; +import org.drools.model.prototype.PrototypeVariable; public class ExtractorPrototypeExpressionUtils { private ExtractorPrototypeExpressionUtils() { diff --git a/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/ValueExtractionVisitor.java b/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/ValueExtractionVisitor.java index 598e3de5..8a229898 100644 --- a/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/ValueExtractionVisitor.java +++ b/drools-ansible-rulebook-integration-protoextractor/src/main/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/ValueExtractionVisitor.java @@ -1,15 +1,15 @@ package org.drools.ansible.rulebook.integration.protoextractor.prototype; -import java.util.List; -import java.util.Map; - import org.drools.ansible.rulebook.integration.protoextractor.ast.ASTNode; import org.drools.ansible.rulebook.integration.protoextractor.ast.DefaultedVisitor; import org.drools.ansible.rulebook.integration.protoextractor.ast.ExtractorNode; import org.drools.ansible.rulebook.integration.protoextractor.ast.IdentifierNode; import org.drools.ansible.rulebook.integration.protoextractor.ast.IndexAccessorNode; import org.drools.ansible.rulebook.integration.protoextractor.ast.SquaredAccessorNode; -import org.drools.model.Prototype; +import org.kie.api.prototype.Prototype; + +import java.util.List; +import java.util.Map; public class ValueExtractionVisitor extends DefaultedVisitor { private final Object original; diff --git a/drools-ansible-rulebook-integration-protoextractor/src/test/java/org/drools/ansible/rulebook/integration/protoextractor/ExtractorTest.java b/drools-ansible-rulebook-integration-protoextractor/src/test/java/org/drools/ansible/rulebook/integration/protoextractor/ExtractorTest.java index e34078d7..15dfdf2b 100644 --- a/drools-ansible-rulebook-integration-protoextractor/src/test/java/org/drools/ansible/rulebook/integration/protoextractor/ExtractorTest.java +++ b/drools-ansible-rulebook-integration-protoextractor/src/test/java/org/drools/ansible/rulebook/integration/protoextractor/ExtractorTest.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.drools.ansible.rulebook.integration.protoextractor.ast.ExtractorNode; -import org.drools.model.Prototype; import org.junit.Test; +import org.kie.api.prototype.Prototype; import java.nio.file.Files; import java.nio.file.Paths; diff --git a/drools-ansible-rulebook-integration-protoextractor/src/test/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/PrototypeTest.java b/drools-ansible-rulebook-integration-protoextractor/src/test/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/PrototypeTest.java index 2f9a177f..6eb0c098 100644 --- a/drools-ansible-rulebook-integration-protoextractor/src/test/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/PrototypeTest.java +++ b/drools-ansible-rulebook-integration-protoextractor/src/test/java/org/drools/ansible/rulebook/integration/protoextractor/prototype/PrototypeTest.java @@ -1,21 +1,18 @@ package org.drools.ansible.rulebook.integration.protoextractor.prototype; -import static org.assertj.core.api.Assertions.assertThat; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.drools.ansible.rulebook.integration.protoextractor.ExtractorParser; +import org.junit.Test; +import org.kie.api.prototype.PrototypeFactInstance; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; import java.util.Map; -import org.drools.ansible.rulebook.integration.protoextractor.ExtractorParser; -import org.drools.base.facttemplates.Fact; -import org.drools.model.PrototypeDSL; -import org.drools.model.PrototypeFact; -import org.drools.modelcompiler.facttemplate.FactFactory; -import org.junit.Test; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; +import static org.assertj.core.api.Assertions.assertThat; +import static org.kie.api.prototype.PrototypeBuilder.prototype; public class PrototypeTest { @@ -33,14 +30,15 @@ public void testBasic() throws Exception { .contains("abcde/asdfgh"); final String JSON = Files.readString(Paths.get(PrototypeTest.class.getResource("/test1.json").toURI())); - final Map readValue = new ObjectMapper().readValue(JSON, new TypeReference>() {}); - final Fact mapBasedFact = FactFactory.createMapBasedFact(PrototypeDSL.prototype("test"), readValue); + final Map readValue = new ObjectMapper().readValue(JSON, new TypeReference<>() {}); + final PrototypeFactInstance mapBasedFact = prototype("test").asFact().newInstance(); + readValue.forEach(mapBasedFact::put); assertThat(mapBasedFact.get("a")) .as("sanity check on manually built drools Fact") .isNotNull() .isInstanceOf(Map.class); - Object valueExtracted = expr.asFunction(ExtractorPrototypeExpression.IGNORED).apply((PrototypeFact) mapBasedFact); + Object valueExtracted = expr.asFunction(ExtractorPrototypeExpression.IGNORED).apply(mapBasedFact); assertThat(valueExtracted) .as("ExtractorPrototypeExpression used to extract value based on the path expression") .isEqualTo(47); diff --git a/drools-ansible-rulebook-integration-runtime/pom.xml b/drools-ansible-rulebook-integration-runtime/pom.xml index 68efc478..d7d84c48 100644 --- a/drools-ansible-rulebook-integration-runtime/pom.xml +++ b/drools-ansible-rulebook-integration-runtime/pom.xml @@ -6,7 +6,7 @@ org.drools drools-ansible-rulebook-integration - 1.0.6-SNAPSHOT + 1.0.7-SNAPSHOT drools-ansible-rulebook-integration-runtime diff --git a/drools-ansible-rulebook-integration-tests/pom.xml b/drools-ansible-rulebook-integration-tests/pom.xml index 5b6681cb..de685a79 100644 --- a/drools-ansible-rulebook-integration-tests/pom.xml +++ b/drools-ansible-rulebook-integration-tests/pom.xml @@ -5,7 +5,7 @@ drools-ansible-rulebook-integration org.drools - 1.0.6-SNAPSHOT + 1.0.7-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index 0219c7e0..b7dbd59b 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.drools drools-ansible-rulebook-integration - 1.0.6-SNAPSHOT + 1.0.7-SNAPSHOT pom @@ -30,7 +30,7 @@ 17 UTF-8 - 8.43.0.Final + 9.101.0 4.13.0 1.35