use of org.drools.workbench.models.guided.dtable.backend.util.GuidedDTBRDRLPersistence in project drools by kiegroup.
the class GuidedDTDRLPersistence method marshal.
public String marshal(final GuidedDecisionTable52 originalDTable) {
final GuidedDecisionTable52 dt = DecisionTableHitPolicyEnhancer.enhance(originalDTable);
StringBuilder sb = new StringBuilder();
List<List<DTCellValue52>> data = dt.getData();
List<BaseColumn> allColumns = dt.getExpandedColumns();
// Append package name and imports to DRL
PackageNameWriter.write(sb, dt);
ImportsWriter.write(sb, dt);
// Build rules
for (int i = 0; i < data.size(); i++) {
List<DTCellValue52> row = data.get(i);
// Specialised BRDRLPersistence provider than can handle template key expansion
TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, row);
Integer num = (Integer) row.get(0).getNumericValue();
String desc = row.get(1).getStringValue();
BRLRuleModel rm = new BRLRuleModel(dt);
rm.name = getName(dt.getTableName(), num);
doMetadata(allColumns, dt.getMetadataCols(), row, rm);
doAttribs(allColumns, dt.getAttributeCols(), row, rm);
doConditions(allColumns, dt.getConditions(), rowDataProvider, row, data, rm);
doActions(allColumns, dt.getActionCols(), rowDataProvider, row, rm);
if (dt.getParentName() != null) {
rm.parentName = dt.getParentName();
}
sb.append("//from row number: " + (i + 1) + "\n");
if (desc != null && desc.length() > 0) {
sb.append("//" + desc + "\n");
}
GuidedDTBRDRLPersistence drlMarshaller = new GuidedDTBRDRLPersistence(rowDataProvider);
String rule = drlMarshaller.marshal(rm);
sb.append(rule);
sb.append("\n");
}
return sb.toString();
}
use of org.drools.workbench.models.guided.dtable.backend.util.GuidedDTBRDRLPersistence in project drools by kiegroup.
the class GuidedDTBRDRLPersistenceTest method testRHSWithTemplateAwareIAction.
@Test
public void testRHSWithTemplateAwareIAction() {
GuidedDTBRDRLPersistence persistence = new GuidedDTBRDRLPersistence((key) -> "value");
RuleModel ruleModel = new RuleModel();
ruleModel.name = "Template aware";
ruleModel.addRhsItem(new TemplateAwareIAction("initialValue"));
String result = persistence.marshal(ruleModel);
String expected = "rule \"Template aware\"\n" + "\tdialect \"mvel\"\n" + "\twhen\n" + "\tthen\n" + "\t\tsubstitutedValue;\n" + "end\n";
assertEquals(expected, result);
}
Aggregations