Search in sources :

Example 11 with SingleFieldConstraintEBLeftSide

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

the class GuidedDecisionTreeModelUnmarshallingVisitor method visit.

private List<Node> visit(final FieldConstraint fc, final GuidedDecisionTree model, final PackageDataModelOracle dmo, final List<ParserMessage> messages) {
    final List<Node> nodes = new ArrayList<Node>();
    if (fc instanceof CompositeFieldConstraint) {
        messages.add(new UnsupportedFieldConstraintParserMessage());
        return nodes;
    } else if (fc instanceof SingleFieldConstraintEBLeftSide) {
        messages.add(new UnsupportedFieldConstraintParserMessage());
        return nodes;
    }
    if (!(fc instanceof SingleFieldConstraint)) {
        messages.add(new UnsupportedFieldConstraintParserMessage());
        return nodes;
    }
    final SingleFieldConstraint sfc = (SingleFieldConstraint) fc;
    if (sfc.getConnectives() != null) {
        messages.add(new UnsupportedFieldConstraintParserMessage());
        return nodes;
    }
    ConstraintNode node = null;
    final String className = sfc.getFactType();
    final String fieldName = sfc.getFieldName();
    if (sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_LITERAL) {
        final String operator = sfc.getOperator();
        final boolean isValueRequired = OperatorsOracle.isValueRequired(operator);
        if (isValueRequired) {
            final Value value = getValue(className, fieldName, model, dmo, messages, sfc.getValue());
            if (value != null) {
                node = new ConstraintNodeImpl(className, fieldName, operator, value);
            }
        } else {
            node = new ConstraintNodeImpl(className, fieldName);
        }
    } else if (sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_ENUM) {
        final String operator = sfc.getOperator();
        final boolean isValueRequired = OperatorsOracle.isValueRequired(operator);
        if (isValueRequired) {
            final Value value = getValue(className, fieldName, model, dmo, messages, sfc.getValue());
            if (value != null) {
                node = new ConstraintNodeImpl(className, fieldName, operator, value);
            }
        } else {
            node = new ConstraintNodeImpl(className, fieldName);
        }
    } else if (sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_UNDEFINED) {
        final String operator = sfc.getOperator();
        final boolean isValueRequired = OperatorsOracle.isValueRequired(operator);
        if (isValueRequired) {
            node = new ConstraintNodeImpl(className, fieldName);
        } else {
            node = new ConstraintNodeImpl(className, fieldName, operator, null);
        }
    } else {
        messages.add(new UnsupportedFieldConstraintTypeParserMessage());
        return nodes;
    }
    if (node != null) {
        if (sfc.isBound()) {
            node.setBinding(sfc.getFieldBinding());
        }
        nodes.add(node);
    }
    return nodes;
}
Also used : ConstraintNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ArrayList(java.util.ArrayList) UnsupportedFieldConstraintTypeParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldConstraintTypeParserMessage) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) UnsupportedFieldConstraintParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldConstraintParserMessage) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ShortValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.ShortValue) StringValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue) FloatValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.FloatValue) BigDecimalValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigDecimalValue) ByteValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.ByteValue) Value(org.drools.workbench.models.guided.dtree.shared.model.values.Value) DoubleValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.DoubleValue) IntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue) DateValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue) BooleanValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BooleanValue) BigIntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue) LongValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.LongValue) ActionFieldValue(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue) EnumValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.EnumValue)

Example 12 with SingleFieldConstraintEBLeftSide

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

the class RuleModelCloneVisitorTest method buildSingleFieldConstraintEBLeftSide.

private static SingleFieldConstraintEBLeftSide buildSingleFieldConstraintEBLeftSide() {
    SingleFieldConstraintEBLeftSide sfc = new SingleFieldConstraintEBLeftSide();
    sfc.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    sfc.setExpressionValue(buildExpressionFormLine());
    sfc.setExpressionLeftSide(buildExpressionFormLine());
    sfc.setFactType("FactType");
    // do not set fieldBinding, fieldName and fieldType, these are computed from expressionLeftSide
    sfc.setId("id");
    sfc.setOperator("operator");
    sfc.setParameter("key", "parameter");
    sfc.setParent(new SingleFieldConstraint("parentFieldName"));
    sfc.setValue("value");
    sfc.addNewConnective();
    return sfc;
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 13 with SingleFieldConstraintEBLeftSide

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

the class PopupCreatorTest method testOnExpressionEditorButtonClick.

@Test
public void testOnExpressionEditorButtonClick() {
    final String factType = "factType";
    final FactPattern factPattern = mock(FactPattern.class);
    final HasConstraints hasConstraints = mock(HasConstraints.class);
    final FormStylePopup popup = mock(FormStylePopup.class);
    final SingleFieldConstraintEBLeftSide constraint = mock(SingleFieldConstraintEBLeftSide.class);
    final RuleModeller ruleModeller = mock(RuleModeller.class);
    final ClickEvent clickEvent = mock(ClickEvent.class);
    doReturn(factType).when(factPattern).getFactType();
    doReturn(constraint).when(popupCreator).makeSingleFieldConstraintEBLeftSide(factType);
    doReturn(ruleModeller).when(popupCreator).getModeller();
    doReturn(factPattern).when(popupCreator).getPattern();
    final ClickHandler clickHandler = popupCreator.onExpressionEditorButtonClick(hasConstraints, popup);
    clickHandler.onClick(clickEvent);
    verify(hasConstraints).addConstraint(constraint);
    verify(ruleModeller).refreshWidget();
    verify(popup).hide();
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) RuleModeller(org.drools.workbench.screens.guided.rule.client.editor.RuleModeller) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) HasConstraints(org.drools.workbench.models.datamodel.rule.HasConstraints) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) Test(org.junit.Test)

Example 14 with SingleFieldConstraintEBLeftSide

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

the class FactPatternWidget method renderSingleFieldConstraint.

/**
 * Applies a single field constraint to the given table, and start row.
 */
private void renderSingleFieldConstraint(final FlexTable inner, final int row, final SingleFieldConstraint constraint, final HasConstraints hasConstraints, boolean showBinding, final int tabs) {
    // for offsetting, just a slight indent
    final int col = 1;
    inner.setWidget(row, 0, new HTML("&nbsp;&nbsp;&nbsp;&nbsp;"));
    if (constraint.getConstraintValueType() != SingleFieldConstraint.TYPE_PREDICATE) {
        HorizontalPanel ebContainer = null;
        if (constraint instanceof SingleFieldConstraintEBLeftSide) {
            ebContainer = expressionBuilderLS((SingleFieldConstraintEBLeftSide) constraint, showBinding);
            inner.setWidget(row, 0 + col, ebContainer);
        } else {
            inner.setWidget(row, 0 + col, fieldLabel(constraint, hasConstraints, showBinding, tabs * 20));
        }
        inner.setWidget(row, 1 + col, operatorDropDown(constraint, inner, row, 2 + col));
        // Get first part of constraint.fieldName? #1=Fact1, #2=SubFact1
        inner.setWidget(row, 2 + col, createValueEditor(constraint));
        inner.setWidget(row, 3 + col, getConnectives().connectives(constraint));
        if (ebContainer != null && ebContainer.getWidgetCount() > 0) {
            if (ebContainer.getWidget(0) instanceof ExpressionBuilder) {
                associateExpressionWithChangeHandler(inner, row, constraint, col, ebContainer);
            }
        }
    } else if (constraint.getConstraintValueType() == SingleFieldConstraint.TYPE_PREDICATE) {
        inner.setWidget(row, 1, predicateEditor(constraint));
        inner.getFlexCellFormatter().setColSpan(row, 1, 5);
    }
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) HTML(com.google.gwt.user.client.ui.HTML) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)

Example 15 with SingleFieldConstraintEBLeftSide

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

the class RuleModelDRLPersistenceTest method testLHSExpressionString1.

@Test
public void testLHSExpressionString1() {
    RuleModel m = new RuleModel();
    m.name = "test expressionsString1";
    FactPattern p = new FactPattern("Person");
    SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide();
    con.getExpressionLeftSide().appendPart(new ExpressionText("field1"));
    con.setOperator("==");
    con.setValue("goo");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con);
    m.addLhsItem(p);
    String expected = "rule \"test expressionsString1\"" + "\tdialect \"mvel\"\n when " + "     Person( field1 == \"goo\" )" + " then " + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) 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) ExpressionText(org.drools.workbench.models.datamodel.rule.ExpressionText) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Aggregations

SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)37 Test (org.junit.Test)31 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)30 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)29 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)29 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)29 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)28 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)28 ExpressionUnboundFact (org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact)24 ExpressionField (org.drools.workbench.models.datamodel.rule.ExpressionField)21 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)13 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)10 ExpressionMethod (org.drools.workbench.models.datamodel.rule.ExpressionMethod)7 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)6 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)3 ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)3 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)3 List (java.util.List)2