use of org.drools.workbench.models.datamodel.rule.ActionFieldValue in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method getComplexModel.
private RuleModel getComplexModel(boolean useDsl) {
final RuleModel m = new RuleModel();
m.name = "Complex Rule";
m.setPackageName("org.test");
m.addAttribute(new RuleAttribute("no-loop", "true"));
m.addAttribute(new RuleAttribute("salience", "-10"));
m.addAttribute(new RuleAttribute("agenda-group", "aGroup"));
final FactPattern pat = new FactPattern("Person");
pat.setBoundName("p1");
final SingleFieldConstraint con = new SingleFieldConstraint();
con.setFieldBinding("f1");
con.setFieldName("age");
con.setOperator("<");
con.setValue("42");
pat.addConstraint(con);
m.addLhsItem(pat);
final CompositeFactPattern comp = new CompositeFactPattern("not");
comp.addFactPattern(new FactPattern("Cancel"));
m.addLhsItem(comp);
final ActionUpdateField upd1 = new ActionUpdateField();
upd1.setVariable("p1");
upd1.addFieldValue(new ActionFieldValue("status", "rejected", DataType.TYPE_STRING));
upd1.addFieldValue(new ActionFieldValue("name", "Fred", DataType.TYPE_STRING));
m.addRhsItem(upd1);
final ActionRetractFact ret = new ActionRetractFact("p1");
m.addRhsItem(ret);
if (useDsl) {
final DSLSentence sen = new DSLSentence();
sen.setDefinition("Send an email to {administrator}");
m.addRhsItem(sen);
}
addModelField("org.test.Person", "this", "org.test.Person", DataType.TYPE_THIS);
addModelField("org.test.Person", "age", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
addModelField("org.test.Person", "status", String.class.getName(), DataType.TYPE_STRING);
return m;
}
use of org.drools.workbench.models.datamodel.rule.ActionFieldValue in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingI18NTest method testI18N_JP_InsertFact.
@Test
public void testI18N_JP_InsertFact() {
final String drl = "package org.test;\n" + "rule \"r1\"\n" + "dialect \"mvel\"\n" + "when\n" + "then\n" + "帽子 fact0 = new 帽子();\n" + "fact0.setサイズ( 55 );\n" + "insert( fact0 );\n" + "end";
addModelField("帽子", "サイズ", "java.lang.Integer", DataType.TYPE_NUMERIC_INTEGER);
final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, new ArrayList<String>(), dmo);
assertNotNull(m);
assertEquals(1, m.rhs.length);
assertTrue(m.rhs[0] instanceof ActionInsertFact);
final ActionInsertFact aif = (ActionInsertFact) m.rhs[0];
assertEquals("帽子", aif.getFactType());
assertEquals("fact0", aif.getBoundName());
assertEquals(1, aif.getFieldValues().length);
final ActionFieldValue afv = aif.getFieldValues()[0];
assertEquals("サイズ", afv.getField());
assertEquals("55", afv.getValue());
assertEquals(DataType.TYPE_NUMERIC_INTEGER, afv.getType());
assertEquals(FieldNatureType.TYPE_LITERAL, afv.getNature());
}
use of org.drools.workbench.models.datamodel.rule.ActionFieldValue in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingI18NTest method testI18N_US_InsertFact.
@Test
public void testI18N_US_InsertFact() {
final String drl = "package org.test;\n" + "rule \"r1\"\n" + "dialect \"mvel\"\n" + "when\n" + "then\n" + "Applicant fact0 = new Applicant();\n" + "fact0.setAge( 55 );\n" + "insert( fact0 );\n" + "end";
addModelField("Applicant", "age", "java.lang.Integer", DataType.TYPE_NUMERIC_INTEGER);
final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, new ArrayList<String>(), dmo);
assertNotNull(m);
assertEquals(1, m.rhs.length);
assertTrue(m.rhs[0] instanceof ActionInsertFact);
final ActionInsertFact aif = (ActionInsertFact) m.rhs[0];
assertEquals("Applicant", aif.getFactType());
assertEquals("fact0", aif.getBoundName());
assertEquals(1, aif.getFieldValues().length);
final ActionFieldValue afv = aif.getFieldValues()[0];
assertEquals("age", afv.getField());
assertEquals("55", afv.getValue());
assertEquals(DataType.TYPE_NUMERIC_INTEGER, afv.getType());
assertEquals(FieldNatureType.TYPE_LITERAL, afv.getNature());
}
use of org.drools.workbench.models.datamodel.rule.ActionFieldValue in project drools by kiegroup.
the class GuidedDTDRLPersistence method doAction.
private void doAction(List<LabelledAction> actions, ActionSetFieldCol52 sf, String cell) {
LabelledAction a = findByLabelledAction(actions, sf.getBoundName(), sf.isUpdate());
if (a == null) {
a = new LabelledAction();
a.boundName = sf.getBoundName();
a.isUpdate = sf.isUpdate();
if (!sf.isUpdate()) {
a.action = new ActionSetField(sf.getBoundName());
} else {
a.action = new ActionUpdateField(sf.getBoundName());
}
actions.add(a);
} else if (sf.isUpdate() && !(a.action instanceof ActionUpdateField)) {
// lets swap it out for an update as the user has asked for it.
ActionSetField old = (ActionSetField) a.action;
ActionUpdateField update = new ActionUpdateField(sf.getBoundName());
update.setFieldValues(old.getFieldValues());
a.action = update;
}
ActionSetField asf = (ActionSetField) a.action;
ActionFieldValue val = new ActionFieldValue(sf.getFactField(), cell, sf.getType());
asf.addFieldValue(val);
}
use of org.drools.workbench.models.datamodel.rule.ActionFieldValue in project drools by kiegroup.
the class GuidedDTDRLPersistence method doAction.
private void doAction(List<LabelledAction> actions, ActionInsertFactCol52 ac, String cell) {
LabelledAction a = findByLabelledAction(actions, ac.getBoundName());
if (a == null) {
a = new LabelledAction();
a.boundName = ac.getBoundName();
if (!ac.isInsertLogical()) {
ActionInsertFact ins = new ActionInsertFact(ac.getFactType());
ins.setBoundName(ac.getBoundName());
a.action = ins;
} else {
ActionInsertLogicalFact ins = new ActionInsertLogicalFact(ac.getFactType());
ins.setBoundName(ac.getBoundName());
a.action = ins;
}
actions.add(a);
}
ActionInsertFact ins = (ActionInsertFact) a.action;
ActionFieldValue val = new ActionFieldValue(ac.getFactField(), cell, ac.getType());
ins.addFieldValue(val);
}
Aggregations