Search in sources :

Example 81 with SingleFieldConstraint

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

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

the class BRLRuleModelTest method assertThereIsAFieldBindingFor.

private void assertThereIsAFieldBindingFor(final String fieldBinding) {
    final SingleFieldConstraint sfc = rm.getLHSBoundField(fieldBinding);
    assertNotNull(sfc);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)

Example 83 with SingleFieldConstraint

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

the class BaseBRLTest method whenBRLFactPatternHasAField.

protected SingleFieldConstraint whenBRLFactPatternHasAField(final BRLConditionColumn brl, final String fieldName, final String fieldType, final String fieldBinding) {
    assertFalse("BRLConditionColumn has not been initialised. Was 'whenThereIsABRLFactPattern' called?", brl.getDefinition().isEmpty());
    assertEquals("BRLConditionColumn has not been initialised correctly. Was 'whenThereIsABRLFactPattern' called?", 1, brl.getDefinition().size());
    assertTrue("BRLConditionColumn has not been initialised correctly. Was 'whenThereIsABRLFactPattern' called?", brl.getDefinition().get(0) instanceof FactPattern);
    final FactPattern fp = (FactPattern) brl.getDefinition().get(0);
    final SingleFieldConstraint sfc = new SingleFieldConstraint();
    sfc.setFactType(fp.getFactType());
    sfc.setFieldName(fieldName);
    sfc.setFieldType(fieldType);
    sfc.setFieldBinding(fieldBinding);
    fp.addConstraint(sfc);
    brl.getDefinition().add(fp);
    return sfc;
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern)

Example 84 with SingleFieldConstraint

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()));
    }
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint)

Example 85 with SingleFieldConstraint

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);
}
Also used : BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Aggregations

SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)278 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)250 Test (org.junit.Test)242 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)236 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)218 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)199 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)148 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)142 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)138 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)73 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)65 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)64 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)62 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)28 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)27 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)25 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)23 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)23 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)21 ArrayList (java.util.ArrayList)20