Search in sources :

Example 6 with FromAccumulateCompositeFactPattern

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

the class GuidedRuleEditorValidatorTest method testFromAccumulateCompositePatternMissingValuesWithExistingFrom.

@Test
public void testFromAccumulateCompositePatternMissingValuesWithExistingFrom() throws Exception {
    FactPattern pattern1 = new FactPattern("Person");
    SingleFieldConstraint constraint1 = new SingleFieldConstraint("name");
    constraint1.setOperator("==");
    pattern1.addConstraint(constraint1);
    FactPattern pattern2 = new FactPattern("Address");
    SingleFieldConstraint constraint2 = new SingleFieldConstraint("street");
    constraint2.setOperator("!=");
    pattern2.addConstraint(constraint2);
    FromAccumulateCompositeFactPattern fromAccumulateCompositeFactPattern = new FromAccumulateCompositeFactPattern();
    fromAccumulateCompositeFactPattern.setSourcePattern(pattern1);
    fromAccumulateCompositeFactPattern.setFactPattern(pattern2);
    fromAccumulateCompositeFactPattern.setInitCode("int i = 0");
    fromAccumulateCompositeFactPattern.setActionCode(" i++;");
    fromAccumulateCompositeFactPattern.setReverseCode("i--;");
    fromAccumulateCompositeFactPattern.setResultCode("return i");
    model.lhs = new IPattern[] { fromAccumulateCompositeFactPattern };
    assertFalse(validator.isValid());
    assertEquals(2, validator.getErrors().size());
    verify(constants, never()).WhenUsingFromTheSourceNeedsToBeSet();
    verify(constants).FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator("Person", "name");
    verify(constants).FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator("Address", "street");
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) Test(org.junit.Test)

Example 7 with FromAccumulateCompositeFactPattern

use of org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern 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();
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) Widget(com.google.gwt.user.client.ui.Widget) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) Button(org.gwtbootstrap3.client.ui.Button) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 8 with FromAccumulateCompositeFactPattern

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

the class RuleModelDRLPersistenceTest method testFromAccumulateWithEmbeddedFromEntryPoint.

@Test
public void testFromAccumulateWithEmbeddedFromEntryPoint() {
    RuleModel m = new RuleModel();
    m.name = "r1";
    SingleFieldConstraint sfc = new SingleFieldConstraint("bar");
    sfc.setFactType(DataType.TYPE_NUMERIC_INTEGER);
    sfc.setFieldBinding("$a");
    sfc.setOperator("==");
    sfc.setValue("777");
    FactPattern fp = new FactPattern("Foo");
    fp.addConstraint(sfc);
    FromEntryPointFactPattern fep = new FromEntryPointFactPattern();
    fep.setEntryPointName("ep");
    fep.setFactPattern(fp);
    FromAccumulateCompositeFactPattern fac = new FromAccumulateCompositeFactPattern();
    fac.setSourcePattern(fep);
    fac.setFactPattern(new FactPattern("java.util.List"));
    fac.setFunction("max($a)");
    m.addLhsItem(fac);
    String expected = "rule \"r1\"\n" + "dialect \"mvel\"\n" + "when\n" + "java.util.List( ) from accumulate ( Foo( $a : bar == 777 ) from entry-point \"ep\", \n" + "max($a))\n" + "then\n" + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 9 with FromAccumulateCompositeFactPattern

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

the class RuleModelDRLPersistenceUnmarshallingTest method testLHSCustomAccumulateFunctions.

@Test
public // https://bugzilla.redhat.com/show_bug.cgi?id=1136100
void testLHSCustomAccumulateFunctions() throws Exception {
    String drl = "package org.test;\n" + "rule \"test\"\n" + "dialect \"mvel\"\n" + "when\n" + "Double( ) from accumulate ( Applicant( $a : age != null ),\n" + "init( double total = 0; ),\n" + "action( total += $a; ),\n" + "reverse( total -= $a; ),\n" + "result( new Double( total ) ) )\n" + "then\n" + "end";
    addModelField(Double.class.getName(), "this", Double.class.getName(), DataType.TYPE_THIS);
    addModelField("org.test.Applicant", "this", "org.test.Applicant", DataType.TYPE_THIS);
    addModelField("org.test.Applicant", "age", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
    when(dmo.getPackageName()).thenReturn("org.test");
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(1, m.lhs.length);
    assertEquals(0, m.rhs.length);
    assertTrue(m.lhs[0] instanceof FromAccumulateCompositeFactPattern);
    final FromAccumulateCompositeFactPattern facfp = (FromAccumulateCompositeFactPattern) m.lhs[0];
    assertEquals("double total = 0;", facfp.getInitCode());
    assertEquals("total += $a;", facfp.getActionCode());
    assertEquals("total -= $a;", facfp.getReverseCode());
    assertEquals("new Double( total )", facfp.getResultCode());
    assertNotNull(facfp.getFactPattern());
    final FactPattern fp = facfp.getFactPattern();
    assertEquals("Double", fp.getFactType());
    assertEquals(0, fp.getNumberOfConstraints());
    assertNotNull(facfp.getSourcePattern());
    assertTrue(facfp.getSourcePattern() instanceof FactPattern);
    final FactPattern fsp = (FactPattern) facfp.getSourcePattern();
    assertEquals("Applicant", fsp.getFactType());
    assertEquals(1, fsp.getNumberOfConstraints());
    assertTrue(fsp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint sfc = (SingleFieldConstraint) fsp.getConstraint(0);
    assertEquals("$a", sfc.getFieldBinding());
    assertEquals("Applicant", sfc.getFactType());
    assertEquals("!= null", sfc.getOperator());
    assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 10 with FromAccumulateCompositeFactPattern

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

the class RuleModelCloneVisitorTest method buildFromAccumulateCompositeFactPattern.

private static FromAccumulateCompositeFactPattern buildFromAccumulateCompositeFactPattern() {
    FromAccumulateCompositeFactPattern facc = new FromAccumulateCompositeFactPattern();
    facc.setActionCode("action code; ");
    facc.setExpression(buildExpressionFormLine());
    facc.setFactPattern(buildFactPattern());
    facc.setFunction("function;");
    facc.setInitCode("setPlugin code;");
    facc.setResultCode("result code;");
    facc.setReverseCode("reverse code;");
    facc.setSourcePattern(buildExpressionFormLine());
    return facc;
}
Also used : FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)

Aggregations

FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)17 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)15 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)15 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)14 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)12 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)10 Test (org.junit.Test)8 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)6 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)6 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)5 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)5 Widget (com.google.gwt.user.client.ui.Widget)5 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)4 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)4 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)4 Button (org.gwtbootstrap3.client.ui.Button)3 ListBox (org.gwtbootstrap3.client.ui.ListBox)3 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)3 FormStylePopup (org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup)3 Command (com.google.gwt.user.client.Command)2