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"));
}
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);
});
}
};
}
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;
}
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;
}
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());
}
Aggregations