private ActionInsertFact visitActionFieldList(ActionInsertFact afl) { ActionInsertFact clone = new ActionInsertFact(); clone.factType = afl.factType; clone.setBoundName( afl.getBoundName() ); for ( ActionFieldValue afv : afl.fieldValues ) { ActionFieldValue afvClone = new ActionFieldValue(); afvClone.setField( afv.getField() ); afvClone.setNature( afv.getNature() ); afvClone.setType( afv.getType() ); afvClone.setValue( afv.getValue() ); clone.addFieldValue( afvClone ); } return clone; }
/** * This will get a list of all RHS bound variables. */ public List<String> getAllRHSVariables() { List<String> result = new ArrayList<String>(); for ( int i = 0; i < this.rhs.length; i++ ) { IAction pat = this.rhs[i]; if ( pat instanceof ActionInsertFact ) { ActionInsertFact fact = (ActionInsertFact) pat; if ( fact.isBound() ) { result.add( fact.getBoundName() ); } } } return result; }
private void doAction(List<LabelledAction> actions, ActionWorkItemInsertFactCol52 ac, String cell) { if ( Boolean.TRUE.equals( Boolean.parseBoolean( cell ) ) ) { LabelledAction a = findByLabelledAction( actions, ac.getBoundName() ); if ( a == null ) { a = new LabelledAction(); a.boundName = ac.getBoundName(); if ( !ac.isInsertLogical() ) { ActionInsertFact ins = new ActionInsertFact( ac.getFactType() ); ins.setBoundName( ac.getBoundName() ); a.action = ins; } else { ActionInsertLogicalFact ins = new ActionInsertLogicalFact( ac.getFactType() ); ins.setBoundName( ac.getBoundName() ); a.action = ins; } actions.add( a ); } ActionInsertFact ins = (ActionInsertFact) a.action; ActionWorkItemFieldValue val = new ActionWorkItemFieldValue( ac.getFactField(), ac.getType(), ac.getWorkItemName(), ac.getWorkItemResultParameterName(), ac.getParameterClassName() ); ins.addFieldValue( val ); } }
ActionInsertFact ai = new ActionInsertFact( "Birthday" ); ai.addFieldValue( new ActionFieldValue( "dob", "31-Jan-2000", SuggestionCompletionEngine.TYPE_DATE ) );
@Test public void testBasics() { final BRLPersistence p = BRXMLPersistence.getInstance(); final RuleModel m = new RuleModel(); m.addLhsItem( new FactPattern( "Person" ) ); m.addLhsItem( new FactPattern( "Accident" ) ); m.addAttribute( new RuleAttribute( "no-loop", "true" ) ); m.addRhsItem( new ActionInsertFact( "Report" ) ); ActionGlobalCollectionAdd ag = new ActionGlobalCollectionAdd(); ag.factName = "x"; ag.globalName = "g"; m.addRhsItem( ag ); m.name = "my rule"; final String xml = p.marshal( m ); System.out.println( xml ); assertTrue( xml.indexOf( "Person" ) > -1 ); assertTrue( xml.indexOf( "Accident" ) > -1 ); assertTrue( xml.indexOf( "no-loop" ) > -1 ); assertTrue( xml.indexOf( "org.drools" ) == -1 ); assertTrue( xml.indexOf( "addToGlobal" ) > -1 ); RuleModel rm_ = BRXMLPersistence.getInstance().unmarshal( xml ); assertEquals( 2, rm_.rhs.length ); }
/** * This will return the ActionInsertFact that a variable is bound to. * * @param var * The bound fact variable (NOT bound field). * @return null or the ActionInsertFact found. */ public ActionInsertFact getRHSBoundFact(final String var) { if ( this.rhs == null ) { return null; } for ( int i = 0; i < this.rhs.length; i++ ) { if ( this.rhs[i] instanceof ActionInsertFact ) { final ActionInsertFact p = (ActionInsertFact) this.rhs[i]; if ( p.getBoundName() != null && var.equals( p.getBoundName() ) ) { return p; } } } return null; }
private ActionInsertFactCol52ActionInsertFactAdaptor(ActionInsertFactCol52 action) { if ( action == null ) { throw new NullPointerException( "action cannot be null" ); } this.action = action; this.factType = action.getFactType(); ActionFieldValue afv = new ActionFieldValue(); afv.field = action.getFactField(); afv.nature = BaseSingleFieldConstraint.TYPE_LITERAL; afv.type = action.getType(); super.addFieldValue( afv ); }
private void doAction(List<LabelledAction> actions, ActionInsertFactCol52 ac, String cell) { LabelledAction a = findByLabelledAction( actions, ac.getBoundName() ); if ( a == null ) { a = new LabelledAction(); a.boundName = ac.getBoundName(); if ( !ac.isInsertLogical() ) { ActionInsertFact ins = new ActionInsertFact( ac.getFactType() ); ins.setBoundName( ac.getBoundName() ); a.action = ins; } else { ActionInsertLogicalFact ins = new ActionInsertLogicalFact( ac.getFactType() ); ins.setBoundName( ac.getBoundName() ); a.action = ins; } actions.add( a ); } ActionInsertFact ins = (ActionInsertFact) a.action; ActionFieldValue val = new ActionFieldValue( ac.getFactField(), cell, ac.getType() ); ins.addFieldValue( val ); }
ActionInsertFact brl1DefinitionAction1 = new ActionInsertFact( "Baddie" ); ActionFieldValue brl1DefinitionAction1FieldValue1 = new ActionFieldValue( "name", "Gargamel", SuggestionCompletionEngine.TYPE_STRING ); brl1DefinitionAction1FieldValue1.setNature( BaseSingleFieldConstraint.TYPE_LITERAL ); brl1DefinitionAction1.addFieldValue( brl1DefinitionAction1FieldValue1 ); brl1Definition.add( brl1DefinitionAction1 );
@Test public void testAssertWithDSL() throws Exception { RuleModel m = new RuleModel(); DSLSentence sen = new DSLSentence(); sen.setDefinition( "I CAN HAS DSL" ); m.addRhsItem( sen ); ActionInsertFact ins = new ActionInsertFact( "Shizzle" ); ActionFieldValue val = new ActionFieldValue( "goo", "42", "Numeric" ); ins.fieldValues = new ActionFieldValue[ 1 ]; ins.fieldValues[ 0 ] = val; m.addRhsItem( ins ); ActionInsertLogicalFact insL = new ActionInsertLogicalFact( "Shizzle" ); ActionFieldValue valL = new ActionFieldValue( "goo", "42", "Numeric" ); insL.fieldValues = new ActionFieldValue[ 1 ]; insL.fieldValues[ 0 ] = valL; m.addRhsItem( insL ); String result = BRDRLPersistence.getInstance().marshal( m ); assertTrue( result.indexOf( ">insert" ) > -1 ); assertTrue( result.indexOf( ">insertLogical" ) > -1 ); }
/** * This will return the ActionInsertFact that a variable is bound to. * * @param var * The bound fact variable (NOT bound field). * @return null or the ActionInsertFact found. */ public ActionInsertFact getRHSBoundFact(final String var) { if ( this.rhs == null ) { return null; } for ( int i = 0; i < this.rhs.length; i++ ) { if ( this.rhs[i] instanceof ActionInsertFact ) { final ActionInsertFact p = (ActionInsertFact) this.rhs[i]; if ( p.getBoundName() != null && var.equals( p.getBoundName() ) ) { return p; } } } return null; }
private ActionInsertFactCol52ActionInsertFactAdaptor(ActionInsertFactCol52 action) { if ( action == null ) { throw new NullPointerException( "action cannot be null" ); } this.action = action; this.factType = action.getFactType(); ActionFieldValue afv = new ActionFieldValue(); afv.field = action.getFactField(); afv.nature = BaseSingleFieldConstraint.TYPE_LITERAL; afv.type = action.getType(); super.addFieldValue( afv ); }
private void doAction(List<LabelledAction> actions, ActionInsertFactCol52 ac, String cell) { LabelledAction a = findByLabelledAction( actions, ac.getBoundName() ); if ( a == null ) { a = new LabelledAction(); a.boundName = ac.getBoundName(); if ( !ac.isInsertLogical() ) { ActionInsertFact ins = new ActionInsertFact( ac.getFactType() ); ins.setBoundName( ac.getBoundName() ); a.action = ins; } else { ActionInsertLogicalFact ins = new ActionInsertLogicalFact( ac.getFactType() ); ins.setBoundName( ac.getBoundName() ); a.action = ins; } actions.add( a ); } ActionInsertFact ins = (ActionInsertFact) a.action; ActionFieldValue val = new ActionFieldValue( ac.getFactField(), cell, ac.getType() ); ins.addFieldValue( val ); }
private ActionInsertFact visitActionFieldList(ActionInsertFact afl) { ActionInsertFact clone = new ActionInsertFact(); clone.factType = afl.factType; clone.setBoundName( afl.getBoundName() ); for ( ActionFieldValue afv : afl.fieldValues ) { ActionFieldValue afvClone = new ActionFieldValue(); afvClone.setField( afv.getField() ); afvClone.setNature( afv.getNature() ); afvClone.setType( afv.getType() ); afvClone.setValue( afv.getValue() ); clone.addFieldValue( afvClone ); } return clone; }
ActionInsertFact brl1DefinitionAction1 = new ActionInsertFact( "Baddie" ); ActionFieldValue brl1DefinitionAction1FieldValue1 = new ActionFieldValue( "name", "Gargamel", SuggestionCompletionEngine.TYPE_STRING ); brl1DefinitionAction1FieldValue1.setNature( BaseSingleFieldConstraint.TYPE_LITERAL ); brl1DefinitionAction1.addFieldValue( brl1DefinitionAction1FieldValue1 ); brl1Definition.add( brl1DefinitionAction1 ); ActionInsertFact brl1DefinitionAction2 = new ActionInsertFact( "Smurf" ); ActionFieldValue brl1DefinitionAction2FieldValue1 = new ActionFieldValue( "name", "$name", SuggestionCompletionEngine.TYPE_STRING ); brl1DefinitionAction2FieldValue1.setNature( BaseSingleFieldConstraint.TYPE_TEMPLATE ); brl1DefinitionAction2.addFieldValue( brl1DefinitionAction2FieldValue1 ); ActionFieldValue brl1DefinitionAction2FieldValue2 = new ActionFieldValue( "age", "$age", SuggestionCompletionEngine.TYPE_NUMERIC_INTEGER ); brl1DefinitionAction2FieldValue2.setNature( BaseSingleFieldConstraint.TYPE_TEMPLATE ); brl1DefinitionAction2.addFieldValue( brl1DefinitionAction2FieldValue2 ); brl1Definition.add( brl1DefinitionAction2 );
/** * This will get a list of all RHS bound variables. */ public List<String> getAllRHSVariables() { List<String> result = new ArrayList<String>(); for ( int i = 0; i < this.rhs.length; i++ ) { IAction pat = this.rhs[i]; if ( pat instanceof ActionInsertFact ) { ActionInsertFact fact = (ActionInsertFact) pat; if ( fact.isBound() ) { result.add( fact.getBoundName() ); } } } return result; }
@Test public void testBasics() { String expected = "rule \"my rule\"\n\tno-loop true\n\tdialect \"mvel\"\n\twhen\n\t\tPerson( )\n" + "\t\tAccident( )\n\tthen\n\t\tinsert( new Report() );\nend\n"; final RuleModel m = new RuleModel(); m.addLhsItem( new FactPattern( "Person" ) ); m.addLhsItem( new FactPattern( "Accident" ) ); m.addAttribute( new RuleAttribute( "no-loop", "true" ) ); m.addRhsItem( new ActionInsertFact( "Report" ) ); m.name = "my rule"; final String drl = brlPersistence.marshal( m ); assertEquals( expected, drl ); }
/** * This will return a List<String> of all ActionInsertFact bindings * * @return The bindings or an empty list if no bindings are found. */ public List<String> getRHSBoundFacts() { if ( this.rhs == null ) { return null; } final List<String> list = new ArrayList<String>(); for ( int i = 0; i < this.rhs.length; i++ ) { if ( this.rhs[i] instanceof ActionInsertFact ) { final ActionInsertFact p = (ActionInsertFact) this.rhs[i]; if ( p.getBoundName() != null ) { list.add( p.getBoundName() ); } } } return list; }
private void doAction(List<LabelledAction> actions, ActionWorkItemInsertFactCol52 ac, String cell) { if ( Boolean.TRUE.equals( Boolean.parseBoolean( cell ) ) ) { LabelledAction a = findByLabelledAction( actions, ac.getBoundName() ); if ( a == null ) { a = new LabelledAction(); a.boundName = ac.getBoundName(); if ( !ac.isInsertLogical() ) { ActionInsertFact ins = new ActionInsertFact( ac.getFactType() ); ins.setBoundName( ac.getBoundName() ); a.action = ins; } else { ActionInsertLogicalFact ins = new ActionInsertLogicalFact( ac.getFactType() ); ins.setBoundName( ac.getBoundName() ); a.action = ins; } actions.add( a ); } ActionInsertFact ins = (ActionInsertFact) a.action; ActionWorkItemFieldValue val = new ActionWorkItemFieldValue( ac.getFactField(), ac.getType(), ac.getWorkItemName(), ac.getWorkItemResultParameterName(), ac.getParameterClassName() ); ins.addFieldValue( val ); } }
ActionInsertFact aif0 = new ActionInsertFact( "AIF0" ); aif0.setBoundName( "$t0" ); ActionFieldValue aif0f0 = new ActionFieldValue( "AIF0F0", "AIF0F0Value", SuggestionCompletionEngine.TYPE_STRING ); aif0f0.setNature( BaseSingleFieldConstraint.TYPE_LITERAL ); aif0.addFieldValue( aif0f0 ); ActionFieldValue aif0f1 = new ActionFieldValue( "AIF0F1", "AIF0F1Value", SuggestionCompletionEngine.TYPE_STRING ); aif0f1.setNature( BaseSingleFieldConstraint.TYPE_LITERAL ); aif0.addFieldValue( aif0f1 ); model.rhs[0] = aif0; ActionInsertFact aif1 = new ActionInsertFact( "AIF1" ); aif1.setBoundName( "$t1" ); ActionFieldValue aif1f0 = new ActionFieldValue( "AIF1F0", "AIF1F0Value", SuggestionCompletionEngine.TYPE_STRING ); aif1f0.setNature( BaseSingleFieldConstraint.TYPE_LITERAL ); aif1.addFieldValue( aif1f0 ); ActionFieldValue aif1f1 = new ActionFieldValue( "AIF1F1", "AIF1F1Value", SuggestionCompletionEngine.TYPE_STRING ); aif1f1.setNature( BaseSingleFieldConstraint.TYPE_LITERAL ); aif1.addFieldValue( aif1f1 ); model.rhs[1] = aif1; aif0Clone.factType );