Examples of ReturnValueRestriction


Examples of org.drools.analytics.components.ReturnValueRestriction

   * @param descr
   */
  private void flatten(ReturnValueRestrictionDescr descr) {
    AnalyticsData data = AnalyticsDataFactory.getAnalyticsData();

    ReturnValueRestriction restriction = new ReturnValueRestriction();

    restriction.setRuleId(currentRule.getId());
    restriction.setRuleName(currentRule.getRuleName());
    restriction.setPatternId(currentPattern.getId());
    restriction.setPatternIsNot(currentPattern.isPatternNot());
    restriction.setConstraintId(currentConstraint.getId());
    restriction.setFieldId(currentConstraint.getFieldId());
    restriction.setEvaluator(descr.getEvaluator());
    restriction.setClassMethodName(descr.getClassMethodName());
    restriction.setContent(descr.getContent());
    restriction.setDeclarations(descr.getDeclarations());

    data.save(restriction);
    solvers.addRestriction(restriction);

  }
View Full Code Here

Examples of org.drools.rule.ReturnValueRestriction

        final Declaration[] previousDeclarations = new Declaration[]{a, b};
        final Declaration[] localDeclarations = new Declaration[]{};
        final String[] requiredGlobals = new String[]{};

        final ReturnValueRestriction returnValue = new ReturnValueRestriction( extractor,
                                                                               previousDeclarations,
                                                                               localDeclarations,
                                                                               requiredGlobals,
                                                                               ValueType.PINTEGER_TYPE.getEvaluator( Operator.EQUAL ) );
        builder.build( context,
                       usedIdentifiers,
                       previousDeclarations,
                       localDeclarations,
                       returnValue,
                       returnValueDescr );

        ContextEntry retValContext = returnValue.createContextEntry();

        final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
        final InternalWorkingMemory wm = (InternalWorkingMemory) ruleBase.newStatefulSession();

        final Cheese stilton = new Cheese( "stilton",
                                           10 );

        final Cheese cheddar = new Cheese( "cheddar",
                                           10 );
        final InternalFactHandle f0 = (InternalFactHandle) wm.insert( cheddar );
        ReteTuple tuple = new ReteTuple( f0 );

        final InternalFactHandle f1 = (InternalFactHandle) wm.insert( stilton );
        tuple = new ReteTuple( tuple,
                               f1 );

        final Cheese brie = new Cheese( "brie",
                                        20 );
       
        ContextEntry ctx = returnValue.createContextEntry();
       
        assertTrue( returnValue.isAllowed( extractor,
                                           brie,
                                           tuple,
                                           wm,
                                           ctx) );

        brie.setPrice( 18 );
        assertFalse( returnValue.isAllowed( extractor,
                                            brie,
                                            tuple,
                                            wm,
                                            retValContext ) );
    }
View Full Code Here

Examples of org.drools.rule.ReturnValueRestriction

        final Declaration[] previousDeclarations = new Declaration[]{a, b};
        final Declaration[] localDeclarations = new Declaration[]{};
        final String[] requiredGlobals = new String[]{};

        final ReturnValueRestriction returnValue = new ReturnValueRestriction( extractor,
                                                                               previousDeclarations,
                                                                               localDeclarations,
                                                                               requiredGlobals,
                                                                               context.getConfiguration().getEvaluatorRegistry().getEvaluator( ValueType.PINTEGER_TYPE,
                                                                                                                                               Operator.EQUAL ) );
        AnalysisResult analysis = context.getDialect().analyzeExpression( context,
                                                                          returnValueDescr,
                                                                          returnValueDescr.getContent(),
                                                                          new BoundIdentifiers( declarationResolver.getDeclarationClasses( (Rule) null ), new HashMap(), null, Cheese.class ) );
        context.getBuildStack().push( patternB );
        builder.build( context,
                       analysis.getBoundIdentifiers(),
                       previousDeclarations,
                       localDeclarations,
                       returnValue,
                       returnValueDescr,
                       analysis );
       
        ((MVELReturnValueExpression)returnValue.getExpression()).compile((MVELDialectRuntimeData) pkgBuilder.getPackageRegistry( pkg.getName() ).getDialectRuntimeRegistry().getDialectData( "mvel" ));

        ContextEntry retValContext = returnValue.createContextEntry();

        final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
        final InternalWorkingMemory wm = (InternalWorkingMemory) ruleBase.newStatefulSession();

        final Cheese stilton = new Cheese( "stilton",
                                           10 );

        final Cheese cheddar = new Cheese( "cheddar",
                                           10 );
        final InternalFactHandle f0 = (InternalFactHandle) wm.insert( cheddar );
        LeftTuple tuple = new LeftTuple( f0,
                                         null,
                                         true );

        final InternalFactHandle f1 = (InternalFactHandle) wm.insert( stilton );
        tuple = new LeftTuple( tuple,
                               new RightTuple( f1,
                                               null ),
                               null,
                               true );

        final Cheese brie = new Cheese( "brie",
                                        20 );
        final InternalFactHandle f2 = (InternalFactHandle) wm.insert( brie );

        assertTrue( returnValue.isAllowed( extractor,
                                           f2,
                                           tuple,
                                           wm,
                                           retValContext ) );

        brie.setPrice( 18 );
        wm.update( f2,
                   brie );
        assertFalse( returnValue.isAllowed( extractor,
                                            f2,
                                            tuple,
                                            wm,
                                            retValContext ) );
    }
View Full Code Here

Examples of org.drools.rule.ReturnValueRestriction

            }
        }
       
        AlphaNode alphanode = (AlphaNode) node.getSinkPropagator().getSinks()[0];       
        assertTrue( (( VariableConstraint ) alphanode.getConstraint()).getFieldExtractor() instanceof ClassFieldReader );
        ReturnValueRestriction r = (ReturnValueRestriction) (( VariableConstraint ) alphanode.getConstraint()).getRestriction();
       
        assertTrue( r.getExpression() instanceof ReturnValueExpression );
        assertTrue( r.getExpression() instanceof MVELReturnValueExpression );        
    }        
View Full Code Here

Examples of org.drools.rule.ReturnValueRestriction

            }
        }
       
        AlphaNode alphanode = (AlphaNode) node.getSinkPropagator().getSinks()[0];       
        assertTrue( (( VariableConstraint ) alphanode.getConstraint()).getFieldExtractor() instanceof MVELClassFieldReader );
        ReturnValueRestriction r = (ReturnValueRestriction) (( VariableConstraint ) alphanode.getConstraint()).getRestriction();
       
        assertTrue( r.getExpression() instanceof ReturnValueExpression );
        assertTrue( r.getExpression() instanceof MVELReturnValueExpression )
       
        alphanode = (AlphaNode) alphanode.getSinkPropagator().getSinks()[0];       
        assertTrue( (( VariableConstraint ) alphanode.getConstraint()).getFieldExtractor() instanceof MVELClassFieldReader );
        r = (ReturnValueRestriction) (( VariableConstraint ) alphanode.getConstraint()).getRestriction();
       
        assertTrue( r.getExpression() instanceof ReturnValueExpression );
        assertTrue( r.getExpression() instanceof MVELReturnValueExpression );         
    }   
View Full Code Here

Examples of org.drools.rule.ReturnValueRestriction

            }
        }
       
        AlphaNode alphanode = (AlphaNode) node.getSinkPropagator().getSinks()[0];       
        assertTrue( (( VariableConstraint ) alphanode.getConstraint()).getFieldExtractor() instanceof MVELClassFieldReader );
        ReturnValueRestriction r = (ReturnValueRestriction) (( VariableConstraint ) alphanode.getConstraint()).getRestriction();
       
        assertTrue( r.getExpression() instanceof ReturnValueExpression );
        assertTrue( r.getExpression() instanceof MVELReturnValueExpression )
       
        alphanode = (AlphaNode) alphanode.getSinkPropagator().getSinks()[0];       
        assertTrue( (( VariableConstraint ) alphanode.getConstraint()).getFieldExtractor() instanceof MVELClassFieldReader );
        r = (ReturnValueRestriction) (( VariableConstraint ) alphanode.getConstraint()).getRestriction();
       
        assertTrue( r.getExpression() instanceof ReturnValueExpression );
        assertTrue( r.getExpression() instanceof MVELReturnValueExpression );         
    }      
View Full Code Here

Examples of org.drools.rule.ReturnValueRestriction

            }
        }
       
        AlphaNode alphanode = (AlphaNode) node.getSinkPropagator().getSinks()[0];       
        assertTrue( (( VariableConstraint ) alphanode.getConstraint()).getFieldExtractor() instanceof MVELClassFieldReader );
        ReturnValueRestriction r = (ReturnValueRestriction) (( VariableConstraint ) alphanode.getConstraint()).getRestriction();
       
        assertTrue( r.getExpression() instanceof ReturnValueExpression );
        assertTrue( r.getExpression() instanceof MVELReturnValueExpression )
       
        alphanode = (AlphaNode) alphanode.getSinkPropagator().getSinks()[0];       
        assertTrue( (( VariableConstraint ) alphanode.getConstraint()).getFieldExtractor() instanceof MVELClassFieldReader );
        r = (ReturnValueRestriction) (( VariableConstraint ) alphanode.getConstraint()).getRestriction();
       
        assertTrue( r.getExpression() instanceof ReturnValueExpression );
        assertTrue( r.getExpression() instanceof MVELReturnValueExpression );         
    }    
View Full Code Here

Examples of org.drools.rule.ReturnValueRestriction

        assertTrue( c.getPredicateExpression() instanceof PredicateExpression );
        assertTrue( c.getPredicateExpression() instanceof CompiledInvoker );
        assertTrue( !(c.getPredicateExpression() instanceof MVELPredicateExpression ) );
       
        alphanode = (AlphaNode) alphanode.getSinkPropagator().getSinks()[0];
        ReturnValueRestriction r = (ReturnValueRestriction) (( VariableConstraint ) alphanode.getConstraint()).getRestriction();
       
        assertTrue( r.getExpression() instanceof ReturnValueExpression );
        assertTrue( r.getExpression() instanceof CompiledInvoker );
        assertTrue( !(r.getExpression() instanceof MVELReturnValueExpression ) );       
    }
View Full Code Here

Examples of org.drools.rule.ReturnValueRestriction

        PredicateConstraint c = ( PredicateConstraint ) constraint[0];
        assertTrue( c.getPredicateExpression() instanceof PredicateExpression );
        assertTrue( c.getPredicateExpression() instanceof CompiledInvoker );
        assertTrue( !(c.getPredicateExpression() instanceof MVELPredicateExpression ) );
        
        ReturnValueRestriction r = ( ReturnValueRestriction ) (( VariableConstraint )constraint[1]).getRestriction();
        assertTrue( r.getExpression() instanceof ReturnValueExpression );
        assertTrue( r.getExpression() instanceof CompiledInvoker );
        assertTrue( !(r.getExpression() instanceof MVELReturnValueExpression ) );       
    }
View Full Code Here

Examples of org.drools.rule.ReturnValueRestriction

            // something failed and an error should already have been reported
            return false;
        }

        if (declr == null) {
            ReturnValueRestriction returnValueRestriction = (ReturnValueRestriction)restriction;
            Declaration[] requiredDeclarations = restriction.getRequiredDeclarations();
            String[] requiredGlobals = returnValueRestriction.getRequiredGlobals();
            declarations = new Declaration[(requiredDeclarations != null ? requiredDeclarations.length : 0) + (requiredGlobals != null ? requiredGlobals.length : 0)];
            int i = 0;
            if (requiredDeclarations != null) {
                for (Declaration requiredDeclaration : requiredDeclarations)
                    declarations[i++] = requiredDeclaration;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.