use of org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52 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.shared.model.GuidedDecisionTable52 in project drools by kiegroup.
the class GuidedDTXMLPersistence method unmarshal.
public GuidedDecisionTable52 unmarshal(String xml) {
if (xml == null || xml.trim().equals("")) {
return new GuidedDecisionTable52();
}
// Upgrade DTModel to new class
Object model = xt.fromXML(xml);
GuidedDecisionTable52 newDTModel;
if (model instanceof GuidedDecisionTable) {
GuidedDecisionTable legacyDTModel = (GuidedDecisionTable) model;
newDTModel = upgrader1.upgrade(legacyDTModel);
} else {
newDTModel = (GuidedDecisionTable52) model;
}
// Upgrade RowNumber, Salience and Duration data-types are correct
newDTModel = upgrader2.upgrade(newDTModel);
// Upgrade Default Values to typed equivalents
newDTModel = upgrader3.upgrade(newDTModel);
return newDTModel;
}
use of org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52 in project drools by kiegroup.
the class GuidedDecisionTableUpgradeHelper3 method upgrade.
/**
* Convert the Default Values in the Decision Table model
*
* @param source
* @return The new DTModel
*/
public GuidedDecisionTable52 upgrade(GuidedDecisionTable52 source) {
final GuidedDecisionTable52 destination = source;
for (BaseColumn column : source.getExpandedColumns()) {
DTColumnConfig52 dtColumn = null;
if (column instanceof MetadataCol52) {
dtColumn = (DTColumnConfig52) column;
} else if (column instanceof AttributeCol52) {
dtColumn = (DTColumnConfig52) column;
} else if (column instanceof ConditionCol52) {
dtColumn = (DTColumnConfig52) column;
} else if (column instanceof ActionCol52) {
dtColumn = (DTColumnConfig52) column;
}
if (dtColumn instanceof LimitedEntryCol) {
dtColumn = null;
}
if (dtColumn instanceof BRLVariableColumn) {
dtColumn = null;
}
if (dtColumn != null) {
final String legacyDefaultValue = dtColumn.defaultValue;
if (legacyDefaultValue != null) {
dtColumn.setDefaultValue(new DTCellValue52(legacyDefaultValue));
dtColumn.defaultValue = null;
}
}
}
return destination;
}
use of org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52 in project drools by kiegroup.
the class BRLRuleModelTest method testUpdateModifyMultipleFieldsWithMultipleSkipped4.
@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped4() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
Pattern52 p1 = new Pattern52();
p1.setBoundName("x");
p1.setFactType("Context");
ConditionCol52 c = new ConditionCol52();
c.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
p1.getChildColumns().add(c);
dt.getConditions().add(p1);
BRLActionColumn brlAction1 = new BRLActionColumn();
ActionUpdateField auf1 = new ActionUpdateField("x");
auf1.addFieldValue(new ActionFieldValue("f1", "$f1", DataType.TYPE_STRING));
auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brlAction1.getDefinition().add(auf1);
brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f1", DataType.TYPE_STRING, "Context", "f1"));
ActionUpdateField auf2 = new ActionUpdateField("x");
auf2.addFieldValue(new ActionFieldValue("f2", "$f2", DataType.TYPE_STRING));
auf2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brlAction1.getDefinition().add(auf2);
brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f2", DataType.TYPE_STRING, "Context", "f2"));
ActionUpdateField auf3 = new ActionUpdateField("x");
auf3.addFieldValue(new ActionFieldValue("f3", "$f3", DataType.TYPE_STRING));
auf3.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brlAction1.getDefinition().add(auf3);
brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f3", DataType.TYPE_STRING, "Context", "f3"));
dt.getActionCols().add(brlAction1);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "x", "v1", null, "v3" } }));
String drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
final String expected = "//from row number: 1\n" + "//desc\n" + "rule \"Row 1 null\"\n" + "dialect \"mvel\"\n" + "when\n" + " x : Context( )\n" + "then\n" + " modify( x ) {\n" + " setF1( \"v1\" ),\n" + " setF3( \"v3\" )\n" + "}\n" + "end\n";
assertEqualsIgnoreWhitespace(expected, drl);
}
use of org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52 in project drools by kiegroup.
the class BRLRuleModelTest method testRuleModelRHSBoundFacts_NoDuplicates.
@Test
public void testRuleModelRHSBoundFacts_NoDuplicates() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
// Setup Decision Table columns (with existing BRLActionColumn)
ActionInsertFactCol52 ins = new ActionInsertFactCol52();
ins.setBoundName("$ins");
ins.setFactField("rating");
ins.setFactType("Person");
ins.setType(DataType.TYPE_STRING);
dt.getActionCols().add(ins);
BRLActionColumn brlAction = new BRLActionColumn();
ActionInsertFact aif1 = new ActionInsertFact("Person");
aif1.setBoundName("$aif");
aif1.addFieldValue(new ActionFieldValue("rating", null, DataType.TYPE_STRING));
aif1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_LITERAL);
brlAction.getDefinition().add(aif1);
dt.getActionCols().add(brlAction);
// Setup RuleModel columns (existing BRLActionColumn being edited)
BRLRuleModel model = new BRLRuleModel(dt);
ActionInsertFact aif2 = new ActionInsertFact("Person");
aif2.setBoundName("$aif");
aif2.addFieldValue(new ActionFieldValue("rating", null, DataType.TYPE_STRING));
aif2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_LITERAL);
model.addRhsItem(aif2);
// Checks
assertNotNull(model.getRHSBoundFacts());
assertEquals(2, model.getRHSBoundFacts().size());
assertTrue(model.getRHSBoundFacts().contains("$ins"));
assertTrue(model.getRHSBoundFacts().contains("$aif"));
ActionInsertFact r1 = model.getRHSBoundFact("$ins");
assertNotNull(r1);
assertTrue(r1 instanceof ActionInsertFactCol52ActionInsertFactAdaptor);
ActionInsertFactCol52ActionInsertFactAdaptor raif1 = (ActionInsertFactCol52ActionInsertFactAdaptor) r1;
assertEquals("Person", raif1.getFactType());
assertEquals("rating", raif1.getFieldValues()[0].getField());
assertEquals(DataType.TYPE_STRING, raif1.getFieldValues()[0].getType());
assertNull(raif1.getFieldValues()[0].getValue());
assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, raif1.getFieldValues()[0].getNature());
ActionInsertFact r2 = model.getRHSBoundFact("$aif");
assertNotNull(r2);
assertTrue(r2 instanceof ActionInsertFact);
ActionInsertFact raif2 = (ActionInsertFact) r2;
assertEquals("Person", raif2.getFactType());
assertEquals("rating", raif2.getFieldValues()[0].getField());
assertEquals(DataType.TYPE_STRING, raif2.getFieldValues()[0].getType());
assertNull(raif2.getFieldValues()[0].getValue());
assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, raif2.getFieldValues()[0].getNature());
}
Aggregations