Search in sources :

Example 56 with CompositeFieldConstraint

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

the class RuleModelDRLPersistenceUnmarshallingTest method testReciprocal_CompositeFactPatternWithOrAndCompositeFieldConstraint.

@Test
public void testReciprocal_CompositeFactPatternWithOrAndCompositeFieldConstraint() {
    // This is the inverse of "CompositeFactPatternWithOrAndCompositeFieldConstraint"
    String drl = "rule \"rule1\"\n" + "dialect \"mvel\"\n" + "when\n" + "( Person( age == 42 ) or Person( age == 43 || age == 44) )\n" + "then\n" + "end";
    RuleModel m = new RuleModel();
    m.name = "rule1";
    // LHS Pattern
    CompositeFactPattern cfp = new CompositeFactPattern();
    cfp.setType(CompositeFactPattern.COMPOSITE_TYPE_OR);
    // LHS sub-patterns
    FactPattern fp1 = new FactPattern();
    fp1.setFactType("Person");
    SingleFieldConstraint fp1_sfp1 = new SingleFieldConstraint();
    fp1_sfp1.setFactType("Person");
    fp1_sfp1.setFieldName("age");
    fp1_sfp1.setOperator("==");
    fp1_sfp1.setValue("42");
    fp1_sfp1.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    fp1_sfp1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    fp1.addConstraint(fp1_sfp1);
    FactPattern fp2 = new FactPattern();
    fp2.setFactType("Person");
    CompositeFieldConstraint fp2_cfp = new CompositeFieldConstraint();
    fp2_cfp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    fp2.addConstraint(fp2_cfp);
    SingleFieldConstraint fp2_sfp1 = new SingleFieldConstraint();
    fp2_sfp1.setFactType("Person");
    fp2_sfp1.setFieldName("age");
    fp2_sfp1.setOperator("==");
    fp2_sfp1.setValue("43");
    fp2_sfp1.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    fp2_sfp1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    fp2_cfp.addConstraint(fp2_sfp1);
    SingleFieldConstraint fp2_sfp2 = new SingleFieldConstraint();
    fp2_sfp2.setFactType("Person");
    fp2_sfp2.setFieldName("age");
    fp2_sfp2.setOperator("==");
    fp2_sfp2.setValue("44");
    fp2_sfp2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    fp2_sfp2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    fp2_cfp.addConstraint(fp2_sfp2);
    cfp.addFactPattern(fp1);
    cfp.addFactPattern(fp2);
    m.addLhsItem(cfp);
    String actualDrl = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    assertEqualsIgnoreWhitespace(drl, actualDrl);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) 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) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Example 57 with CompositeFieldConstraint

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

the class GuidedRuleModelVisitor method visitCompositeFieldConstraint.

private Set<String> visitCompositeFieldConstraint(CompositeFieldConstraint cfc) {
    final Set<String> factTypes = new HashSet<String>();
    if (cfc.getConstraints() != null) {
        for (int i = 0; i < cfc.getConstraints().length; i++) {
            FieldConstraint fc = cfc.getConstraints()[i];
            factTypes.addAll(visit(fc));
        }
    }
    return factTypes;
}
Also used : ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) HashSet(java.util.HashSet) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)

Aggregations

CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)57 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)56 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)49 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)49 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)49 Test (org.junit.Test)49 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)47 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)34 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)16 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)15 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)14 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)9 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)7 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)7 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)5 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)4 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2