Search in sources :

Example 1 with Package

use of org.drools.impact.analysis.model.Package in project drools by kiegroup.

the class ModelToGraphConverter method generateGraphAnalysis.

private GraphAnalysis generateGraphAnalysis(AnalysisModel model) {
    GraphAnalysis graphAnalysis = new GraphAnalysis();
    for (Package pkg : model.getPackages()) {
        List<Rule> rules = pkg.getRules();
        for (Rule rule : rules) {
            graphAnalysis.addNode(new Node(rule));
            LeftHandSide lhs = rule.getLhs();
            List<Pattern> patterns = lhs.getPatterns();
            for (Pattern pattern : patterns) {
                Class<?> patternClass = pattern.getPatternClass();
                Collection<String> reactOnFields = pattern.getReactOnFields();
                if (pattern.isClassReactive()) {
                    // Pattern which cannot analyze reactivity (e.g. Person(blackBoxMethod())) so reacts to all properties
                    graphAnalysis.addClassReactiveRule(patternClass, rule, pattern.isPositive());
                } else if (reactOnFields.isEmpty()) {
                    // Pattern without constraint (e.g. Person()) so doesn't react to properties (only react to  insert/delete)
                    graphAnalysis.addInsertReactiveRule(patternClass, rule, pattern.isPositive());
                } else {
                    for (String field : reactOnFields) {
                        graphAnalysis.addPropertyReactiveRule(patternClass, field, rule, pattern.isPositive());
                    }
                }
            }
        }
    }
    return graphAnalysis;
}
Also used : Pattern(org.drools.impact.analysis.model.left.Pattern) LeftHandSide(org.drools.impact.analysis.model.left.LeftHandSide) Package(org.drools.impact.analysis.model.Package) Rule(org.drools.impact.analysis.model.Rule)

Example 2 with Package

use of org.drools.impact.analysis.model.Package in project drools by kiegroup.

the class ModelToGraphConverter method parseGraphAnalysis.

private void parseGraphAnalysis(AnalysisModel model, GraphAnalysis graphAnalysis) {
    for (Package pkg : model.getPackages()) {
        String pkgName = pkg.getName();
        List<Rule> rules = pkg.getRules();
        for (Rule rule : rules) {
            String ruleName = rule.getName();
            RightHandSide rhs = rule.getRhs();
            List<ConsequenceAction> actions = rhs.getActions();
            for (ConsequenceAction action : actions) {
                switch(action.getType()) {
                    case INSERT:
                        processInsert(graphAnalysis, pkgName, ruleName, (InsertAction) action);
                        break;
                    case DELETE:
                        processDelete(graphAnalysis, pkgName, ruleName, action);
                        break;
                    case MODIFY:
                        processModify(graphAnalysis, pkgName, ruleName, (ModifyAction) action);
                        break;
                }
            }
        }
    }
}
Also used : ConsequenceAction(org.drools.impact.analysis.model.right.ConsequenceAction) Package(org.drools.impact.analysis.model.Package) Rule(org.drools.impact.analysis.model.Rule) RightHandSide(org.drools.impact.analysis.model.right.RightHandSide)

Aggregations

Package (org.drools.impact.analysis.model.Package)2 Rule (org.drools.impact.analysis.model.Rule)2 LeftHandSide (org.drools.impact.analysis.model.left.LeftHandSide)1 Pattern (org.drools.impact.analysis.model.left.Pattern)1 ConsequenceAction (org.drools.impact.analysis.model.right.ConsequenceAction)1 RightHandSide (org.drools.impact.analysis.model.right.RightHandSide)1