Examples of FactPattern


Examples of org.drools.brms.client.modeldriven.brl.FactPattern

    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";
View Full Code Here

Examples of org.drools.guvnor.client.modeldriven.brl.FactPattern

      ConditionCol c = (ConditionCol) conditionCols.get(i);
      String cell = row[i + 2 + numOfAttributesAndMeta];
      if (validCell(cell)) {

        //get or create the pattern it belongs too
        FactPattern fp = find(patterns, c.boundName);
        if (fp == null) {
          fp = new FactPattern(c.factType);
          fp.boundName = c.boundName;
          patterns.add(fp);
        }



        //now add the constraint from this cell
        switch (c.constraintValueType) {
          case ISingleFieldConstraint.TYPE_LITERAL:
          case ISingleFieldConstraint.TYPE_RET_VALUE:
            SingleFieldConstraint sfc = new SingleFieldConstraint(c.factField);
            if (no(c.operator)) {

              String[] a = cell.split("\\s");
              if (a.length > 1) {
                sfc.operator = a[0];
                sfc.value = a[1];
              } else {
                sfc.value = cell;
              }
            } else {
              sfc.operator = c.operator;
              sfc.value = cell;
            }
            sfc.constraintValueType = c.constraintValueType;
            fp.addConstraint(sfc);
            break;
          case ISingleFieldConstraint.TYPE_PREDICATE:
            SingleFieldConstraint pred = new SingleFieldConstraint();
            pred.constraintValueType = c.constraintValueType;
            pred.value = cell;
            fp.addConstraint(pred);
            break;
        default:
          throw new IllegalArgumentException("Unknown constraintValueType: " + c.constraintValueType);
        }
      }
View Full Code Here

Examples of org.drools.guvnor.models.commons.shared.rule.FactPattern

                IPattern ifp = findByFactPattern( patterns,
                                                  pattern.getBoundName() );

                //If the pattern does not exist create one suitable
                if ( ifp == null ) {
                    FactPattern fp = new FactPattern( pattern.getFactType() );
                    fp.setBoundName( pattern.getBoundName() );
                    fp.setNegated( pattern.isNegated() );
                    fp.setWindow( pattern.getWindow() );
                    if ( pattern.getEntryPointName() != null && pattern.getEntryPointName().length() > 0 ) {
                        FromEntryPointFactPattern fep = new FromEntryPointFactPattern();
                        fep.setEntryPointName( pattern.getEntryPointName() );
                        fep.setFactPattern( fp );
                        patterns.add( fep );
                        ifp = fep;
                    } else {
                        patterns.add( fp );
                        ifp = fp;
                    }
                }

                //Extract the FactPattern from the IFactPattern
                FactPattern fp;
                if ( ifp instanceof FactPattern ) {
                    fp = (FactPattern) ifp;
                } else if ( ifp instanceof FromEntryPointFactPattern ) {
                    FromEntryPointFactPattern fep = (FromEntryPointFactPattern) ifp;
                    fp = fep.getFactPattern();
                } else {
                    throw new IllegalArgumentException( "Inexpected IFactPattern implementation found." );
                }

                //Add the constraint from this cell
                switch ( c.getConstraintValueType() ) {
                    case BaseSingleFieldConstraint.TYPE_LITERAL:
                    case BaseSingleFieldConstraint.TYPE_RET_VALUE:
                        if ( !isOtherwise ) {
                            FieldConstraint fc = makeSingleFieldConstraint( c,
                                                                            cell );
                            fp.addConstraint( fc );
                        } else {
                            FieldConstraint fc = makeSingleFieldConstraint( c,
                                                                            allColumns,
                                                                            data );
                            fp.addConstraint( fc );
                        }
                        break;
                    case BaseSingleFieldConstraint.TYPE_PREDICATE:
                        SingleFieldConstraint pred = new SingleFieldConstraint();
                        pred.setConstraintValueType( c.getConstraintValueType() );
                        if ( c.getFactField() != null
                                && c.getFactField().indexOf( "$param" ) > -1 ) {
                            // handle interpolation
                            pred.setValue( c.getFactField().replace( "$param",
                                                                     cell ) );
                        } else {
                            pred.setValue( cell );
                        }
                        fp.addConstraint( pred );
                        break;
                    default:
                        throw new IllegalArgumentException( "Unknown constraintValueType: "
                                                                    + c.getConstraintValueType() );
                }
View Full Code Here

Examples of org.drools.ide.common.client.modeldriven.brl.FactPattern

         * variable type, then propose a list
         */
        ListBox listVariable = new ListBox();
        List<String> vars = model.getModel().getLHSBoundFacts();
        for ( String v : vars ) {
            FactPattern factPattern = model.getModel().getLHSBoundFact( v );
            if ( factPattern.getFactType().equals( this.methodParameter.type ) ) {
                // First selection is empty
                if ( listVariable.getItemCount() == 0 ) {
                    listVariable.addItem( "..." );
                }

View Full Code Here

Examples of org.drools.ide.common.client.modeldriven.brl.FactPattern

        }
        for ( String v : vars ) {
            boolean createButton = false;
            Button variable = new Button( constants.BoundVariable() );
            if ( vars2.contains( v ) == false ) {
                FactPattern factPattern = model.getModel().getLHSBoundFact( v );
                if ( factPattern.getFactType().equals( this.parameterType ) ) {
                    createButton = true;
                }
            } else {
                ActionInsertFact factPattern = model.getModel().getRHSBoundFact( v );
                if ( factPattern.factType.equals( this.parameterType ) ) {
View Full Code Here

Examples of org.drools.ide.common.client.modeldriven.brl.FactPattern

        //Examine LHS Fact and Field bindings and RHS (new) Fact bindings
        for ( String v : bindingsInScope ) {

            //LHS FactPattern
            FactPattern fp = model.getLHSBoundFact( v );
            if ( fp != null ) {
                if ( isLHSFactTypeEquivalent( v ) ) {
                    applicableBindingsInScope.add( v );
                }
            }
View Full Code Here

Examples of org.drools.ide.common.client.modeldriven.brl.FactPattern

    @Test
    public void testFactPattern_ExpressionFormLine() {
        RuleModel model = new RuleModel();

        model.lhs = new IPattern[1];
        FactPattern fp0 = new FactPattern();
        fp0.setBoundName( "$t0" );
        fp0.setFactType( "FT0" );

        SingleFieldConstraint sfc0 = new SingleFieldConstraint();
        ExpressionFormLine efl0 = new ExpressionFormLine();
        efl0.setBinding( "$efl0" );
        ExpressionText efl0p0 = new ExpressionText( "efl0p0" );
        efl0.appendPart( efl0p0 );
        sfc0.setExpressionValue( efl0 );
        fp0.addConstraint( sfc0 );

        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( 1,
                      fp0Clone.constraintList.constraints.length );

        assertNotSame( fp0.constraintList.constraints[0],
View Full Code Here

Examples of org.drools.ide.common.client.modeldriven.brl.FactPattern

    @Test
    public void testFactPattern_SingleFieldConstraintEBLeftSide() {
        RuleModel model = new RuleModel();

        model.lhs = new IPattern[1];
        FactPattern fp0 = new FactPattern();
        fp0.setBoundName( "$t0" );
        fp0.setFactType( "FT0" );

        SingleFieldConstraintEBLeftSide sfc0 = new SingleFieldConstraintEBLeftSide();

        ExpressionFormLine eflhs0 = new ExpressionFormLine();
        eflhs0.setBinding( "$eflhs0" );
        ExpressionText eflhs0p0 = new ExpressionText( "eflhs0p0" );
        eflhs0.appendPart( eflhs0p0 );
        sfc0.setExpressionLeftSide( eflhs0 );

        ExpressionFormLine efl0 = new ExpressionFormLine();
        efl0.setBinding( "$efl0" );
        ExpressionText efl0p0 = new ExpressionText( "efl0p0" );
        efl0.appendPart( efl0p0 );
        sfc0.setExpressionValue( efl0 );

        fp0.addConstraint( sfc0 );

        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( 1,
                      fp0Clone.constraintList.constraints.length );

        assertNotSame( fp0.constraintList.constraints[0],
View Full Code Here

Examples of org.drools.ide.common.client.modeldriven.brl.FactPattern

        model.lhs = new IPattern[1];
        CompositeFactPattern cfp0 = new CompositeFactPattern();
        cfp0.type = CompositeFactPattern.COMPOSITE_TYPE_OR;

        FactPattern fp0 = new FactPattern();
        fp0.setBoundName( "$t0" );
        fp0.setFactType( "FT0" );
        fp0.setNegated( true );

        SingleFieldConstraint fp0sfc0 = new SingleFieldConstraint();
        fp0sfc0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        fp0sfc0.setFieldBinding( "$fp0sfc0" );
        fp0sfc0.setFieldName( "fp0sfc0" );
        fp0sfc0.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
        fp0sfc0.setOperator( "==" );
        fp0sfc0.setParameter( "fp0sfc0p0",
                              "fp0sfc0p0Value" );
        fp0sfc0.setValue( "fp0sfc0Value" );
        fp0.addConstraint( fp0sfc0 );

        FactPattern fp1 = new FactPattern();
        fp1.setBoundName( "$t1" );
        fp1.setFactType( "FT1" );
        fp1.setNegated( true );

        SingleFieldConstraint fp1sfc0 = new SingleFieldConstraint();
        fp1sfc0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        fp1sfc0.setFieldBinding( "$fp1sfc0" );
        fp1sfc0.setFieldName( "fp1sfc0" );
        fp1sfc0.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
        fp1sfc0.setOperator( "==" );
        fp1sfc0.setParameter( "fp1sfc0p0",
                              "fp1sfc0p0Value" );
        fp1sfc0.setValue( "fp1sfc0Value" );
        fp1.addConstraint( fp1sfc0 );

        cfp0.addFactPattern( fp0 );
        cfp0.addFactPattern( fp1 );

        model.lhs[0] = cfp0;

        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 CompositeFactPattern );
        CompositeFactPattern cfp0Clone = (CompositeFactPattern) clone.lhs[0];
        assertEquals( cfp0.type,
                      cfp0Clone.type );
        assertEquals( cfp0.getPatterns().length,
                      cfp0Clone.getPatterns().length );

        assertNotSame( cfp0.getPatterns()[0],
                       cfp0Clone.getPatterns()[0] );
        assertNotNull( cfp0Clone.getPatterns()[0] );
        assertTrue( cfp0Clone.getPatterns()[0] instanceof FactPattern );
        FactPattern fp0Clone = (FactPattern) cfp0Clone.getPatterns()[0];
        assertEquals( fp0.getBoundName(),
                      fp0Clone.getBoundName() );
        assertEquals( fp0.getFactType(),
                      fp0Clone.getFactType() );

        assertEquals( fp0.constraintList.constraints.length,
                      fp0Clone.constraintList.constraints.length );
        assertNotSame( fp0.constraintList.constraints[0],
                       fp0Clone.constraintList.constraints[0] );
        assertNotNull( fp0Clone.constraintList.constraints[0] );
        assertTrue( fp0Clone.constraintList.constraints[0] instanceof SingleFieldConstraint );
        SingleFieldConstraint fp0sfc0Clone = (SingleFieldConstraint) fp0Clone.constraintList.constraints[0];
        assertEquals( fp0sfc0.getFieldBinding(),
                      fp0sfc0Clone.getFieldBinding() );
        assertEquals( fp0sfc0.getFieldName(),
                      fp0sfc0Clone.getFieldName() );
        assertEquals( fp0sfc0.getFieldType(),
                      fp0sfc0Clone.getFieldType() );
        assertEquals( fp0sfc0.getOperator(),
                      fp0sfc0Clone.getOperator() );
        assertNotNull( fp0sfc0Clone.getParameter( "fp0sfc0p0" ) );
        assertEquals( fp0sfc0.getParameter( "fp0sfc0p0" ),
                      fp0sfc0Clone.getParameter( "fp0sfc0p0" ) );
        assertEquals( fp0sfc0.getValue(),
                      fp0sfc0Clone.getValue() );

        assertNotSame( cfp0.getPatterns()[1],
                       cfp0Clone.getPatterns()[1] );
        assertNotNull( cfp0Clone.getPatterns()[1] );
        assertTrue( cfp0Clone.getPatterns()[1] instanceof FactPattern );
        FactPattern fp1Clone = (FactPattern) cfp0Clone.getPatterns()[1];
        assertEquals( fp1.getBoundName(),
                      fp1Clone.getBoundName() );
        assertEquals( fp1.getFactType(),
                      fp1Clone.getFactType() );

        assertEquals( fp1.constraintList.constraints.length,
                      fp1Clone.constraintList.constraints.length );
        assertNotSame( fp1.constraintList.constraints[0],
                       fp1Clone.constraintList.constraints[0] );
View Full Code Here

Examples of org.drools.ide.common.client.modeldriven.brl.FactPattern

        ExpressionFormLine efl0 = new ExpressionFormLine();
        efl0.setBinding( "$efl0" );
        ExpressionText efl0p0 = new ExpressionText( "efl0p0" );
        efl0.appendPart( efl0p0 );
        fp0.setExpression( efl0 );
        FactPattern fp0FactPattern = new FactPattern( "fp0FactPattern" );
        fp0.setFactPattern( fp0FactPattern );
        fp0.setFunction( "fp0.function" );
        fp0.setInitCode( "fp0.initCode" );
        fp0.setResultCode( "fp0.resultCode" );
        fp0.setReverseCode( "fp0.reverseCode" );
        FactPattern fp0SourcePattern = new FactPattern( "fp0SourcePattern" );
        fp0.setSourcePattern( fp0SourcePattern );

        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 FromAccumulateCompositeFactPattern );
        FromAccumulateCompositeFactPattern fp0Clone = (FromAccumulateCompositeFactPattern) clone.lhs[0];
        assertEquals( fp0.getActionCode(),
                      fp0Clone.getActionCode() );
        assertEquals( fp0.getFunction(),
                      fp0Clone.getFunction() );
        assertEquals( fp0.getInitCode(),
                      fp0Clone.getInitCode() );
        assertEquals( fp0.getResultCode(),
                      fp0Clone.getResultCode() );
        assertEquals( fp0.getReverseCode(),
                      fp0Clone.getReverseCode() );

        assertNotSame( fp0.getExpression(),
                       fp0Clone.getExpression() );
        assertNotNull( fp0Clone.getExpression() );
        assertTrue( fp0Clone.getExpression() instanceof ExpressionFormLine );
        ExpressionFormLine efl0Clone = (ExpressionFormLine) fp0Clone.getExpression();

        assertEquals( 1,
                      fp0Clone.getExpression().getParts().size() );
        assertTrue( fp0Clone.getExpression().getParts().get( 0 ) instanceof ExpressionText );
        ExpressionText efl0p0Clone = (ExpressionText) fp0Clone.getExpression().getParts().get( 0 );
        assertEquals( efl0p0.getClassType(),
                      efl0p0Clone.getClassType() );
        assertEquals( efl0p0.getName(),
                      efl0p0Clone.getName() );
        assertEquals( efl0p0.getGenericType(),
                      efl0p0Clone.getGenericType() );
        assertEquals( efl0p0.getParametricType(),
                      efl0p0Clone.getParametricType() );

        assertEquals( efl0.getBinding(),
                      efl0Clone.getBinding() );
        assertEquals( efl0.getClassType(),
                      efl0Clone.getClassType() );
        assertEquals( efl0.getFieldName(),
                      efl0Clone.getFieldName() );
        assertEquals( efl0.getGenericType(),
                      efl0Clone.getGenericType() );
        assertEquals( efl0.getParametricType(),
                      efl0Clone.getParametricType() );
        assertEquals( efl0.getCurrentName(),
                      efl0Clone.getCurrentName() );

        assertNotSame( fp0.getFactPattern(),
                       fp0Clone.getFactPattern() );
        assertNotNull( fp0Clone.getFactPattern() );
        assertTrue( fp0Clone.getFactPattern() instanceof FactPattern );
        FactPattern fp0FactPatternClone = (FactPattern) fp0Clone.getFactPattern();
        assertEquals( fp0FactPattern.getBoundName(),
                      fp0FactPatternClone.getBoundName() );
        assertEquals( fp0FactPattern.getFactType(),
                      fp0FactPatternClone.getFactType() );

        assertNotSame( fp0.getSourcePattern(),
                       fp0Clone.getSourcePattern() );
        assertNotNull( fp0Clone.getSourcePattern() );
        assertTrue( fp0Clone.getSourcePattern() instanceof FactPattern );
        FactPattern fp0SourcePatternClone = (FactPattern) fp0Clone.getSourcePattern();
        assertEquals( fp0SourcePattern.getBoundName(),
                      fp0SourcePatternClone.getBoundName() );
        assertEquals( fp0SourcePattern.getFactType(),
                      fp0SourcePatternClone.getFactType() );
    }
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.