use of org.drools.impact.analysis.model.left.MapConstraint in project drools by kiegroup.
the class LhsParser method processMapProperty.
private Constraint processMapProperty(RuleContext context, Constraint constraint, TypedExpression expr) {
MethodCallExpr mce = expr.getExpression().asMethodCallExpr();
Optional<Expression> scope = mce.getScope();
if (scope.isPresent() && scope.get().isMethodCallExpr()) {
MethodCallExpr scopeMce = scope.get().asMethodCallExpr();
String prop = ClassUtils.getter2property(scopeMce.getName().asString());
Optional<Class<?>> origType = expr.getOriginalPatternType();
if (prop != null && origType.isPresent()) {
Method accessor = ClassUtils.getAccessor(origType.get(), prop);
if (accessor != null && Map.class.isAssignableFrom(accessor.getReturnType()) && mce.getName().asString().equals("get")) {
String key = getLiteralString(context, mce.getArgument(0));
if (key != null) {
MapConstraint mapConstraint = new MapConstraint(constraint);
// map name
mapConstraint.setProperty(prop);
mapConstraint.setKey(key);
constraint = mapConstraint;
}
}
}
}
return constraint;
}
use of org.drools.impact.analysis.model.left.MapConstraint in project drools by kiegroup.
the class ModelToGraphConverter method processModify.
private void processModify(GraphAnalysis graphAnalysis, String pkgName, String ruleName, ModifyAction action) {
Node source = graphAnalysis.getNode(fqdn(pkgName, ruleName));
Class<?> modifiedClass = action.getActionClass();
if (!graphAnalysis.isRegisteredClass(modifiedClass)) {
// Not likely happen but not invalid
logger.warn("Not found {} in reactiveMap", modifiedClass);
return;
}
List<ModifiedProperty> modifiedProperties = action.getModifiedProperties();
for (ModifiedProperty modifiedProperty : modifiedProperties) {
String property = modifiedProperty.getProperty();
for (AnalyzedRule reactedRule : graphAnalysis.getRulesReactiveTo(modifiedClass, property)) {
List<Constraint> constraints = reactedRule.getRule().getLhs().getPatterns().stream().filter(pattern -> pattern.getPatternClass() == modifiedClass).flatMap(pattern -> pattern.getConstraints().stream()).filter(constraint -> constraint.getProperty() != null && constraint.getProperty().equals(property)).filter(constraint -> {
if (constraint instanceof MapConstraint) {
return doesAssertSameKey((MapConstraint) constraint, modifiedProperty);
} else {
return true;
}
}).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, modifiedProperty);
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 (reactedRule.getReactivityType() == ReactivityType.NEGATIVE) {
combinedLinkType = combinedLinkType.negate();
}
Node target = graphAnalysis.getNode(fqdn(pkgName, reactedRule.getRule().getName()));
linkNodesIfExpected(source, target, combinedLinkType);
}
}
}
Aggregations