Search in sources :

Example 16 with CompositeFactPattern

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

the class GuidedRuleEditorValidatorTest method testValidateCompositeFactPatternFalse.

@Test
public void testValidateCompositeFactPatternFalse() throws Exception {
    CompositeFactPattern not = new CompositeFactPattern();
    not.setType("not");
    model.addLhsItem(not);
    assertFalse(validator.isValid());
    assertTrue(validator.getErrors().get(0).equals(MISSING_FACT_PATTERN));
}
Also used : 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 17 with CompositeFactPattern

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

the class GuidedRuleEditorValidatorTest method testMissingValueWhenOperatorExistsInCompositePattern.

@Test
public void testMissingValueWhenOperatorExistsInCompositePattern() throws Exception {
    FactPattern pattern = new FactPattern("Person");
    SingleFieldConstraint constraint = new SingleFieldConstraint("age");
    constraint.setOperator("==");
    pattern.addConstraint(constraint);
    CompositeFactPattern not = new CompositeFactPattern();
    not.setType("not");
    not.addFactPattern(pattern);
    model.lhs = new IPattern[] { not };
    assertFalse(validator.isValid());
    assertEquals(1, validator.getErrors().size());
    assertEquals(MISSING_VALUE_WHEN_OPERATOR_IS_SET, validator.getErrors().get(0));
    verify(constants).FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator("Person", "age");
}
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) 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) 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 18 with CompositeFactPattern

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

the class RuleModelDRLPersistenceImpl method parseExistentialElementDescr.

private CompositeFactPattern parseExistentialElementDescr(final RuleModel m, final ConditionalElementDescr conditionalDescr, final boolean isJavaDialect, final Map<String, String> boundParams, final PackageDataModelOracle dmo) {
    CompositeFactPattern comp;
    if (conditionalDescr instanceof NotDescr) {
        comp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_NOT);
    } else if (conditionalDescr instanceof OrDescr) {
        comp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_OR);
    } else if (conditionalDescr instanceof ExistsDescr) {
        comp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_EXISTS);
    } else {
        throw new IllegalArgumentException("Unknown conditional descr type: " + conditionalDescr);
    }
    addPatternToComposite(m, conditionalDescr, comp, isJavaDialect, boundParams, dmo);
    IFactPattern[] patterns = comp.getPatterns();
    return patterns != null && patterns.length > 0 ? comp : null;
}
Also used : NotDescr(org.drools.compiler.lang.descr.NotDescr) ExistsDescr(org.drools.compiler.lang.descr.ExistsDescr) 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) OrDescr(org.drools.compiler.lang.descr.OrDescr) IFactPattern(org.drools.workbench.models.datamodel.rule.IFactPattern)

Example 19 with CompositeFactPattern

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

the class RuleModelDRLPersistenceTest method testOrComposite.

@Test
public void testOrComposite() throws Exception {
    RuleModel m = new RuleModel();
    m.name = "or";
    CompositeFactPattern cp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_OR);
    FactPattern p1 = new FactPattern("Person");
    SingleFieldConstraint sf1 = new SingleFieldConstraint("age");
    sf1.setOperator("==");
    sf1.setValue("42");
    p1.addConstraint(sf1);
    cp.addFactPattern(p1);
    FactPattern p2 = new FactPattern("Person");
    SingleFieldConstraint sf2 = new SingleFieldConstraint("age");
    sf2.setOperator("==");
    sf2.setValue("43");
    p2.addConstraint(sf2);
    cp.addFactPattern(p2);
    m.addLhsItem(cp);
    String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    assertTrue(result.indexOf("( Person( age == 42 ) or Person( age == 43 ) )") > 0);
    checkMarshalling(result, m);
}
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) 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 20 with CompositeFactPattern

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

the class RuleModelDRLPersistenceTest method testSingleExists.

@Test
public void testSingleExists() throws Exception {
    RuleModel m = new RuleModel();
    m.name = "or";
    CompositeFactPattern cp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_EXISTS);
    FactPattern p1 = new FactPattern("Person");
    SingleFieldConstraint sf1 = new SingleFieldConstraint("age");
    sf1.setOperator("==");
    sf1.setValue("42");
    p1.addConstraint(sf1);
    cp.addFactPattern(p1);
    m.addLhsItem(cp);
    String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    logger.debug(result);
    assertTrue(result.indexOf("exists (Person( age == 42 )) ") > 0);
    checkMarshalling(result, m);
}
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) 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)

Aggregations

CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)27 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)23 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)22 Test (org.junit.Test)22 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)21 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)21 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)18 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)16 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)15 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)9 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)4 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)4 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)4 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)3 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)3 DSLSentence (org.drools.workbench.models.datamodel.rule.DSLSentence)3 IFactPattern (org.drools.workbench.models.datamodel.rule.IFactPattern)3 RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)3 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)2 IAction (org.drools.workbench.models.datamodel.rule.IAction)2