Search in sources :

Example 11 with FromCompositeFactPattern

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

the class GuidedRuleEditorValidatorTest method testMissingValueInFrom.

@Test
public void testMissingValueInFrom() throws Exception {
    FactPattern boundPattern = new FactPattern("Person");
    boundPattern.setBoundName("person");
    boundPattern.addConstraint(new SingleFieldConstraint("addresses"));
    FactPattern pattern = new FactPattern("Address");
    SingleFieldConstraint constraint = new SingleFieldConstraint("street");
    constraint.setOperator("!=");
    pattern.addConstraint(constraint);
    FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern();
    fromCompositeFactPattern.setFactPattern(pattern);
    ExpressionFormLine expression = new ExpressionFormLine();
    expression.setBinding("person.addresses");
    fromCompositeFactPattern.setExpression(expression);
    model.lhs = new IPattern[] { boundPattern, fromCompositeFactPattern };
    assertFalse(validator.isValid());
    assertEquals(1, validator.getErrors().size());
    assertEquals(MISSING_VALUE_WHEN_OPERATOR_IS_SET, validator.getErrors().get(0));
    verify(constants).FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator("Address", "street");
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) 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 12 with FromCompositeFactPattern

use of org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern 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();
}
Also used : 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) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) Test(org.junit.Test)

Example 13 with FromCompositeFactPattern

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

the class GuidedRuleEditorValidatorTest method testWorkingFrom.

@Test
public void testWorkingFrom() throws Exception {
    FactPattern boundPattern = new FactPattern("Person");
    boundPattern.setBoundName("person");
    boundPattern.addConstraint(new SingleFieldConstraint("addresses"));
    FactPattern pattern = new FactPattern("Address");
    SingleFieldConstraint constraint = new SingleFieldConstraint("street");
    pattern.addConstraint(constraint);
    FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern();
    fromCompositeFactPattern.setFactPattern(pattern);
    ExpressionFormLine expression = new ExpressionFormLine();
    expression.setBinding("person.addresses");
    fromCompositeFactPattern.setExpression(expression);
    model.lhs = new IPattern[] { boundPattern, fromCompositeFactPattern };
    assertTrue(validator.isValid());
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) 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 14 with FromCompositeFactPattern

use of org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern 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 15 with FromCompositeFactPattern

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

the class GuidedRuleEditorValidatorTest method testValidFromCompositeFactPattern.

@Test
public void testValidFromCompositeFactPattern() throws Exception {
    FactPattern factPattern = new FactPattern("SomeList");
    factPattern.setBoundName("list");
    FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern();
    fromCompositeFactPattern.setFactPattern(new FactPattern("Person"));
    ExpressionFormLine expression = new ExpressionFormLine();
    expression.appendPart(new ExpressionVariable("list", "SomeList", "SomeList"));
    fromCompositeFactPattern.setExpression(expression);
    model.lhs = new IPattern[] { fromCompositeFactPattern };
    assertTrue(validator.isValid());
}
Also used : ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) 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) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable) Test(org.junit.Test)

Aggregations

FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)29 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)24 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)22 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)22 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)18 Test (org.junit.Test)18 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)15 ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)12 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)11 ExpressionVariable (org.drools.workbench.models.datamodel.rule.ExpressionVariable)10 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)9 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)8 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)7 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 ExpressionText (org.drools.workbench.models.datamodel.rule.ExpressionText)5 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)4 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)4 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)3