use of org.drools.impact.analysis.model.right.InsertAction in project drools by kiegroup.
the class RhsParser method processInsert.
private InsertAction processInsert(RuleContext context, MethodCallExpr consequenceExpr, MethodCallExpr statement, BlockStmt ruleVariablesBlock) {
Class<?> actionClass = getActionClass(context, consequenceExpr, statement);
InsertAction action = new InsertAction(actionClass);
Expression insertedArgument = statement.getArgument(0);
String insertedId = insertedArgument.toString();
// Process setters
List<MethodCallExpr> insertedExprs = consequenceExpr.findAll(MethodCallExpr.class).stream().filter(m -> m.getScope().map(s -> s.toString().equals(insertedId) || s.toString().equals("(" + insertedId + ")")).orElse(false)).collect(Collectors.toList());
for (MethodCallExpr expr : insertedExprs) {
String methodName = expr.getNameAsString();
String property = ClassUtils.setter2property(methodName);
if (property != null) {
Object value = getLiteralValue(context, expr.getArgument(0));
action.addInsertedProperty(new InsertedProperty(property, value));
}
}
// Process literal insert
if (isLiteral(actionClass) && insertedArgument.isLiteralExpr()) {
action.addInsertedProperty(new InsertedProperty("this", literalToValue(insertedArgument.asLiteralExpr())));
}
return action;
}
use of org.drools.impact.analysis.model.right.InsertAction in project drools by kiegroup.
the class ModelToGraphConverter method processInsert.
private void processInsert(GraphAnalysis graphAnalysis, String pkgName, String ruleName, InsertAction action) {
Node source = graphAnalysis.getNode(fqdn(pkgName, ruleName));
Class<?> insertedClass = action.getActionClass();
if (!graphAnalysis.isRegisteredClass(insertedClass)) {
// Not likely happen but not invalid
logger.warn("Not found {} in reactiveMap", insertedClass);
return;
}
// property based link
List<InsertedProperty> insertedProperties = action.getInsertedProperties();
for (InsertedProperty insertedProperty : insertedProperties) {
String property = insertedProperty.getProperty();
for (AnalyzedRule reactedRule : graphAnalysis.getRulesReactiveTo(insertedClass, property)) {
List<Pattern> patterns = reactedRule.getRule().getLhs().getPatterns().stream().filter(pattern -> pattern.getPatternClass() == insertedClass).collect(Collectors.toList());
for (Pattern pattern : patterns) {
List<Constraint> constraints = pattern.getConstraints().stream().filter(constraint -> constraint.getProperty() != null && constraint.getProperty().equals(property)).collect(Collectors.toList());
ReactivityType combinedLinkType = ReactivityType.UNKNOWN;
if (constraints.isEmpty()) {
// This rule is reactive to the property but cannot find its constraint (e.g. [age > $a] non-literal constraint). It means UNKNOWN impact
combinedLinkType = ReactivityType.UNKNOWN;
} else {
// If constraints contain at least one POSITIVE, we consider it's POSITIVE.
for (Constraint constraint : constraints) {
ReactivityType linkType = linkType(constraint, insertedProperty);
if (linkType == ReactivityType.POSITIVE) {
combinedLinkType = ReactivityType.POSITIVE;
break;
} else if (linkType == ReactivityType.NEGATIVE) {
// NEGATIVE is stronger than UNKNOWN (but may be configurable)
combinedLinkType = ReactivityType.NEGATIVE;
} else if (combinedLinkType == ReactivityType.NEGATIVE && linkType == ReactivityType.UNKNOWN) {
// Don't overwrite with UNKNOWN
} else {
// UNKNOWN
combinedLinkType = linkType;
}
}
}
if (combinedLinkType == ReactivityType.NEGATIVE) {
// TODO: handle "exists" case
continue;
}
if (combinedLinkType == ReactivityType.POSITIVE && !pattern.isPositive()) {
// POSITIVE insert in not() means NEGATIVE
combinedLinkType = combinedLinkType.negate();
}
Node target = graphAnalysis.getNode(fqdn(pkgName, reactedRule.getRule().getName()));
linkNodesIfExpected(source, target, combinedLinkType);
}
}
}
// class based link
for (AnalyzedRule reactedRule : graphAnalysis.getRulesReactiveToWithoutProperty(insertedClass)) {
Node target = graphAnalysis.getNode(fqdn(pkgName, reactedRule.getRule().getName()));
linkNodesIfExpected(source, target, reactedRule.getReactivityType());
}
}
Aggregations