Search in sources :

Example 1 with CEPWindow

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

the class RuleModelDRLPersistenceUnmarshallingTest method testSingleFieldConstraintCEPOperatorTimeWindow.

@Test
public void testSingleFieldConstraintCEPOperatorTimeWindow() {
    String drl = "rule \"rule1\"\n" + "when\n" + "Event() over window:time (1d)\n" + "then\n" + "end";
    RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals("rule1", m.name);
    assertEquals(1, m.lhs.length);
    IPattern p1 = m.lhs[0];
    assertTrue(p1 instanceof FactPattern);
    FactPattern fp1 = (FactPattern) p1;
    assertEquals("Event", fp1.getFactType());
    assertNull(fp1.getBoundName());
    assertEquals(0, fp1.getNumberOfConstraints());
    assertNotNull(fp1.getWindow());
    CEPWindow window = fp1.getWindow();
    assertEquals("over window:time", window.getOperator());
    assertEquals(2, window.getParameters().size());
    assertEquals("1d", window.getParameter("1"));
    assertEquals("org.drools.workbench.models.commons.backend.rule.CEPWindowOperatorParameterDRLBuilder", window.getParameter("org.drools.workbench.models.commons.backend.rule.operatorParameterGenerator"));
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) CEPWindow(org.drools.workbench.models.datamodel.rule.CEPWindow) 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 2 with CEPWindow

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

the class ValueOptionsPage method newCEPWindowOperatorsDropdown.

private CEPWindowOperatorsDropdown newCEPWindowOperatorsDropdown() {
    final Pattern52 editingPattern = editingPattern();
    return new CEPWindowOperatorsDropdown(editingPattern, false) {

        {
            addValueChangeHandler(event -> {
                final CEPWindow cepWindow = editingPattern.getWindow();
                final String operator = event.getValue().getValue();
                cepWindow.setOperator(operator);
            });
        }
    };
}
Also used : CEPWindowOperatorsDropdown(org.drools.workbench.screens.guided.rule.client.editor.CEPWindowOperatorsDropdown) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) CEPWindow(org.drools.workbench.models.datamodel.rule.CEPWindow)

Example 3 with CEPWindow

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

the class RuleModelCloneVisitorTest method buildFactPattern.

private static FactPattern buildFactPattern() {
    FactPattern fp = new FactPattern();
    fp.setBoundName("$f");
    fp.setFactType("FactType");
    fp.setNegated(true);
    CEPWindow win = new CEPWindow();
    win.setOperator("winOp");
    win.setParameter("winKey", "winPar");
    fp.setWindow(win);
    fp.addConstraint(buildSingleFieldConstraint());
    return fp;
}
Also used : CEPWindow(org.drools.workbench.models.datamodel.rule.CEPWindow) IFactPattern(org.drools.workbench.models.datamodel.rule.IFactPattern) 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)

Example 4 with CEPWindow

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

the class RuleModelDRLPersistenceImpl method getFactPattern.

private FactPattern getFactPattern(final RuleModel m, final PatternDescr pattern, final boolean isJavaDialect, final Map<String, String> boundParams, final PackageDataModelOracle dmo) {
    String type = pattern.getObjectType();
    FactPattern factPattern = new FactPattern(getSimpleFactType(type, dmo));
    if (pattern.getIdentifier() != null) {
        String identifier = pattern.getIdentifier();
        factPattern.setBoundName(identifier);
        boundParams.put(identifier, type);
    }
    parseConstraint(m, factPattern, pattern.getConstraint(), isJavaDialect, boundParams, dmo);
    for (BehaviorDescr behavior : pattern.getBehaviors()) {
        if (behavior.getText().equals("window")) {
            CEPWindow window = new CEPWindow();
            window.setOperator("over window:" + behavior.getSubType());
            window.setParameter("org.drools.workbench.models.commons.backend.rule.operatorParameterGenerator", "org.drools.workbench.models.commons.backend.rule.CEPWindowOperatorParameterDRLBuilder");
            List<String> params = behavior.getParameters();
            if (params != null) {
                int i = 1;
                for (String param : params) {
                    window.setParameter("" + i++, param);
                }
            }
            factPattern.setWindow(window);
        }
    }
    return factPattern;
}
Also used : CEPWindow(org.drools.workbench.models.datamodel.rule.CEPWindow) BehaviorDescr(org.drools.compiler.lang.descr.BehaviorDescr) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) 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) IFactPattern(org.drools.workbench.models.datamodel.rule.IFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 5 with CEPWindow

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

the class Pattern52Test method testDiffAll.

@Test
public void testDiffAll() {
    column1.setFactType("Fact1");
    column1.setBoundName("$var1");
    column1.setNegated(false);
    CEPWindow window1 = new CEPWindow();
    window1.setOperator("dummyOp1");
    column1.setWindow(window1);
    column1.setEntryPointName("entryPoint1");
    column2.setFactType("Fact2");
    column2.setBoundName("$var2");
    column2.setNegated(true);
    CEPWindow window2 = new CEPWindow();
    window2.setOperator("dummyOp2");
    column2.setWindow(window2);
    column2.setEntryPointName("entryPoint2");
    List<BaseColumnFieldDiff> diff = column1.diff(column2);
    assertNotNull(diff);
    assertEquals(5, diff.size());
    assertEquals(FIELD_FACT_TYPE, diff.get(0).getFieldName());
    assertEquals("Fact1", diff.get(0).getOldValue());
    assertEquals("Fact2", diff.get(0).getValue());
    assertEquals(FIELD_BOUND_NAME, diff.get(1).getFieldName());
    assertEquals("$var1", diff.get(1).getOldValue());
    assertEquals("$var2", diff.get(1).getValue());
    assertEquals(FIELD_IS_NEGATED, diff.get(2).getFieldName());
    assertEquals(false, diff.get(2).getOldValue());
    assertEquals(true, diff.get(2).getValue());
    assertEquals(FIELD_WINDOW, diff.get(3).getFieldName());
    assertEquals(window1, diff.get(3).getOldValue());
    assertEquals(window2, diff.get(3).getValue());
    assertEquals(FIELD_ENTRY_POINT_NAME, diff.get(4).getFieldName());
    assertEquals("entryPoint1", diff.get(4).getOldValue());
    assertEquals("entryPoint2", diff.get(4).getValue());
}
Also used : CEPWindow(org.drools.workbench.models.datamodel.rule.CEPWindow) Test(org.junit.Test)

Aggregations

CEPWindow (org.drools.workbench.models.datamodel.rule.CEPWindow)11 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)7 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)7 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)7 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)7 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)7 Test (org.junit.Test)6 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)4 IFactPattern (org.drools.workbench.models.datamodel.rule.IFactPattern)3 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)2 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)2 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)2 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)2 BehaviorDescr (org.drools.compiler.lang.descr.BehaviorDescr)1 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)1 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)1 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)1 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)1 CEPWindowOperatorsDropdown (org.drools.workbench.screens.guided.rule.client.editor.CEPWindowOperatorsDropdown)1 Before (org.junit.Before)1