private ActionInsertFact visitActionFieldList( ActionInsertFact afl ) { ActionInsertFact clone = new ActionInsertFact(); clone.setFactType( afl.getFactType() ); clone.setBoundName( afl.getBoundName() ); for ( ActionFieldValue afv : afl.getFieldValues() ) { 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; }
private Widget getAssertLabel() { ClickHandler cl = new ClickHandler() { public void onClick( ClickEvent event ) { Widget w = (Widget) event.getSource(); showAddFieldPopup( w ); } }; String assertType = "assert"; //NON-NLS if ( this.model instanceof ActionInsertLogicalFact) { assertType = "assertLogical"; //NON-NLS } String lbl = ( model.isBound() == false ) ? HumanReadable.getActionDisplayName(assertType) + " <b>" + this.model.getFactType() + "</b>" : HumanReadable.getActionDisplayName( assertType ) + " <b>" + this.model.getFactType() + "</b>" + " <b>[" + model.getBoundName() + "]</b>"; if ( this.model.getFieldValues() != null && model.getFieldValues().length > 0 ) { lbl = lbl + ":"; } return new ClickableLabel( lbl, cl, !this.readOnly ); }
/** * 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; }
ActionInsertFact aif1 = new ActionInsertFact( "Person" ); aif1.setBoundName( "$aif" ); aif1.addFieldValue( new ActionFieldValue( "rating", null, DataType.TYPE_STRING ) ); aif1.getFieldValues()[ 0 ].setNature( BaseSingleFieldConstraint.TYPE_LITERAL ); ActionInsertFact aif2 = new ActionInsertFact( "Person" ); aif2.setBoundName( "$aif" ); aif2.addFieldValue( new ActionFieldValue( "rating", null, DataType.TYPE_STRING ) ); aif2.getFieldValues()[ 0 ].setNature( BaseSingleFieldConstraint.TYPE_LITERAL ); model.addRhsItem( aif2 ); ActionInsertFact raif2 = (ActionInsertFact) r2; assertEquals( "Person", raif2.getFactType() ); assertEquals( "rating", raif2.getFieldValues()[ 0 ].getField() ); assertEquals( DataType.TYPE_STRING, raif2.getFieldValues()[ 0 ].getType() ); assertNull( raif2.getFieldValues()[ 0 ].getValue() ); assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL, raif2.getFieldValues()[ 0 ].getNature() );
ActionInsertFact ai = new ActionInsertFact( "Birthday" ); ai.addFieldValue( new ActionFieldValue( "dob", "31-Jan-2000", DataType.TYPE_DATE ) );
public void execute() { model.addRhsItem( new ActionInsertFact( item ), Integer.parseInt( positionCbo.getValue( positionCbo.getSelectedIndex() ) ) ); hide(); } } );
ActionInsertFact aif = new ActionInsertFact(); aif.setBoundName( "$r" ); aif.setFactType( "Results" ); ActionWorkItemFieldValue fv1 = new ActionWorkItemFieldValue( "ResultsBooleanResult", DataType.TYPE_BOOLEAN, "BooleanResult", Boolean.class.getName() ); aif.addFieldValue( fv1 ); ActionWorkItemFieldValue fv2 = new ActionWorkItemFieldValue( "ResultsFloatResult", DataType.TYPE_NUMERIC_FLOAT, "FloatResult", Float.class.getName() ); aif.addFieldValue( fv2 ); ActionWorkItemFieldValue fv3 = new ActionWorkItemFieldValue( "ResultsIntegerResult", DataType.TYPE_NUMERIC_INTEGER, "IntegerResult", Integer.class.getName() ); aif.addFieldValue( fv3 ); ActionWorkItemFieldValue fv4 = new ActionWorkItemFieldValue( "ResultsStringResult", DataType.TYPE_STRING, "StringResult", String.class.getName() ); aif.addFieldValue( fv4 );
if ( action.getFieldValues().length == 0 && action.getBoundName() == null ) { buf.append( ( isLogic ) ? "insertLogical( new " : "insert( new " ); buf.append( action.getFactType() ); buf.append( "() );\n" ); } else { buf.append( action.getFactType() ); if ( action.getBoundName() == null ) { buf.append( " fact" ); buf.append( idx ); } else { buf.append( " " + action.getBoundName() ); buf.append( action.getFactType() ); buf.append( "();\n" ); if ( action.getBoundName() == null ) { generateSetMethodCalls( "fact" + idx, action.getFieldValues() ); } else { generateSetMethodCalls( action.getBoundName(), action.getFieldValues() ); if ( action.getBoundName() == null ) { buf.append( "fact" ); buf.append( idx++ ); } else { buf.append( action.getBoundName() ); if ( action.getBoundName() == null ) {
private void visitActionFieldList( ActionInsertFact afl ) { String factType = afl.getFactType(); for ( ActionFieldValue afv : afl.getFieldValues() ) { InterpolationVariable var = new InterpolationVariable( afv.getValue(), afv.getType(), factType, afv.getField() ); if ( afv.getNature() == FieldNatureType.TYPE_TEMPLATE && !vars.containsKey( var ) ) { vars.put( var, vars.size() ); } } }
assertEquals( aif.getBoundName(), "$r" ); assertEquals( 1, aif.getFieldValues().length ); ActionFieldValue fv1 = aif.getFieldValues()[ 0 ]; assertNotNull( fv1 ); assertTrue( fv1 instanceof ActionWorkItemFieldValue );
@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.setFieldValues( new ActionFieldValue[ 1 ] ); ins.getFieldValues()[ 0 ] = val; m.addRhsItem( ins ); ActionInsertLogicalFact insL = new ActionInsertLogicalFact( "Shizzle" ); ActionFieldValue valL = new ActionFieldValue( "goo", "42", "Numeric" ); insL.setFieldValues( new ActionFieldValue[ 1 ] ); insL.getFieldValues()[ 0 ] = valL; m.addRhsItem( insL ); String result = BRDRLPersistence.getInstance().marshal( m ); assertTrue( result.indexOf( ">insert" ) > -1 ); assertTrue( result.indexOf( ">insertLogical" ) > -1 ); }
private boolean isRHSFieldTypeEquivalent( String boundVariable ) { String boundFactType = modeller.getModel().getRHSBoundFact( boundVariable ).getFactType(); if ( boundFactType == null ) { return false; } if ( this.variableType == null ) { return false; } //If the types are SuggestionCompletionEngine.TYPE_COMPARABLE check the enums are equivalent if ( boundFactType.equals( DataType.TYPE_COMPARABLE ) ) { if ( !this.variableType.equals( DataType.TYPE_COMPARABLE ) ) { return false; } String[] dd = this.modeller.getSuggestionCompletions().getEnumValues( boundFactType, this.value.getField() ); return isEnumEquivalent( dd ); } //If the types are identical (and not SuggestionCompletionEngine.TYPE_COMPARABLE) then return true if ( boundFactType.equals( this.variableType ) ) { return true; } return false; }
public void onClick( ClickEvent event ) { String var = varName.getText(); if ( getModeller().isVariableNameUsed( var ) && ( ( model.getBoundName() != null && model.getBoundName().equals( var ) == false ) || model.getBoundName() == null ) ) { Window.alert( Constants.INSTANCE.TheVariableName0IsAlreadyTaken( var ) ); return; } model.setBoundName( var ); setModified( true ); getModeller().refreshWidget(); popup.hide(); } } );
String type = getStatementType( fact, factsType ); if ( type != null ) { ActionInsertFact action = new ActionInsertFact( type ); m.addRhsItem( action ); if ( factsType.containsKey( fact ) ) { action.setBoundName( fact ); addSettersToAction( setStatements, fact, action, isJavaDialect );
public void onChange( ChangeEvent event ) { String fieldName = box.getItemText( box.getSelectedIndex() ); String fieldType = completions.getFieldType( model.getFactType(), fieldName ); model.addFieldValue( new ActionFieldValue( fieldName, "", fieldType ) ); setModified( true ); getModeller().refreshWidget(); popup.hide(); } } );
public void visitActionInsertFact( final ActionInsertFact action ) { getClasses( action.getFieldValues() ); }
/** * 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; }
ActionInsertFact aif = new ActionInsertFact( "Person" ); aif.setBoundName( "$aif" ); aif.addFieldValue( new ActionFieldValue( "rating", null, DataType.TYPE_STRING ) ); aif.getFieldValues()[ 0 ].setNature( BaseSingleFieldConstraint.TYPE_LITERAL ); model.addRhsItem( aif ); ActionInsertFact raif2 = (ActionInsertFact) r2; assertEquals( "Person", raif2.getFactType() ); assertEquals( "rating", raif2.getFieldValues()[ 0 ].getField() ); assertEquals( DataType.TYPE_STRING, raif2.getFieldValues()[ 0 ].getType() ); assertNull( raif2.getFieldValues()[ 0 ].getValue() ); assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL, raif2.getFieldValues()[ 0 ].getNature() );
ActionInsertFact brl1DefinitionAction1 = new ActionInsertFact( "Baddie" ); ActionFieldValue brl1DefinitionAction1FieldValue1 = new ActionFieldValue( "name", "Gargamel", DataType.TYPE_STRING ); brl1DefinitionAction1FieldValue1.setNature( BaseSingleFieldConstraint.TYPE_LITERAL ); brl1DefinitionAction1.addFieldValue( brl1DefinitionAction1FieldValue1 ); brl1Definition.add( brl1DefinitionAction1 );
@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"; 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"; checkMarshallUnmarshall( expected, m ); }