use of org.drools.workbench.models.datamodel.rule.RuleAttribute 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.RuleAttribute in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testRoundTrip.
@Test
public void testRoundTrip() {
final RuleModel m = getComplexModel(true);
final String drl = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
final RuleModel m2 = RuleModelDRLPersistenceImpl.getInstance().unmarshalUsingDSL(drl, Collections.EMPTY_LIST, dmo);
assertNotNull(m2);
assertEquals(m.name, m2.name);
assertEquals(m.lhs.length, m2.lhs.length);
assertEquals(m.rhs.length, m2.rhs.length);
assertEquals(3, m.attributes.length);
final RuleAttribute at = m.attributes[0];
assertEquals("no-loop", at.getAttributeName());
assertEquals("true", at.getValue());
final String drl2 = RuleModelDRLPersistenceImpl.getInstance().marshal(m2);
assertEquals(drl, drl2);
}
use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.
the class GuidedDTDRLPersistence method doAttribs.
void doAttribs(List<BaseColumn> allColumns, List<AttributeCol52> attributeCols, List<DTCellValue52> row, RuleModel rm) {
List<RuleAttribute> attribs = new ArrayList<RuleAttribute>();
for (int j = 0; j < attributeCols.size(); j++) {
AttributeCol52 at = attributeCols.get(j);
int index = allColumns.indexOf(at);
final DTCellValue52 dcv = row.get(index);
String cell = GuidedDTDRLUtilities.convertDTCellValueToString(dcv);
if (validateAttributeCell(cell)) {
// If instance of "otherwise" column then flag RuleModel as being negated
if (at.getAttribute().equals(GuidedDecisionTable52.NEGATE_RULE_ATTR)) {
rm.setNegated(Boolean.valueOf(cell));
} else {
attribs.add(new RuleAttribute(at.getAttribute(), cell));
}
}
}
if (attribs.size() > 0) {
rm.attributes = attribs.toArray(new RuleAttribute[attribs.size()]);
}
}
use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.
the class RuleTemplateModelXMLPersistenceTest method testRoundTrip.
@Test
public void testRoundTrip() {
final TemplateModel m = getComplexModel();
final String xml = RuleTemplateModelXMLPersistenceImpl.getInstance().marshal(m);
final TemplateModel m2 = RuleTemplateModelXMLPersistenceImpl.getInstance().unmarshal(xml);
assertNotNull(m2);
assertEquals(m.name, m2.name);
assertEquals(m.lhs.length, m2.lhs.length);
assertEquals(m.rhs.length, m2.rhs.length);
assertEquals(1, m.attributes.length);
final RuleAttribute at = m.attributes[0];
assertEquals("no-loop", at.getAttributeName());
assertEquals("true", at.getValue());
final String newXML = RuleTemplateModelXMLPersistenceImpl.getInstance().marshal(m2);
assertEquals(xml, newXML);
}
use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.
the class RuleTemplateModelXMLPersistenceTest method getComplexModel.
private TemplateModel getComplexModel() {
final TemplateModel m = new TemplateModel();
m.addAttribute(new RuleAttribute("no-loop", "true"));
final FactPattern pat = new FactPattern("Person");
pat.setBoundName("p1");
final SingleFieldConstraint con = new SingleFieldConstraint();
con.setFactType("Person");
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 set = new ActionUpdateField();
set.setVariable("p1");
set.addFieldValue(new ActionFieldValue("status", "rejected", DataType.TYPE_STRING));
m.addRhsItem(set);
final ActionRetractFact ret = new ActionRetractFact("p1");
m.addRhsItem(ret);
final DSLSentence sen = new DSLSentence();
sen.setDefinition("Send an email to {administrator}");
m.addRhsItem(sen);
return m;
}
Aggregations