use of org.drools.workbench.models.datamodel.rule.DSLSentence in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingTest method testDSL.
@Test
public void testDSL() {
String drl = "package org.mortgages;\n" + "rule \"testdsl\"\n" + " dialect \"mvel\"\n" + " when\n" + " There is a test rated applicant older than 111 years\n" + " then\n" + "end";
String dslDefinition = "There is a {rating} rated applicant older than {age} years";
String dslFile = "[when]" + dslDefinition + "= Applicant( creditRating == \"{rating}\", age > {age} )";
when(dmo.getPackageName()).thenReturn("org.mortgages");
final RuleModel model = RuleModelDRLPersistenceImpl.getInstance().unmarshalUsingDSL(drl, Collections.emptyList(), dmo, dslFile);
assertEquals(1, model.lhs.length);
DSLSentence dslSentence = (DSLSentence) model.lhs[0];
assertEquals("Applicant( creditRating == \"{rating}\", age > {age} )", dslSentence.getDrl());
assertEquals("test", dslSentence.getValues().get(0).getValue());
assertEquals("111", dslSentence.getValues().get(1).getValue());
}
use of org.drools.workbench.models.datamodel.rule.DSLSentence in project drools-wb by kiegroup.
the class RuleModellerConditionSelectorPopup method addDSLSentences.
// The list of DSL sentences
private void addDSLSentences() {
// DSL might be prohibited (e.g. editing a DRL file. Only DSLR files can contain DSL)
if (!ruleModeller.isDSLEnabled()) {
return;
}
for (final DSLSentence sen : oracle.getDSLConditions()) {
final String sentence = sen.toString();
final String key = "DSL" + sentence;
choices.addItem(sentence, key);
cmds.put(key, new Command() {
public void execute() {
addNewDSLLhs(sen, Integer.parseInt(positionCbo.getValue(positionCbo.getSelectedIndex())));
hide();
}
});
}
}
use of org.drools.workbench.models.datamodel.rule.DSLSentence in project drools-wb by kiegroup.
the class RuleModellerWidgetFactory method getWidget.
public RuleModellerWidget getWidget(RuleModeller ruleModeller, EventBus eventBus, IAction action, Boolean readOnly) {
if (action instanceof ActionCallMethod) {
return new ActionCallMethodWidget(ruleModeller, eventBus, (ActionCallMethod) action, readOnly);
}
if (action instanceof ActionSetField) {
return new ActionSetFieldWidget(ruleModeller, eventBus, (ActionSetField) action, readOnly);
}
if (action instanceof ActionInsertFact) {
return new ActionInsertFactWidget(ruleModeller, eventBus, (ActionInsertFact) action, readOnly);
}
if (action instanceof ActionRetractFact) {
return new ActionRetractFactWidget(ruleModeller, eventBus, (ActionRetractFact) action, readOnly);
}
if (action instanceof DSLSentence) {
RuleModellerWidget w = new DSLSentenceWidget(ruleModeller, eventBus, (DSLSentence) action, readOnly);
return w;
}
if (action instanceof FreeFormLine) {
return new FreeFormLineWidget(ruleModeller, eventBus, (FreeFormLine) action, readOnly);
}
if (action instanceof ActionGlobalCollectionAdd) {
return new GlobalCollectionAddWidget(ruleModeller, eventBus, (ActionGlobalCollectionAdd) action, readOnly);
}
// All hardcoded action widgets have been checked, perform a plugin lookup
List<RuleModellerActionPlugin> matchingActionPlugins = actionPlugins.stream().filter(p -> p.accept(action)).collect(Collectors.toList());
if (matchingActionPlugins.size() > 1) {
throw new IllegalStateException("Ambigious " + RuleModellerActionPlugin.class.getName() + " implementations for action " + action);
}
if (matchingActionPlugins.size() == 1) {
RuleModellerActionPlugin actionPlugin = matchingActionPlugins.get(0);
RuleModellerWidget ruleModellerWidget = actionPlugin.createWidget(ruleModeller, eventBus, action, readOnly);
return ruleModellerWidget;
}
// NON-NLS
throw new RuntimeException("I don't know what type of action is: " + action);
}
use of org.drools.workbench.models.datamodel.rule.DSLSentence in project drools-wb by kiegroup.
the class RuleModellerActionSelectorPopup method addDSLSentences.
// Add DSL sentences
void addDSLSentences() {
// DSL might be prohibited (e.g. editing a DRL file. Only DSLR files can contain DSL)
if (!ruleModeller.isDSLEnabled()) {
return;
}
for (final DSLSentence sen : oracle.getDSLActions()) {
final String sentence = sen.toString();
final String key = "DSL" + sentence;
choices.addItem(sentence, key);
cmds.put(key, new Command() {
public void execute() {
addNewDSLRhs(sen, Integer.parseInt(positionCbo.getValue(positionCbo.getSelectedIndex())));
hide();
}
});
}
}
Aggregations