Search in sources :

Example 6 with ActionGlobalCollectionAdd

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

the class RuleTemplateModelXMLPersistenceTest method testBasics.

@Test
public void testBasics() {
    final RuleTemplateModelPersistence p = RuleTemplateModelXMLPersistenceImpl.getInstance();
    final TemplateModel m = new TemplateModel();
    m.addLhsItem(new FactPattern("Person"));
    m.addLhsItem(new FactPattern("Accident"));
    m.addAttribute(new RuleAttribute("no-loop", "true"));
    m.addRhsItem(new ActionInsertFact("Report"));
    ActionGlobalCollectionAdd ag = new ActionGlobalCollectionAdd();
    ag.setFactName("x");
    ag.setGlobalName("g");
    m.addRhsItem(ag);
    m.name = "my rule";
    final String xml = p.marshal(m);
    System.out.println(xml);
    assertTrue(xml.indexOf("Person") > -1);
    assertTrue(xml.indexOf("Accident") > -1);
    assertTrue(xml.indexOf("no-loop") > -1);
    assertTrue(xml.indexOf("org.kie") == -1);
    assertTrue(xml.indexOf("addToGlobal") > -1);
    RuleModel rm_ = RuleTemplateModelXMLPersistenceImpl.getInstance().unmarshal(xml);
    assertEquals(2, rm_.rhs.length);
}
Also used : ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 7 with ActionGlobalCollectionAdd

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

the class RuleModelDRLPersistenceTest method testAddToGlobalCollection.

@Test
public void testAddToGlobalCollection() {
    String global = "global java.util.ArrayList list";
    String drl = "rule \"r0\"\n" + "dialect \"mvel\"\n" + "when\n" + "$a : Applicant( )\n" + "then\n" + "list.add( $a );\n" + "end\n";
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Arrays.asList(global), mock(PackageDataModelOracle.class));
    assertNotNull(m);
    assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
    // LHS
    assertEquals(1, m.lhs.length);
    assertTrue(m.lhs[0] instanceof FactPattern);
    final FactPattern p = (FactPattern) m.lhs[0];
    assertEquals("$a", p.getBoundName());
    assertEquals("Applicant", p.getFactType());
    // RHS
    assertEquals(1, m.rhs.length);
    assertTrue(m.rhs[0] instanceof ActionGlobalCollectionAdd);
    final ActionGlobalCollectionAdd a = (ActionGlobalCollectionAdd) m.rhs[0];
    assertEquals("list", a.getGlobalName());
    assertEquals("$a", a.getFactName());
}
Also used : PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) 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) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) Test(org.junit.Test)

Example 8 with ActionGlobalCollectionAdd

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

the class RuleModelDRLPersistenceTest method testAddGlobal.

@Test
public void testAddGlobal() {
    String expected = "rule \"my rule\"\n\tno-loop true\n\tdialect \"mvel\"\n\twhen\n\t\tPerson( )\n" + "\t\tAccident( )\n\tthen\n\t\tinsert( new Report() );\n\t\tresults.add(f);\nend\n";
    final RuleModel m = new RuleModel();
    m.addLhsItem(new FactPattern("Person"));
    m.addLhsItem(new FactPattern("Accident"));
    m.addAttribute(new RuleAttribute("no-loop", "true"));
    m.addRhsItem(new ActionInsertFact("Report"));
    ActionGlobalCollectionAdd add = new ActionGlobalCollectionAdd();
    add.setGlobalName("results");
    add.setFactName("f");
    m.addRhsItem(add);
    m.name = "my rule";
    checkMarshalling(expected, m);
}
Also used : ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) 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) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) Test(org.junit.Test)

Example 9 with ActionGlobalCollectionAdd

use of org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd 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);
}
Also used : ExpressionBuilder(org.drools.workbench.screens.guided.rule.client.widget.ExpressionBuilder) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.CompositeFactPatternWidget) RuleModellerActionPlugin(org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin) FromCompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromCompositeFactPatternWidget) ActionCallMethodWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionCallMethodWidget) ActionInsertFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionInsertFactWidget) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromEntryPointFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromEntryPointFactPatternWidget) PortablePreconditions(org.kie.soup.commons.validation.PortablePreconditions) ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) ActionSetFieldWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionSetFieldWidget) GlobalCollectionAddWidget(org.drools.workbench.screens.guided.rule.client.widget.GlobalCollectionAddWidget) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) IAction(org.drools.workbench.models.datamodel.rule.IAction) EventBus(com.google.gwt.event.shared.EventBus) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) FactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FactPatternWidget) Collection(java.util.Collection) RuleModellerWidget(org.drools.workbench.screens.guided.rule.client.widget.RuleModellerWidget) FreeFormLineWidget(org.drools.workbench.screens.guided.rule.client.widget.FreeFormLineWidget) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) Collectors(java.util.stream.Collectors) FromCollectCompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromCollectCompositeFactPatternWidget) ActionRetractFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionRetractFactWidget) List(java.util.List) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) FromAccumulateCompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromAccumulateCompositeFactPatternWidget) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) DSLSentenceWidget(org.drools.workbench.screens.guided.rule.client.widget.DSLSentenceWidget) Collections(java.util.Collections) GlobalCollectionAddWidget(org.drools.workbench.screens.guided.rule.client.widget.GlobalCollectionAddWidget) RuleModellerActionPlugin(org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) ActionInsertFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionInsertFactWidget) ActionCallMethodWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionCallMethodWidget) RuleModellerWidget(org.drools.workbench.screens.guided.rule.client.widget.RuleModellerWidget) DSLSentenceWidget(org.drools.workbench.screens.guided.rule.client.widget.DSLSentenceWidget) FreeFormLineWidget(org.drools.workbench.screens.guided.rule.client.widget.FreeFormLineWidget) ActionSetFieldWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionSetFieldWidget) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) ActionRetractFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionRetractFactWidget)

Example 10 with ActionGlobalCollectionAdd

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

the class RuleModellerActionSelectorPopup method addGlobalCollections.

// Add global collections
void addGlobalCollections() {
    List<String> vars = model.getLHSBoundFacts();
    if (vars.size() == 0) {
        return;
    }
    if (oracle.getGlobalCollections().length == 0) {
        return;
    }
    choices.addItem(SECTION_SEPARATOR);
    for (String bf : vars) {
        for (int i = 0; i < oracle.getGlobalCollections().length; i++) {
            final String glob = oracle.getGlobalCollections()[i];
            final String var = bf;
            choices.addItem(GuidedRuleEditorResources.CONSTANTS.Append0ToList1(var, glob), "GLOBCOL" + glob + var);
            cmds.put("GLOBCOL" + glob + var, new Command() {

                public void execute() {
                    ActionGlobalCollectionAdd gca = new ActionGlobalCollectionAdd();
                    gca.setGlobalName(glob);
                    gca.setFactName(var);
                    model.addRhsItem(gca, Integer.parseInt(positionCbo.getValue(positionCbo.getSelectedIndex())));
                    hide();
                }
            });
        }
    }
}
Also used : Command(com.google.gwt.user.client.Command) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd)

Aggregations

ActionGlobalCollectionAdd (org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd)10 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)6 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)6 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)6 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)6 Test (org.junit.Test)6 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)5 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)5 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)5 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)4 RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)4 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)3 ActionSetField (org.drools.workbench.models.datamodel.rule.ActionSetField)3 HashMap (java.util.HashMap)2 List (java.util.List)2 ActionCallMethod (org.drools.workbench.models.datamodel.rule.ActionCallMethod)2 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)2 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)2 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)2 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)2