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;
}
}
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations