protected boolean checkProcessInstance(Activation activation) { final Map<?, ?> declarations = activation.getSubRule().getOuterDeclarations(); for ( Iterator<?> it = declarations.values().iterator(); it.hasNext(); ) { Declaration declaration = (Declaration) it.next(); if ("processInstance".equals(declaration.getIdentifier()) || "org.kie.api.runtime.process.WorkflowProcessInstance".equals(declaration.getTypeName())) { Object value = declaration.getValue( ((StatefulKnowledgeSessionImpl) getProcessInstance().getKnowledgeRuntime()).getInternalWorkingMemory(), ((InternalFactHandle) activation.getTuple().get(declaration)).getObject()); if (value instanceof ProcessInstance) { return ((ProcessInstance) value).getId() == getProcessInstance().getId(); } } } return true; }
public boolean evaluate(InternalFactHandle handle, Tuple tuple, Declaration[] previousDeclarations, Declaration[] localDeclarations, WorkingMemory workingMemory, Object context) { int price1 = previousDeclarations[0].getIntValue( (InternalWorkingMemory) workingMemory, tuple.getObject( previousDeclarations[0] ) ); int price2 = localDeclarations[0].getIntValue( (InternalWorkingMemory) workingMemory, handle.getObject() ); return (price2 == (price1 * 2)); }
DialectCompiletimeRegistry dialectRegistry = pkgBuilder.getPackageRegistry( pkg.getName() ).getDialectCompiletimeRegistry(); MVELDialect mvelDialect = (MVELDialect) dialectRegistry.getDialect( "mvel" ); final Declaration declaration = new Declaration( "p", extractor, pattern ); ((MVELSalienceExpression) context.getRule().getSalience()).compile( (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData( "mvel" ) );
protected BetaNodeFieldConstraint getConstraint(String identifier, Operator operator, String fieldName, Class clazz) { ClassFieldAccessorStore store = new ClassFieldAccessorStore(); store.setClassFieldAccessorCache( new ClassFieldAccessorCache( Thread.currentThread().getContextClassLoader() ) ); store.setEagerWire( true ); InternalReadAccessor extractor = store.getReader( clazz, fieldName ); Declaration declaration = new Declaration( identifier, extractor, new Pattern( 0, new ClassObjectType( clazz ) ) ); String expression = fieldName + " " + operator.getOperatorString() + " " + declaration.getIdentifier(); return new MvelConstraintTestUtil(expression, declaration, extractor); }
final Declaration[] declarations = new Declaration[]{new Declaration( "name", null, null ), new Declaration( "age", null, null )}; final Declaration[] inner = new Declaration[]{new Declaration( "cheese", new PatternExtractor( new ClassObjectType( Cheese.class ) ), null ), new Declaration( "price", store.getReader( Cheese.class, "price" ),
@Test public void testDeclaration() { final InternalReadAccessor extractor = store.getReader( Cheese.class, "type" ); final Pattern pattern = new Pattern( 5, new ClassObjectType( Cheese.class ) ); // Bind the extractor to a decleration // Declarations know the pattern they derive their value from final Declaration declaration = new Declaration( "typeOfCheese", extractor, pattern ); assertEquals( "typeOfCheese", declaration.getIdentifier() ); assertSame( String.class, declaration.getDeclarationClass() ); assertSame( extractor, declaration.getExtractor() ); assertEquals( 5, declaration.getPattern().getOffset() ); }
PackageRegistry pkgRegistry = pkgBuilder.getPackageRegistry( pkg.getName() ); DialectCompiletimeRegistry dialectRegistry = pkgBuilder.getPackageRegistry( pkg.getName() ).getDialectCompiletimeRegistry(); MVELDialect mvelDialect = (MVELDialect) dialectRegistry.getDialect( pkgRegistry.getDialect() ); final Declaration declaration = new Declaration( "cheese", extractor, pattern ); kbHelper.setActivation( item ); try { ((MVELConsequence) context.getRule().getConsequence()).compile( (MVELDialectRuntimeData) pkgBuilder.getPackageRegistry( pkg.getName() ).getDialectRuntimeRegistry().getDialectData( "mvel" ) ); context.getRule().getConsequence().evaluate( kbHelper, ksession ); fail( "should throw an exception, as 'if' is not allowed" );
DialectCompiletimeRegistry dialectRegistry = pkgBuilder.getPackageRegistry( pkg.getName() ).getDialectCompiletimeRegistry(); MVELDialect mvelDialect = ( MVELDialect ) dialectRegistry.getDialect( "mvel" ); final Declaration declaration = new Declaration( "a", extractor, pattern ); final EvalCondition eval = (EvalCondition) builder.build( context, evalDescr ); ((MVELEvalExpression) eval.getEvalExpression()).compile( (MVELDialectRuntimeData) pkgBuilder.getPackageRegistry( pkg.getName() ).getDialectRuntimeRegistry().getDialectData( "mvel" ) ); f0.removeLeftTuple(tuple);
@Test public void testGetFieldValue() { final InternalReadAccessor extractor = store.getReader( Cheese.class, "type" ); final Pattern pattern = new Pattern( 5, new ClassObjectType( Cheese.class ) ); // Bind the extractor to a decleration // Declarations know the pattern they derive their value from final Declaration declaration = new Declaration( "typeOfCheese", extractor, pattern ); // Create some facts final Cheese cheddar = new Cheese( "cheddar", 5 ); // Check we can extract Declarations correctly assertEquals( "cheddar", declaration.getValue( null, cheddar ) ); }
protected BetaNodeFieldConstraint getConstraint(String identifier, Operator operator, String fieldName, Class clazz) { ClassFieldAccessorStore store = new ClassFieldAccessorStore(); store.setClassFieldAccessorCache( new ClassFieldAccessorCache( Thread.currentThread().getContextClassLoader() ) ); store.setEagerWire( true ); InternalReadAccessor extractor = store.getReader( clazz, fieldName ); Declaration declaration = new Declaration( identifier, extractor, new Pattern( 0, new ClassObjectType( clazz ) ) ); String expression = fieldName + " " + operator.getOperatorString() + " " + identifier; return new MvelConstraintTestUtil(expression, operator.getOperatorString(), declaration, extractor); }
@Test public void testDeclarationsObjectType() throws Exception { final ObjectType type = new ClassObjectType( Cheese.class ); final Pattern col = new Pattern( 0, type, "foo" ); final Declaration dec = col.getDeclaration(); final InternalReadAccessor ext = dec.getExtractor(); assertEquals( Cheese.class, ext.getExtractToClass() ); final Cheese stilton = new Cheese( "stilton", 42 ); assertEquals( stilton, dec.getValue( null, stilton ) ); }
public BetaNodeFieldConstraint getBoundVariableConstraint(final Class clazz, final String fieldName, final Declaration declaration, final String evaluatorString) { final InternalReadAccessor extractor = store.getReader(clazz, fieldName); String expression = fieldName + " " + evaluatorString + " " + declaration.getIdentifier(); return new MvelConstraintTestUtil(expression, declaration, extractor); }
protected BetaNodeFieldConstraint getConstraint(String identifier, Operator operator, String fieldName, Class clazz) { ClassFieldAccessorStore store = new ClassFieldAccessorStore(); store.setClassFieldAccessorCache( new ClassFieldAccessorCache( Thread.currentThread().getContextClassLoader() ) ); store.setEagerWire( true ); InternalReadAccessor extractor = store.getReader( clazz, fieldName ); Declaration declaration = new Declaration( identifier, extractor, new Pattern( 0, new ClassObjectType( clazz ) ) ); String expression = fieldName + " " + operator.getOperatorString() + " " + declaration.getIdentifier(); return new MvelConstraintTestUtil(expression, declaration, extractor); }
final Declaration[] declarations = new Declaration[]{new Declaration( "name", store.getReader( Person.class, "name" ), null ), new Declaration( "age", store.getReader( Person.class, "age" ), null )}; final Declaration[] inner = new Declaration[]{new Declaration( "cheese", new PatternExtractor( new ClassObjectType( Cheese.class ) ), null ), new Declaration( "price", store.getReader( Cheese.class, "price" ),
new FactTemplateObjectType( cheese ) ); final Declaration declaration = new Declaration( "typeOfCheese", extractName, pattern ); declaration.getValue( null, brie ) );
@Test public void testDeclarationsFactTemplate() throws Exception { InternalKnowledgePackage pkg = new KnowledgePackageImpl( "org.store" ); final FieldTemplate cheeseName = new FieldTemplateImpl( "name", 0, String.class ); final FieldTemplate cheesePrice = new FieldTemplateImpl( "price", 1, Integer.class ); final FieldTemplate[] fields = new FieldTemplate[]{cheeseName, cheesePrice}; final FactTemplate cheese = new FactTemplateImpl( pkg, "Cheese", fields ); final ObjectType type = new FactTemplateObjectType( cheese ); final Pattern col = new Pattern( 0, type, "foo" ); final Declaration dec = col.getDeclaration(); final InternalReadAccessor ext = dec.getExtractor(); assertEquals( Fact.class, ext.getExtractToClass() ); final Fact stilton = cheese.createFact( 10 ); stilton.setFieldValue( "name", "stilton" ); stilton.setFieldValue( "price", new Integer( 200 ) ); assertEquals( stilton, dec.getValue( null, stilton ) ); }
protected boolean checkProcessInstance(Activation activation) { final Map<?, ?> declarations = activation.getSubRule().getOuterDeclarations(); for ( Iterator<?> it = declarations.values().iterator(); it.hasNext(); ) { Declaration declaration = (Declaration) it.next(); if ("processInstance".equals(declaration.getIdentifier()) || "org.kie.api.runtime.process.WorkflowProcessInstance".equals(declaration.getTypeName())) { Object value = declaration.getValue( ((StatefulKnowledgeSessionImpl) getProcessInstance().getKnowledgeRuntime()).getInternalWorkingMemory(), ((InternalFactHandle) activation.getTuple().get(declaration)).getObject()); if (value instanceof ProcessInstance) { return ((ProcessInstance) value).getId() == getProcessInstance().getId(); } } } return true; }
final Declaration[] declarations = new Declaration[]{new Declaration( "name", store.getReader( Person.class, "name" ), null ), new Declaration( "age", store.getReader( Person.class, "age" ), null )}; final Declaration[] inner = new Declaration[]{new Declaration( "$cheese", new PatternExtractor( new ClassObjectType( Cheese.class ) ), null ), new Declaration( "$person", new PatternExtractor( new ClassObjectType( Person.class ) ), null )};
final Object[] row, final boolean left) { final Declaration declaration = new Declaration( "test", extractor, null );
new Declaration("id", extractor, null) , MvelConstraint.INDEX_EVALUATOR ); final SingleIndex singleIndex = new SingleIndex( new FieldIndex[]{fieldIndex},