use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleModelUpgradeHelper3 method fixConstraints.
private void fixConstraints(FactPattern fp, SingleFieldConstraint sfc) {
final FieldConstraint parent = sfc.getParent();
if (parent == null) {
sfc.setFactType(fp.getFactType());
} else if (parent instanceof SingleFieldConstraint) {
sfc.setFactType(((SingleFieldConstraint) parent).getFieldType());
}
sfc.setFieldName(fixFieldName(sfc.getFieldName()));
if (sfc.getConnectives() == null) {
return;
}
for (ConnectiveConstraint cc : sfc.getConnectives()) {
cc.setFactType(fp.getFactType());
cc.setFieldName(fixFieldName(cc.getFieldName()));
}
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints5ThirdValue.
@Test
public void testNestedCompositeConstraints5ThirdValue() {
TemplateModel m = new TemplateModel();
m.name = "t1";
FactPattern p = new FactPattern("Person");
CompositeFieldConstraint comp = new CompositeFieldConstraint();
comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
p.addConstraint(comp);
m.addLhsItem(p);
final SingleFieldConstraint comp1sfc1 = new SingleFieldConstraint();
comp1sfc1.setFieldName("field1");
comp1sfc1.setFieldType(DataType.TYPE_STRING);
comp1sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp1sfc1.setValue("$f1");
comp1sfc1.setOperator("==");
comp.addConstraint(comp1sfc1);
final SingleFieldConstraint comp1sfc2 = new SingleFieldConstraint();
comp1sfc2.setFieldName("field2");
comp1sfc2.setFieldType(DataType.TYPE_STRING);
comp1sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp1sfc2.setValue("$f2");
comp1sfc2.setOperator("==");
comp.addConstraint(comp1sfc2);
final SingleFieldConstraint comp1sfc3 = new SingleFieldConstraint();
comp1sfc3.setFieldName("field3");
comp1sfc3.setFieldType(DataType.TYPE_STRING);
comp1sfc3.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp1sfc3.setValue("$f3");
comp1sfc3.setOperator("==");
comp.addConstraint(comp1sfc3);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field3 == \"goo\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { null, null, "goo" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testCompositeFactPatternSecondValue.
@Test
public void testCompositeFactPatternSecondValue() {
TemplateModel m = new TemplateModel();
m.name = "t1";
CompositeFactPattern cp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_OR);
FactPattern p1 = new FactPattern("Person");
SingleFieldConstraint sfc1 = new SingleFieldConstraint();
sfc1.setFieldName("field1");
sfc1.setFieldType(DataType.TYPE_STRING);
sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc1.setValue("$f1");
sfc1.setOperator("==");
p1.addConstraint(sfc1);
FactPattern p2 = new FactPattern("Person");
SingleFieldConstraint sfc2 = new SingleFieldConstraint();
sfc2.setFieldName("field2");
sfc2.setFieldType(DataType.TYPE_STRING);
sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc2.setValue("$f2");
sfc2.setOperator("==");
p2.addConstraint(sfc2);
cp.addFactPattern(p1);
cp.addFactPattern(p2);
m.addLhsItem(cp);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "(\n" + "Person( )\n" + "or\n" + "Person( field2 == \"bar\" )\n" + ")\n" + "then\n" + "end\n";
m.addRow(new String[] { null, "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint 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);
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testSimpleFromCollectMultipleSubPatternValues.
@Test
public void testSimpleFromCollectMultipleSubPatternValues() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FactPattern fp = new FactPattern("Person");
SingleFieldConstraint sfc = new SingleFieldConstraint("field1");
sfc.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc.setFieldType(DataType.TYPE_STRING);
sfc.setOperator("==");
sfc.setValue("$f1");
fp.addConstraint(sfc);
SingleFieldConstraint sfc1 = new SingleFieldConstraint("field2");
sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc1.setFieldType(DataType.TYPE_STRING);
sfc1.setOperator("==");
sfc1.setValue("$f2");
fp.addConstraint(sfc1);
FactPattern fp2 = new FactPattern("java.util.List");
SingleFieldConstraint sfc2 = new SingleFieldConstraint("size");
sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
sfc2.setOperator(">");
sfc2.setValue("$f3");
fp2.addConstraint(sfc2);
FromCollectCompositeFactPattern fac = new FromCollectCompositeFactPattern();
fac.setRightPattern(fp);
fac.setFactPattern(fp2);
m.addLhsItem(fac);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "java.util.List( size > 1 ) from collect ( Person( field1 == \"foo\", field2 == \"bar\" ) ) \n" + "then\n" + "end";
m.addRow(new String[] { "1", "foo", "bar" });
checkMarshall(expected, m);
}
Aggregations