use of org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern in project drools-wb by kiegroup.
the class FromAccumulateCompositeFactPatternWidget method showSourcePatternSelector.
/**
* Pops up the fact selector.
*/
protected void showSourcePatternSelector() {
final ListBox box = new ListBox();
AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
String[] facts = oracle.getFactTypes();
box.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
for (int i = 0; i < facts.length; i++) {
box.addItem(facts[i]);
}
box.setSelectedIndex(0);
final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorResources.CONSTANTS.NewFactPattern());
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.chooseFactType(), box);
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
getFromAccumulatePattern().setSourcePattern(new FactPattern(box.getItemText(box.getSelectedIndex())));
setModified(true);
getModeller().refreshWidget();
popup.hide();
}
});
final Button fromBtn = new Button(HumanReadableConstants.INSTANCE.From());
final Button fromAccumulateBtn = new Button(HumanReadableConstants.INSTANCE.FromAccumulate());
final Button fromCollectBtn = new Button(HumanReadableConstants.INSTANCE.FromCollect());
final Button fromEntryPointBtn = new Button(HumanReadableConstants.INSTANCE.FromEntryPoint());
ClickHandler btnsClickHandler = new ClickHandler() {
public void onClick(ClickEvent event) {
Widget sender = (Widget) event.getSource();
if (sender == fromBtn) {
getFromAccumulatePattern().setSourcePattern(new FromCompositeFactPattern());
} else if (sender == fromAccumulateBtn) {
getFromAccumulatePattern().setSourcePattern(new FromAccumulateCompositeFactPattern());
} else if (sender == fromCollectBtn) {
getFromAccumulatePattern().setSourcePattern(new FromCollectCompositeFactPattern());
} else if (sender == fromEntryPointBtn) {
getFromAccumulatePattern().setSourcePattern(new FromEntryPointFactPattern());
} else {
throw new IllegalArgumentException("Unknown sender: " + sender);
}
setModified(true);
getModeller().refreshWidget();
popup.hide();
}
};
fromBtn.addClickHandler(btnsClickHandler);
fromAccumulateBtn.addClickHandler(btnsClickHandler);
fromCollectBtn.addClickHandler(btnsClickHandler);
fromEntryPointBtn.addClickHandler(btnsClickHandler);
popup.addAttribute("", fromBtn);
popup.addAttribute("", fromAccumulateBtn);
popup.addAttribute("", fromCollectBtn);
popup.addAttribute("", fromEntryPointBtn);
popup.show();
}
use of org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern in project drools-wb by kiegroup.
the class GuidedRuleEditorValidatorTest method testMissingFactTypeInFromCollect.
@Test
public void testMissingFactTypeInFromCollect() throws Exception {
FromCollectCompositeFactPattern fromCompositeFactPattern = new FromCollectCompositeFactPattern();
fromCompositeFactPattern.setRightPattern(new FactPattern("Person"));
model.lhs = new IPattern[] { fromCompositeFactPattern };
assertFalse(validator.isValid());
assertEquals(1, validator.getErrors().size());
assertEquals(MISSING_FACT_PATTERN, validator.getErrors().get(0));
verify(constants).AreasMarkedWithRedAreMandatoryPleaseSetAValueBeforeSaving();
}
use of org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testSimpleFromCollectFirstValue.
@Test
public void testSimpleFromCollectFirstValue() {
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);
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("$f2");
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( ) )\n" + "then\n" + "end";
m.addRow(new String[] { "1", null });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testSimpleFromCollectSecondValue.
@Test
public void testSimpleFromCollectSecondValue() {
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);
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("$f2");
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() from collect ( Person( field1 == \"foo\" ) )" + "then\n" + "end";
m.addRow(new String[] { null, "foo" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testFromCollectFreeFormLineSecondValue.
@Test
public void testFromCollectFreeFormLineSecondValue() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FreeFormLine ffl = new FreeFormLine();
ffl.setText("Person( field1 == \"@{f1}\", field2 == \"@{f2}\" )");
FactPattern fp = new FactPattern("java.util.List");
FromCollectCompositeFactPattern fac = new FromCollectCompositeFactPattern();
fac.setRightPattern(ffl);
fac.setFactPattern(fp);
m.addLhsItem(fac);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "then\n" + "end";
m.addRow(new String[] { null, "foo" });
checkMarshall(expected, m);
}
Aggregations