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