Search in sources :

Example 6 with CompositeFieldConstraint

use of org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testNotSoundsLikeAndNotMatches.

@Test
public void testNotSoundsLikeAndNotMatches() {
    final String ruleName = "test not soundslike constraint";
    final RuleModel model = new RuleModel();
    model.name = ruleName;
    final FactPattern pattern = new FactPattern("Person");
    final CompositeFieldConstraint notMatchesAndNotSoundsLike = new CompositeFieldConstraint();
    notMatchesAndNotSoundsLike.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_AND);
    pattern.addConstraint(notMatchesAndNotSoundsLike);
    final SingleFieldConstraint fieldNotSoundsLikeGoo = new SingleFieldConstraint();
    fieldNotSoundsLikeGoo.setFieldType(DataType.TYPE_STRING);
    fieldNotSoundsLikeGoo.setFieldName("field");
    fieldNotSoundsLikeGoo.setOperator("not soundslike");
    fieldNotSoundsLikeGoo.setValue("goo");
    fieldNotSoundsLikeGoo.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    notMatchesAndNotSoundsLike.addConstraint(fieldNotSoundsLikeGoo);
    final SingleFieldConstraint fieldNotMatchesGoo = new SingleFieldConstraint();
    fieldNotMatchesGoo.setFieldType(DataType.TYPE_STRING);
    fieldNotMatchesGoo.setFieldName("field");
    fieldNotMatchesGoo.setOperator("not matches");
    fieldNotMatchesGoo.setValue("goo");
    fieldNotMatchesGoo.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    notMatchesAndNotSoundsLike.addConstraint(fieldNotMatchesGoo);
    model.addLhsItem(pattern);
    String expected = "rule \"" + ruleName + "\"" + "\tdialect \"mvel\"\n when " + "Person( field not soundslike \"goo\" && field not matches \"goo\" )" + "then" + "end";
    checkMarshalling(expected, model);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Example 7 with CompositeFieldConstraint

use of org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testCompositeConstraintsRoundTrip.

@Test
public void testCompositeConstraintsRoundTrip() throws Exception {
    RuleModel m = new RuleModel();
    m.name = "with composite";
    FactPattern p1 = new FactPattern("Person");
    p1.setBoundName("p1");
    m.addLhsItem(p1);
    FactPattern p = new FactPattern("Goober");
    m.addLhsItem(p);
    CompositeFieldConstraint comp = new CompositeFieldConstraint();
    comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    p.addConstraint(comp);
    final SingleFieldConstraint X = new SingleFieldConstraint();
    X.setFieldName("goo");
    X.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    X.setValue("foo");
    X.setOperator("==");
    X.setConnectives(new ConnectiveConstraint[1]);
    X.getConnectives()[0] = new ConnectiveConstraint();
    X.getConnectives()[0].setConstraintValueType(ConnectiveConstraint.TYPE_LITERAL);
    X.getConnectives()[0].setOperator("|| ==");
    X.getConnectives()[0].setValue("bar");
    comp.addConstraint(X);
    final SingleFieldConstraint Y = new SingleFieldConstraint();
    Y.setFieldName("goo2");
    Y.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    Y.setValue("foo");
    Y.setOperator("==");
    comp.addConstraint(Y);
    CompositeFieldConstraint comp2 = new CompositeFieldConstraint();
    comp2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_AND);
    final SingleFieldConstraint Q1 = new SingleFieldConstraint();
    Q1.setFieldName("goo");
    Q1.setOperator("==");
    Q1.setValue("whee");
    Q1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    comp2.addConstraint(Q1);
    final SingleFieldConstraint Q2 = new SingleFieldConstraint();
    Q2.setFieldName("gabba");
    Q2.setOperator("==");
    Q2.setValue("whee");
    Q2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    comp2.addConstraint(Q2);
    // now nest it
    comp.addConstraint(comp2);
    final SingleFieldConstraint Z = new SingleFieldConstraint();
    Z.setFieldName("goo3");
    Z.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    Z.setValue("foo");
    Z.setOperator("==");
    p.addConstraint(Z);
    ActionInsertFact ass = new ActionInsertFact("Whee");
    m.addRhsItem(ass);
    String drl = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    PackageDataModelOracle dmo = mock(PackageDataModelOracle.class);
    RuleModel m2 = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.EMPTY_LIST, dmo);
    assertNotNull(m2);
    assertEquals("with composite", m2.name);
    assertEquals(m2.lhs.length, m.lhs.length);
    assertEquals(m2.rhs.length, m.rhs.length);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Example 8 with CompositeFieldConstraint

use of org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testCompositeOrConstraints.

@Test
public void testCompositeOrConstraints() {
    RuleModel m = new RuleModel();
    m.name = "or composite";
    FactPattern p = new FactPattern("Goober");
    m.addLhsItem(p);
    CompositeFieldConstraint comp = new CompositeFieldConstraint();
    comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    p.addConstraint(comp);
    final SingleFieldConstraint sfc1 = new SingleFieldConstraint();
    sfc1.setFactType("Goober");
    sfc1.setFieldName("gooField");
    sfc1.setFieldType(DataType.TYPE_STRING);
    sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    sfc1.setValue("gooValue");
    sfc1.setOperator("==");
    comp.addConstraint(sfc1);
    final SingleFieldConstraint sfc2 = new SingleFieldConstraint();
    sfc2.setFactType("Goober");
    sfc2.setFieldName("fooField");
    sfc2.setFieldType(DataType.TYPE_OBJECT);
    sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    sfc2.setOperator("!= null");
    comp.addConstraint(sfc2);
    final SingleFieldConstraint sfc3 = new SingleFieldConstraint();
    sfc3.setFactType("Bar");
    sfc3.setFieldName("barField");
    sfc3.setParent(sfc2);
    sfc3.setFieldType(DataType.TYPE_STRING);
    sfc3.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    sfc3.setValue("barValue");
    sfc3.setOperator("==");
    comp.addConstraint(sfc3);
    ActionInsertFact ass = new ActionInsertFact("Whee");
    m.addRhsItem(ass);
    String actual = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    String expected = "rule \"or composite\"" + "dialect \"mvel\"\n" + "when\n" + "Goober( gooField == \"gooValue\" || fooField != null || fooField.barField == \"barValue\" )\n" + "then\n" + "insert( new Whee() );\n" + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Example 9 with CompositeFieldConstraint

use of org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testCompositeOrConstraintsComplex.

@Test
public void testCompositeOrConstraintsComplex() {
    RuleModel m = new RuleModel();
    m.name = "or composite complex";
    FactPattern p = new FactPattern("Goober");
    m.addLhsItem(p);
    CompositeFieldConstraint comp = new CompositeFieldConstraint();
    comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    p.addConstraint(comp);
    final SingleFieldConstraint sfc1 = new SingleFieldConstraint();
    sfc1.setFactType("Goober");
    sfc1.setFieldName("gooField");
    sfc1.setFieldType(DataType.TYPE_STRING);
    sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    sfc1.setValue("gooValue");
    sfc1.setOperator("==");
    comp.addConstraint(sfc1);
    final SingleFieldConstraint sfc2 = new SingleFieldConstraint();
    sfc2.setFactType("Goober");
    sfc2.setFieldName("fooField");
    sfc2.setFieldType(DataType.TYPE_OBJECT);
    sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    sfc2.setOperator("!= null");
    comp.addConstraint(sfc2);
    final SingleFieldConstraint sfc3 = new SingleFieldConstraint();
    sfc3.setFactType("Bar");
    sfc3.setFieldName("barField");
    sfc3.setParent(sfc2);
    sfc3.setFieldType(DataType.TYPE_STRING);
    sfc3.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    sfc3.setValue("barValue");
    sfc3.setOperator("==");
    comp.addConstraint(sfc3);
    final SingleFieldConstraint sfc4 = new SingleFieldConstraint();
    sfc4.setFactType("Goober");
    sfc4.setFieldName("zooField");
    sfc4.setFieldType(DataType.TYPE_STRING);
    sfc4.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    sfc4.setValue("zooValue");
    sfc4.setOperator("==");
    p.addConstraint(sfc4);
    ActionInsertFact ass = new ActionInsertFact("Whee");
    m.addRhsItem(ass);
    String expected = "rule \"or composite complex\"" + "dialect \"mvel\"\n" + "when\n" + "Goober( gooField == \"gooValue\" || fooField != null || fooField.barField == \"barValue\", zooField == \"zooValue\" )\n" + "then\n" + "insert( new Whee() );\n" + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Example 10 with CompositeFieldConstraint

use of org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testCompositeConstraints.

@Test
public void testCompositeConstraints() {
    RuleModel m = new RuleModel();
    m.name = "with composite";
    FactPattern p1 = new FactPattern("Person");
    p1.setBoundName("p1");
    m.addLhsItem(p1);
    FactPattern p = new FactPattern("Goober");
    m.addLhsItem(p);
    CompositeFieldConstraint comp = new CompositeFieldConstraint();
    comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    p.addConstraint(comp);
    final SingleFieldConstraint X = new SingleFieldConstraint();
    X.setFieldName("goo");
    X.setFieldType(DataType.TYPE_STRING);
    X.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    X.setValue("foo");
    X.setOperator("==");
    X.setConnectives(new ConnectiveConstraint[1]);
    X.getConnectives()[0] = new ConnectiveConstraint();
    X.getConnectives()[0].setConstraintValueType(ConnectiveConstraint.TYPE_LITERAL);
    X.getConnectives()[0].setFieldType(DataType.TYPE_STRING);
    X.getConnectives()[0].setOperator("|| ==");
    X.getConnectives()[0].setValue("bar");
    comp.addConstraint(X);
    final SingleFieldConstraint Y = new SingleFieldConstraint();
    Y.setFieldName("goo2");
    Y.setFieldType(DataType.TYPE_STRING);
    Y.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    Y.setValue("foo");
    Y.setOperator("==");
    comp.addConstraint(Y);
    CompositeFieldConstraint comp2 = new CompositeFieldConstraint();
    comp2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_AND);
    final SingleFieldConstraint Q1 = new SingleFieldConstraint();
    Q1.setFieldType(DataType.TYPE_STRING);
    Q1.setFieldName("goo");
    Q1.setOperator("==");
    Q1.setValue("whee");
    Q1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    comp2.addConstraint(Q1);
    final SingleFieldConstraint Q2 = new SingleFieldConstraint();
    Q2.setFieldType(DataType.TYPE_STRING);
    Q2.setFieldName("gabba");
    Q2.setOperator("==");
    Q2.setValue("whee");
    Q2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    comp2.addConstraint(Q2);
    // now nest it
    comp.addConstraint(comp2);
    final SingleFieldConstraint Z = new SingleFieldConstraint();
    Z.setFieldName("goo3");
    Z.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    Z.setFieldType(DataType.TYPE_STRING);
    Z.setValue("foo");
    Z.setOperator("==");
    p.addConstraint(Z);
    ActionInsertFact ass = new ActionInsertFact("Whee");
    m.addRhsItem(ass);
    String actual = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    String expected = "rule \"with composite\"\n" + "\tdialect \"mvel\"\n" + "\twhen\n" + "\t\tp1 : Person( )\n" + "\t\tGoober( goo == \"foo\"  || == \"bar\" || goo2 == \"foo\" || ( goo == \"whee\" && gabba == \"whee\" ), goo3 == \"foo\" )\n" + "\tthen\n" + "\t\tinsert( new Whee() );\n" + "end\n";
    assertEqualsIgnoreWhitespace(expected, actual);
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Aggregations

CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)57 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)56 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)49 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)49 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)49 Test (org.junit.Test)49 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)47 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)34 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)16 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)15 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)14 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)9 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)7 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)7 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)5 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)4 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2