private FactPattern visitFactPattern(FactPattern pattern) { FactPattern clone = new FactPattern(); clone.setBoundName( pattern.getBoundName() ); clone.setFactType( pattern.getFactType() ); clone.setNegated( pattern.isNegated() ); CEPWindow cloneCEPWindow = new CEPWindow(); cloneCEPWindow.setOperator( pattern.getWindow().getOperator() ); cloneCEPWindow.setParameters( cloneCEPWindowParameters( pattern.getWindow() ) ); clone.setWindow( cloneCEPWindow ); for ( FieldConstraint fc : pattern.getFieldConstraints() ) { clone.addConstraint( (FieldConstraint) visit( fc ) ); } return clone; }
if ( p.isBound() && var.equals( p.getBoundName() ) ) { return p.getFactType(); for ( FieldConstraint fc : p.getFieldConstraints() ) { String type = getFieldBinding( fc, var );
public ExpressionVariable(FactPattern fact) { super(fact.getBoundName(), fact.getFactType(), fact.getFactType()); if (!fact.isBound()) { throw new RuntimeException("the fact is not bounded: " + fact); } this.fact = fact; }
FactPattern fp0 = new FactPattern(); fp0.setBoundName( "$t0" ); fp0.setFactType( "FT0" ); fp0.setNegated( true ); "fp0sfc0p0Value" ); fp0sfc0.setValue( "fp0sfc0Value" ); fp0.addConstraint( fp0sfc0 ); FactPattern fp1 = new FactPattern(); fp1.setBoundName( "$t1" ); fp1.setFactType( "FT1" ); fp1.setNegated( true ); "fp1sfc0p0Value" ); fp1sfc0.setValue( "fp1sfc0Value" ); fp1.addConstraint( fp1sfc0 ); assertTrue( cfp0Clone.getPatterns()[0] instanceof FactPattern ); FactPattern fp0Clone = (FactPattern) cfp0Clone.getPatterns()[0]; assertEquals( fp0.getBoundName(), fp0Clone.getBoundName() ); assertEquals( fp0.getFactType(), fp0Clone.getFactType() ); assertTrue( cfp0Clone.getPatterns()[1] instanceof FactPattern ); FactPattern fp1Clone = (FactPattern) cfp0Clone.getPatterns()[1]; assertEquals( fp1.getBoundName(), fp1Clone.getBoundName() );
cfp0.type = CompositeFactPattern.COMPOSITE_TYPE_OR; FactPattern fp0 = new FactPattern(); fp0.setBoundName( "$t0" ); fp0.setFactType( "FT0" ); fp0.setNegated( true ); fp0sfc0.setOperator( "==" ); fp0sfc0.setValue( "fp0sfc0Value" ); fp0.addConstraint( fp0sfc0 ); fp0sfc1.setOperator( "==" ); fp0sfc1.setValue( "fp0sfc1Value" ); fp0.addConstraint( fp0sfc1 ); FactPattern fp1 = new FactPattern(); fp1.setBoundName( "$t1" ); fp1.setFactType( "FT1" ); fp1.setNegated( true ); fp1sfc0.setOperator( "==" ); fp1sfc0.setValue( "fp1sfc0Value" ); fp1.addConstraint( fp1sfc0 );
private RuleModel getModelWithNoConstraints() { final RuleModel m = new RuleModel(); m.name = "Complex Rule"; final FactPattern pat = new FactPattern( "Person" ); pat.setBoundName( "p1" ); final SingleFieldConstraint con = new SingleFieldConstraint(); con.setFieldBinding( "f1" ); con.setFieldName( "age" ); // con.operator = "<"; // con.value = "42"; pat.addConstraint( con ); m.addLhsItem( pat ); return m; }
@Test public void testFactPattern_Basics() { RuleModel model = new RuleModel(); model.lhs = new IPattern[1]; FactPattern fp0 = new FactPattern(); fp0.setBoundName( "$t0" ); fp0.setFactType( "FT0" ); fp0.setNegated( true ); model.lhs[0] = fp0; RuleModelCloneVisitor cloneVisitor = new RuleModelCloneVisitor(); RuleModel clone = cloneVisitor.visitRuleModel( model ); assertEquals( 1, clone.lhs.length ); assertNotSame( model.lhs[0], clone.lhs[0] ); assertNotNull( clone.lhs[0] ); assertTrue( clone.lhs[0] instanceof FactPattern ); FactPattern fp0Clone = (FactPattern) clone.lhs[0]; assertEquals( fp0.getBoundName(), fp0Clone.getBoundName() ); assertEquals( fp0.getFactType(), fp0Clone.getFactType() ); assertEquals( fp0.isNegated(), fp0Clone.isNegated() ); }
@Test public void testAddConstraint() { final FactPattern p = new FactPattern(); final SingleFieldConstraint x = new SingleFieldConstraint( "x" ); p.addConstraint( x ); assertEquals( 1, p.constraintList.constraints.length ); assertEquals( x, p.constraintList.constraints[0] ); final SingleFieldConstraint y = new SingleFieldConstraint( "y" ); p.addConstraint( y ); assertEquals( 2, p.constraintList.constraints.length ); assertEquals( x, p.constraintList.constraints[0] ); assertEquals( y, p.constraintList.constraints[1] ); }
private void generateFactPattern( FactPattern pattern ) { if ( pattern.isNegated() ) { buf.append( "not " ); } else if ( pattern.isBound() ) { bindingsPatterns.put( pattern.getBoundName(), pattern ); buf.append( pattern.getBoundName() ); buf.append( " : " ); } if ( pattern.getFactType() != null ) { buf.append( pattern.getFactType() ); } buf.append( "( " ); // top level constraints if ( pattern.constraintList != null ) { generateConstraints( pattern ); } buf.append( ")" ); //Add CEP window definition CEPWindow window = pattern.getWindow(); if ( window.isDefined() ) { buf.append( " " ); buf.append( window.getOperator() ); buf.append( buildOperatorParameterDRL( window.getParameters() ) ); } }
if ( fact.isBound() ) { result.add( fact.getBoundName() ); for ( int j = 0; j < fact.getFieldConstraints().length; j++ ) { FieldConstraint fc = fact.getFieldConstraints()[j]; if ( fc instanceof SingleFieldConstraintEBLeftSide ) { SingleFieldConstraintEBLeftSide exp = (SingleFieldConstraintEBLeftSide) fc;
@Test public void testRemoveItemLhs() { final RuleModel model = new RuleModel(); model.lhs = new IPattern[3]; final FactPattern x = new FactPattern( "Car" ); model.lhs[0] = x; x.setBoundName( "x" ); final FactPattern y = new FactPattern( "Car" ); model.lhs[1] = y; y.setBoundName( "y" ); final FactPattern other = new FactPattern( "House" ); model.lhs[2] = other; assertEquals( 3, model.lhs.length ); assertEquals( x, model.lhs[0] ); model.removeLhsItem( 0 ); assertEquals( 2, model.lhs.length ); assertEquals( y, model.lhs[0] ); }
@Test public void testDataEnums3() { String pkg = "package org.test\n import org.drools.ide.common.client.modeldriven.SuggestionCompletionEngineTest.NestedClass"; SuggestionCompletionLoader loader = new SuggestionCompletionLoader(); List<String> enums = new ArrayList<String>(); enums.add( "'Fact.f1' : ['a1', 'a2'] \n 'Fact.f2' : ['def1', 'def2', 'def3'] \n 'Fact.f2[f1=a2]' : ['c1', 'c2']" ); SuggestionCompletionEngine engine = loader.getSuggestionEngine( pkg, new ArrayList<JarInputStream>(), new ArrayList<DSLTokenizedMappingFile>(), enums ); assertEquals( "String", engine.getFieldType( "NestedClass", "name" ) ); FactPattern pat = new FactPattern( "Fact" ); SingleFieldConstraint f1 = new SingleFieldConstraint( "f1" ); f1.setValue( "a1" ); pat.addConstraint( f1 ); pat.addConstraint( new SingleFieldConstraint( "f2" ) ); DropDownData data = engine.getEnums( pat.getFactType(), pat.constraintList, "f2" ); assertNotNull( data ); assertEquals( 3, data.fixedList.length ); }
@Override public List<String> getLHSBoundFacts() { Set<String> facts = new HashSet<String>(); for ( CompositeColumn< ? extends BaseColumn> col : dtable.getConditions() ) { if ( col instanceof Pattern52 ) { Pattern52 p = (Pattern52) col; if ( p.isBound() ) { facts.add( p.getBoundName() ); } } else if ( col instanceof BRLConditionColumn ) { BRLConditionColumn brl = (BRLConditionColumn) col; for ( IPattern p : brl.getDefinition() ) { if ( p instanceof FactPattern ) { final FactPattern fp = (FactPattern) p; if ( fp.isBound() ) { facts.add( fp.getBoundName() ); } } } } } facts.addAll( super.getLHSBoundFacts() ); return new ArrayList<String>( facts ); }
@Test public void testIsBound() { FactPattern pat = new FactPattern(); pat.setBoundName("x"); assertTrue(pat.isBound()); pat = new FactPattern(); assertFalse(pat.isBound()); }
private void visitFactPattern(FactPattern pattern) { this.factPattern = pattern; for ( FieldConstraint fc : pattern.getFieldConstraints() ) { visit( fc ); } }
@Test public void testGetFieldConstraints() { FactPattern pat = new FactPattern(); assertEquals(0, pat.getFieldConstraints().length); assertNull(pat.constraintList); pat.addConstraint( new SingleFieldConstraint() ); assertNotNull(pat.constraintList); assertEquals(1, pat.getFieldConstraints().length); }
((FactPattern) rm.lhs[0]).getFactType() ); assertEquals( "p1", ((FactPattern) rm.lhs[0]).getBoundName() ); ((FactPattern) rm.lhs[1]).getFactType() ); assertEquals( "c", ((FactPattern) rm.lhs[1]).getBoundName() ); cons.getValue() ); assertEquals( person.isNegated(), true ); cons.getConstraintValueType() ); assertEquals( cheese.isNegated(), false );
FactPattern fp0 = new FactPattern(); fp0.setFactType( "FT0" ); sfc0p0.setOperator( "==" ); sfc0p0.setValue( "sfc0p0Value" ); fp0.addConstraint( sfc0p0 ); sfc1p0.setOperator( "==" ); sfc1p0.setValue( "sfc1p0Value" ); fp0.addConstraint( sfc1p0 ); FactPattern fp1 = new FactPattern(); fp1.setFactType( "FT1" ); sfc0p1.setOperator( "==" ); sfc0p1.setValue( "sfc0p1Value" ); fp1.addConstraint( sfc0p1 ); sfc1p1.setOperator( "==" ); sfc1p1.setValue( "sfc1p1Value" ); fp1.addConstraint( sfc1p1 );
if ( p.getBoundName() != null && var.equals( p.getBoundName() ) ) { return p; for ( int j = 0; j < p.getFieldConstraints().length; j++ ) { FieldConstraint fc = p.getFieldConstraints()[j]; List<String> fieldBindings = getFieldBinding( fc ); if ( fieldBindings.contains( var ) ) {
@Test public void testRemoveConstraint() { final FactPattern p = new FactPattern(); final SingleFieldConstraint x = new SingleFieldConstraint( "x" ); p.addConstraint( x ); final SingleFieldConstraint y = new SingleFieldConstraint( "y" ); p.addConstraint( y ); assertEquals( 2, p.constraintList.constraints.length ); p.removeConstraint( 1 ); assertEquals( 1, p.constraintList.constraints.length ); assertEquals( x, p.constraintList.constraints[0] ); }