Package org.drools.guvnor.client.modeldriven.brl

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


    assertEquals("Cheese", ((FactPattern)rm.lhs[1]).factType);
    assertEquals("c", ((FactPattern)rm.lhs[1]).boundName);

    //examine the first pattern
    FactPattern person = (FactPattern) rm.lhs[0];
    assertEquals(3, person.constraintList.constraints.length);
    SingleFieldConstraint cons = (SingleFieldConstraint) person.constraintList.constraints[0];
    assertEquals(ISingleFieldConstraint.TYPE_LITERAL, cons.constraintValueType);
    assertEquals("name", cons.fieldName);
    assertEquals("==", cons.operator);
    assertEquals("mike", cons.value);

    cons = (SingleFieldConstraint) person.constraintList.constraints[1];
    assertEquals(ISingleFieldConstraint.TYPE_RET_VALUE, cons.constraintValueType);
    assertEquals("age", cons.fieldName);
    assertEquals("<", cons.operator);
    assertEquals("33 + 1", cons.value);

    cons = (SingleFieldConstraint) person.constraintList.constraints[2];
    assertEquals(ISingleFieldConstraint.TYPE_PREDICATE, cons.constraintValueType);
    assertEquals("age > 6", cons.value);


    //examine the second pattern
    FactPattern cheese = (FactPattern) rm.lhs[1];
    assertEquals(1, cheese.constraintList.constraints.length);
    cons = (SingleFieldConstraint) cheese.constraintList.constraints[0];
    assertEquals("type", cons.fieldName);
    assertEquals("==", cons.operator);
    assertEquals("stilton", cons.value);
View Full Code Here

            }
           
      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

            }
           
      if (validCell(cell)) {

        //get or create the pattern it belongs too
        FactPattern fp = findByFactPattern(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;
                            if (c.operator.equals("in")) {
                                sfc.value = makeInList(cell);
                            } else {
                                sfc.value = cell;
                            }

            }
            sfc.constraintValueType = c.constraintValueType;
            fp.addConstraint(sfc);
            break;
          case ISingleFieldConstraint.TYPE_PREDICATE:
            SingleFieldConstraint pred = new SingleFieldConstraint();
            pred.constraintValueType = c.constraintValueType;
                        if (c.factField != null && c.factField.indexOf("$param") > -1) {
                            //handle interpolation
                            pred.value = c.factField.replace("$param", cell)
                        } else {
                pred.value = cell;
                        }
            fp.addConstraint(pred);
            break;
        default:
          throw new IllegalArgumentException("Unknown constraintValueType: " + c.constraintValueType);
        }
      }
View Full Code Here

      ConditionCol c = (ConditionCol) conditionCols.get(i);
      String cell = row[i + GuidedDecisionTable.INTERNAL_ELEMENTS + 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

        String[] items = (String[]) engine.dataEnumLists.get( "Person.age" );
        assertEquals(2, items.length);
        assertEquals("42", items[0]);
        assertEquals("43", items[1]);

        items = engine.getEnums(new FactPattern("Person"), "age").fixedList;
        assertEquals(2, items.length);
        assertEquals("42", items[0]);
        assertEquals("43", items[1]);

        assertNull(engine.getEnums(new FactPattern("Nothing"), "age"));


        assertEquals(null, engine.getEnums(new FactPattern("Something"), "else"));

    }
View Full Code Here

      sce.dataEnumLists = new HashMap();
      sce.dataEnumLists.put("Fact.type", new String[] {"sex", "colour"});
      sce.dataEnumLists.put("Fact.value[type=sex]", new String[] {"M", "F"});
      sce.dataEnumLists.put("Fact.value[type=colour]", new String[] {"RED", "WHITE", "BLUE"});

      FactPattern pat = new FactPattern("Fact");
      SingleFieldConstraint sfc = new SingleFieldConstraint("type");
      sfc.value = "sex";
      pat.addConstraint(sfc);
      String[] result = sce.getEnums(pat, "value").fixedList;
      assertEquals(2, result.length);
      assertEquals("M", result[0]);
      assertEquals("F", result[1]);


      pat = new FactPattern("Fact");
      sfc = new SingleFieldConstraint("type");
      sfc.value = "colour";
      pat.addConstraint(sfc);

      result = sce.getEnums(pat, "value").fixedList;
      assertEquals(3, result.length);
      assertEquals("RED", result[0]);
      assertEquals("WHITE", result[1]);
View Full Code Here

      sce.dataEnumLists.put("Fact.type", new String[] {"sex", "colour"});
      sce.dataEnumLists.put("Fact.value[f1, f2]", new String[] {"select something from database where x=@{f1} and y=@{f2}"});



      FactPattern fp = new FactPattern("Fact");
      String[] drops = sce.getEnums(fp, "type").fixedList;
      assertEquals(2, drops.length);
      assertEquals("sex", drops[0]);
      assertEquals("colour", drops[1]);


      Map lookupFields = sce.loadDataEnumLookupFields();
      assertEquals(1, lookupFields.size());
      String[] flds = (String[]) lookupFields.get("Fact.value");
      assertEquals(2, flds.length);
      assertEquals("f1", flds[0]);
      assertEquals("f2", flds[1]);


      FactPattern pat = new FactPattern("Fact");
      SingleFieldConstraint sfc = new SingleFieldConstraint("f1");
      sfc.value = "f1val";
      pat.addConstraint(sfc);
      sfc = new SingleFieldConstraint("f2");
      sfc.value = "f2val";
      pat.addConstraint(sfc);


      DropDownData dd = sce.getEnums(pat, "value");
      assertNull(dd.fixedList);
      assertNotNull(dd.queryExpression);
View Full Code Here

public class RuleModelTest extends TestCase {

  public void testAddItemLhs() {
    final RuleModel model = new RuleModel();
    final FactPattern x = new FactPattern();
    model.addLhsItem(x);
    assertEquals(1, model.lhs.length);

    final FactPattern y = new FactPattern();
    model.addLhsItem(y);

    assertEquals(2, model.lhs.length);
    assertEquals(x, model.lhs[0]);
    assertEquals(y, model.lhs[1]);
View Full Code Here

  }

  public void testAllVariableBindings() {
    final RuleModel model = new RuleModel();
    model.lhs = new IPattern[2];
    final FactPattern x = new FactPattern("Car");
    model.lhs[0] = x;
    x.boundName = "boundFact";

    SingleFieldConstraint sfc = new SingleFieldConstraint("q");
    x.addConstraint(sfc);
    sfc.fieldBinding = "field1";

    SingleFieldConstraint sfc2 = new SingleFieldConstraint("q");
    x.addConstraint(sfc2);
    sfc2.fieldBinding = "field2";

    model.lhs[1] = new CompositeFactPattern();

    List vars = model.getAllVariables();
View Full Code Here

TOP

Related Classes of org.drools.guvnor.client.modeldriven.brl.FactPattern

Copyright © 2018 www.massapicom. 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.