Search in sources :

Example 6 with ActionInsertLogicalFact

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

the class RuleModellerActionSelectorPopup method addLogicalInsertions.

// Add logical insertions
void addLogicalInsertions() {
    if (oracle.getFactTypes().length == 0) {
        return;
    }
    choices.addItem(SECTION_SEPARATOR);
    for (int i = 0; i < oracle.getFactTypes().length; i++) {
        final String item = oracle.getFactTypes()[i];
        choices.addItem(GuidedRuleEditorResources.CONSTANTS.LogicallyInsertFact0(item), "LINS" + item);
        cmds.put("LINS" + item, new Command() {

            public void execute() {
                model.addRhsItem(new ActionInsertLogicalFact(item), Integer.parseInt(positionCbo.getValue(positionCbo.getSelectedIndex())));
                hide();
            }
        });
    }
}
Also used : Command(com.google.gwt.user.client.Command) ActionInsertLogicalFact(org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact)

Example 7 with ActionInsertLogicalFact

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

the class ActionInsertFactWidget method getAssertLabel.

private Widget getAssertLabel() {
    ClickHandler cl = new ClickHandler() {

        public void onClick(ClickEvent event) {
            Widget w = (Widget) event.getSource();
            showAddFieldPopup(w);
        }
    };
    // NON-NLS
    String assertType = "assert";
    if (this.model instanceof ActionInsertLogicalFact) {
        // NON-NLS
        assertType = "assertLogical";
    }
    String lbl = (model.isBound() == false) ? HumanReadable.getActionDisplayName(assertType) + " <b>" + this.model.getFactType() + "</b>" : HumanReadable.getActionDisplayName(assertType) + " <b>" + this.model.getFactType() + "</b>" + " <b>[" + model.getBoundName() + "]</b>";
    if (this.model.getFieldValues() != null && model.getFieldValues().length > 0) {
        lbl = lbl + ":";
    }
    return new ClickableLabel(lbl, cl, !this.readOnly);
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Widget(com.google.gwt.user.client.ui.Widget) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel) ActionInsertLogicalFact(org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact)

Example 8 with ActionInsertLogicalFact

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

the class RHSClassDependencyVisitorTest method visitActionInsertLogicalFact.

@Test
public void visitActionInsertLogicalFact() {
    ActionInsertLogicalFact iAction = new ActionInsertLogicalFact();
    iAction.setFieldValues(new ActionFieldValue[] { new ActionFieldValue("field", "value", "type") });
    visitor.visit(iAction);
    assertTrue(visitor.getRHSClasses().containsKey("type"));
}
Also used : ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertLogicalFact(org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact) Test(org.junit.Test)

Example 9 with ActionInsertLogicalFact

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

the class RuleModelDRLPersistenceTest method testAssertWithDSL.

@Test
public void testAssertWithDSL() throws Exception {
    RuleModel m = new RuleModel();
    DSLSentence sen = new DSLSentence();
    sen.setDefinition("I CAN HAS DSL");
    m.addRhsItem(sen);
    ActionInsertFact ins = new ActionInsertFact("Shizzle");
    ActionFieldValue val = new ActionFieldValue("goo", "42", "Numeric");
    ins.setFieldValues(new ActionFieldValue[1]);
    ins.getFieldValues()[0] = val;
    m.addRhsItem(ins);
    ActionInsertLogicalFact insL = new ActionInsertLogicalFact("Shizzle");
    ActionFieldValue valL = new ActionFieldValue("goo", "42", "Numeric");
    insL.setFieldValues(new ActionFieldValue[1]);
    insL.getFieldValues()[0] = valL;
    m.addRhsItem(insL);
    String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    assertTrue(result.indexOf(">insert") > -1);
    assertTrue(result.indexOf(">insertLogical") > -1);
}
Also used : ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) ActionInsertLogicalFact(org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact) Test(org.junit.Test)

Example 10 with ActionInsertLogicalFact

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

the class RuleModelDRLPersistenceUnmarshallingTest method testRHSAppendToList.

@Test
public void testRHSAppendToList() throws Exception {
    // https://issues.jboss.org/browse/GUVNOR-2286
    String drl = "package org.test;\n" + "import java.lang.Number;\n" + "rule \"RuleCheckEmail\"\n" + "dialect \"mvel\"\n" + "when\n" + "incomeData : IncomeData( email == \"myemail\" , $list : list != null )\n" + "then\n" + "Element element = new Element();\n" + "element.setId( 2 );\n" + "insertLogical( element );\n" + "$list.add( element );\n" + "end";
    addModelField("org.test.IncomeData", "this", "org.test.IncomeData", DataType.TYPE_THIS);
    addModelField("org.test.IncomeData", "email", String.class.getName(), DataType.TYPE_STRING);
    addModelField("org.test.IncomeData", "list", List.class.getName(), DataType.TYPE_COLLECTION);
    addModelField("java.util.List", "this", "java.util.List", DataType.TYPE_THIS);
    addMethodInformation("java.util.List", "add", new ArrayList<String>() {

        {
            add("java.lang.Object");
        }
    }, DataType.TYPE_BOOLEAN, null, DataType.TYPE_BOOLEAN);
    addMethodInformation("java.util.List", "add", new ArrayList<String>() {

        {
            add("java.lang.Integer");
            add("java.lang.Object");
        }
    }, DataType.TYPE_BOOLEAN, null, DataType.TYPE_BOOLEAN);
    when(dmo.getPackageName()).thenReturn("org.test");
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(1, m.lhs.length);
    final IPattern p0 = m.lhs[0];
    assertTrue(p0 instanceof FactPattern);
    final FactPattern fp0 = (FactPattern) p0;
    assertEquals("IncomeData", fp0.getFactType());
    assertEquals(2, fp0.getNumberOfConstraints());
    assertTrue(fp0.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint fp0sfc0 = (SingleFieldConstraint) fp0.getConstraint(0);
    assertEquals("IncomeData", fp0sfc0.getFactType());
    assertEquals("email", fp0sfc0.getFieldName());
    assertEquals(DataType.TYPE_STRING, fp0sfc0.getFieldType());
    assertEquals("==", fp0sfc0.getOperator());
    assertEquals("myemail", fp0sfc0.getValue());
    assertTrue(fp0.getConstraint(1) instanceof SingleFieldConstraint);
    final SingleFieldConstraint fp0sfc1 = (SingleFieldConstraint) fp0.getConstraint(1);
    assertEquals("IncomeData", fp0sfc1.getFactType());
    assertEquals("list", fp0sfc1.getFieldName());
    assertEquals(DataType.TYPE_COLLECTION, fp0sfc1.getFieldType());
    assertEquals("!= null", fp0sfc1.getOperator());
    assertNull(fp0sfc1.getValue());
    assertEquals(2, m.rhs.length);
    assertTrue(m.rhs[0] instanceof ActionInsertLogicalFact);
    final ActionInsertLogicalFact a0 = (ActionInsertLogicalFact) m.rhs[0];
    assertEquals("Element", a0.getFactType());
    assertEquals("element", a0.getBoundName());
    assertEquals(1, a0.getFieldValues().length);
    final ActionFieldValue a0f0 = a0.getFieldValues()[0];
    assertEquals("id", a0f0.getField());
    assertEquals("2", a0f0.getValue());
    assertEquals(DataType.TYPE_NUMERIC, a0f0.getType());
    assertEquals(FieldNatureType.TYPE_LITERAL, a0f0.getNature());
    assertTrue(m.rhs[1] instanceof ActionCallMethod);
    final ActionCallMethod a1 = (ActionCallMethod) m.rhs[1];
    assertEquals("add", a1.getMethodName());
    assertEquals("$list", a1.getVariable());
    assertEquals(1, a1.getFieldValues().length);
    final ActionFieldValue a1f0 = a1.getFieldValues()[0];
    assertEquals("add", a1f0.getField());
    assertEquals("element", a1f0.getValue());
    assertEquals(FieldNatureType.TYPE_VARIABLE, a1f0.getNature());
    assertEquals("java.lang.Object", a1f0.getType());
    // Check round-trip
    assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) 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) List(java.util.List) ArrayList(java.util.ArrayList) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ActionInsertLogicalFact(org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact) Test(org.junit.Test)

Aggregations

ActionInsertLogicalFact (org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact)10 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)5 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)4 ArrayList (java.util.ArrayList)3 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)3 Test (org.junit.Test)3 List (java.util.List)2 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)2 ActionSetField (org.drools.workbench.models.datamodel.rule.ActionSetField)2 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)2 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)2 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)2 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)2 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)2 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)2 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)2 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 Command (com.google.gwt.user.client.Command)1