Search in sources :

Example 11 with ConnectiveConstraint

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

the class RuleTemplateModelDRLPersistenceTest method testConnectiveConstraintSecondValue.

@Test
public void testConnectiveConstraintSecondValue() {
    TemplateModel m = new TemplateModel();
    m.name = "t1";
    FactPattern p1 = new FactPattern("Person");
    m.addLhsItem(p1);
    final SingleFieldConstraint X = new SingleFieldConstraint();
    X.setFieldName("field1");
    X.setFieldType(DataType.TYPE_STRING);
    X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    X.setValue("$f1");
    X.setOperator("==");
    p1.addConstraint(X);
    ConnectiveConstraint connective = new ConnectiveConstraint();
    connective.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    connective.setFieldType(DataType.TYPE_STRING);
    connective.setOperator("|| ==");
    connective.setValue("$f2");
    X.setConnectives(new ConnectiveConstraint[1]);
    X.getConnectives()[0] = connective;
    String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"bar\" )\n" + "then\n" + "end\n";
    m.addRow(new String[] { null, "bar" });
    checkMarshall(expected, m);
}
Also used : BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Example 12 with ConnectiveConstraint

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

the class RuleTemplateModelDRLPersistenceTest method testCompositeConstraintWithConnectiveConstraintBothValues.

@Test
public void testCompositeConstraintWithConnectiveConstraintBothValues() {
    TemplateModel m = new TemplateModel();
    m.name = "t1";
    FactPattern p1 = new FactPattern("Person");
    m.addLhsItem(p1);
    CompositeFieldConstraint comp = new CompositeFieldConstraint();
    comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    p1.addConstraint(comp);
    final SingleFieldConstraint X = new SingleFieldConstraint();
    X.setFieldName("field1");
    X.setFieldType(DataType.TYPE_STRING);
    X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    X.setValue("$f1");
    X.setOperator("==");
    comp.addConstraint(X);
    ConnectiveConstraint connective = new ConnectiveConstraint();
    connective.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    connective.setFieldType(DataType.TYPE_STRING);
    connective.setOperator("|| ==");
    connective.setValue("goo");
    X.setConnectives(new ConnectiveConstraint[1]);
    X.getConnectives()[0] = connective;
    final SingleFieldConstraint Y = new SingleFieldConstraint();
    Y.setFieldName("field2");
    Y.setFieldType(DataType.TYPE_STRING);
    Y.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    Y.setValue("$f2");
    Y.setOperator("==");
    comp.addConstraint(Y);
    String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" || == \"goo\" || field2 == \"bar\" )\n" + "then\n" + "end\n";
    m.addRow(new String[] { "foo", "bar" });
    checkMarshall(expected, m);
}
Also used : BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Example 13 with ConnectiveConstraint

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

the class RuleTemplateModelDRLPersistenceTest method testConnectiveConstraintFirstValue.

@Test
public void testConnectiveConstraintFirstValue() {
    TemplateModel m = new TemplateModel();
    m.name = "t1";
    FactPattern p1 = new FactPattern("Person");
    m.addLhsItem(p1);
    final SingleFieldConstraint X = new SingleFieldConstraint();
    X.setFieldName("field1");
    X.setFieldType(DataType.TYPE_STRING);
    X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    X.setValue("$f1");
    X.setOperator("==");
    p1.addConstraint(X);
    ConnectiveConstraint connective = new ConnectiveConstraint();
    connective.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    connective.setFieldType(DataType.TYPE_STRING);
    connective.setOperator("|| ==");
    connective.setValue("$f2");
    X.setConnectives(new ConnectiveConstraint[1]);
    X.getConnectives()[0] = connective;
    String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" )\n" + "then\n" + "end\n";
    m.addRow(new String[] { "foo", null });
    checkMarshall(expected, m);
}
Also used : BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Example 14 with ConnectiveConstraint

use of org.drools.workbench.models.datamodel.rule.ConnectiveConstraint in project drools-wb by kiegroup.

the class RuleModelCloneVisitor method visitConnectiveConstraint.

private ConnectiveConstraint visitConnectiveConstraint(ConnectiveConstraint cc) {
    ConnectiveConstraint clone = new ConnectiveConstraint();
    clone.setConstraintValueType(cc.getConstraintValueType());
    clone.setExpressionValue((ExpressionFormLine) visit(cc.getExpressionValue()));
    clone.setFactType(cc.getFactType());
    clone.setFieldName(cc.getFieldName());
    clone.setFieldType(cc.getFieldType());
    clone.setOperator(cc.getOperator());
    for (Map.Entry<String, String> entry : cc.getParameters().entrySet()) {
        clone.setParameter(entry.getKey(), entry.getValue());
    }
    clone.setValue(cc.getValue());
    return clone;
}
Also used : ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with ConnectiveConstraint

use of org.drools.workbench.models.datamodel.rule.ConnectiveConstraint in project drools-wb by kiegroup.

the class GuidedRuleEditorServiceImplCDITest method testAbbreviatedCondition.

@Test
public void testAbbreviatedCondition() throws Exception {
    final String resourcePath = RULES_ROOT + "matchPeopleAbbreviatedCondition.rdrl";
    final GuidedEditorContent content = guidedRuleService.loadContent(getPath(resourcePath));
    final RuleModel model = content.getModel();
    Assertions.assertThat(model.lhs.length).isEqualTo(1);
    final FactPattern pattern = (FactPattern) model.lhs[0];
    final SingleFieldConstraint fieldConstraintOne = (SingleFieldConstraint) pattern.getConstraint(0);
    Assertions.assertThat(fieldConstraintOne.getConnectives()).hasSize(2);
    final ConnectiveConstraint fieldConstraintTwo = fieldConstraintOne.getConnectives()[0];
    final ConnectiveConstraint fieldConstraintThree = fieldConstraintOne.getConnectives()[1];
    Assertions.assertThat(fieldConstraintOne.getFieldName()).isEqualTo("age");
    Assertions.assertThat(fieldConstraintOne.getOperator()).isEqualTo(Operator.NOT_EQUAL.getOperatorString());
    Assertions.assertThat(fieldConstraintOne.getValue()).isEqualTo("18");
    Assertions.assertThat(fieldConstraintTwo.getFieldName()).isEqualTo("age");
    Assertions.assertThat(fieldConstraintTwo.getOperator()).isEqualTo("&& " + Operator.LESS.getOperatorString());
    Assertions.assertThat(fieldConstraintTwo.getValue()).isEqualTo("25");
    Assertions.assertThat(fieldConstraintThree.getFieldName()).isEqualTo("age");
    Assertions.assertThat(fieldConstraintThree.getOperator()).isEqualTo("&& " + Operator.GREATER.getOperatorString());
    Assertions.assertThat(fieldConstraintThree.getValue()).isEqualTo("15");
    final List<ValidationMessage> messages = validateResource(resourcePath);
    Assertions.assertThat(messages).isEmpty();
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) GuidedEditorContent(org.drools.workbench.screens.guided.rule.model.GuidedEditorContent) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Aggregations

ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)28 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)25 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)21 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)15 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)15 Test (org.junit.Test)15 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)14 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)13 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)9 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)9 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)7 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)7 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)7 HashMap (java.util.HashMap)4 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)4 InterpolationVariable (org.drools.workbench.models.datamodel.rule.InterpolationVariable)4 Map (java.util.Map)3 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)3 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)3 HashSet (java.util.HashSet)2