Search in sources :

Example 16 with ConnectiveConstraint

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

the class GeneratorContextRuleModelVisitor method visitSingleFieldConstraint.

private void visitSingleFieldConstraint(final SingleFieldConstraintEBLeftSide sfexp) {
    final String genericType = sfexp.getExpressionLeftSide().getGenericType();
    String factType = sfexp.getExpressionLeftSide().getPreviousClassType();
    if (factType == null) {
        factType = sfexp.getExpressionLeftSide().getClassType();
    }
    final InterpolationVariable var = new InterpolationVariable(sfexp.getValue(), genericType, factType, sfexp.getFieldName());
    if (BaseSingleFieldConstraint.TYPE_TEMPLATE == sfexp.getConstraintValueType() && !vars.contains(var)) {
        vars.add(var);
    } else {
        hasNonTemplateOutput = true;
    }
    // Visit Connection constraints
    if (sfexp.getConnectives() != null) {
        for (int i = 0; i < sfexp.getConnectives().length; i++) {
            final ConnectiveConstraint cc = sfexp.getConnectives()[i];
            InterpolationVariable ccVar = new InterpolationVariable(cc.getValue(), genericType, factType, cc.getFieldName());
            if (BaseSingleFieldConstraint.TYPE_TEMPLATE == cc.getConstraintValueType() && !vars.contains(ccVar)) {
                vars.add(ccVar);
            } else {
                hasNonTemplateOutput = true;
            }
        }
    }
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 17 with ConnectiveConstraint

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

the class RuleTemplateModelDRLPersistenceTest method testCompositeConstraintWithConnectiveConstraintSecondValue.

@Test
public void testCompositeConstraintWithConnectiveConstraintSecondValue() {
    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( field2 == \"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) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Example 18 with ConnectiveConstraint

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

the class RuleTemplateModelDRLPersistenceTest method testConnectiveConstraintBothValues.

@Test
public void testConnectiveConstraintBothValues() {
    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\" || == \"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) Test(org.junit.Test)

Example 19 with ConnectiveConstraint

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

the class RuleTemplateModelDRLPersistenceTest method testCompositeConstraintWithConnectiveConstraintFirstValue.

@Test
public void testCompositeConstraintWithConnectiveConstraintFirstValue() {
    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\" )\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) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Example 20 with ConnectiveConstraint

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

the class RuleTemplateModelXMLPersistenceTest method testCompositeConstraintsRoundTrip.

@Test
public void testCompositeConstraintsRoundTrip() throws Exception {
    TemplateModel m = new TemplateModel();
    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 xml = RuleTemplateModelXMLPersistenceImpl.getInstance().marshal(m);
    // System.err.println(xml);
    RuleModel m2 = RuleTemplateModelXMLPersistenceImpl.getInstance().unmarshal(xml);
    assertNotNull(m2);
    assertEquals("with composite", m2.name);
    assertEquals(m2.lhs.length, m.lhs.length);
    assertEquals(m2.rhs.length, m.rhs.length);
}
Also used : BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) 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