use of org.drools.workbench.models.guided.dtable.shared.model.ActionCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistence method doActions.
void doActions(List<BaseColumn> allColumns, List<ActionCol52> actionCols, TemplateDataProvider rowDataProvider, List<DTCellValue52> row, RuleModel rm) {
List<LabelledAction> actions = new ArrayList<LabelledAction>();
for (ActionCol52 c : actionCols) {
if (c instanceof LimitedEntryBRLActionColumn) {
doAction(allColumns, (LimitedEntryBRLActionColumn) c, actions, rowDataProvider, row, rm);
} else if (c instanceof BRLActionColumn) {
doAction(allColumns, (BRLActionColumn) c, actions, rowDataProvider, row, rm);
} else {
int index = allColumns.indexOf(c);
DTCellValue52 dcv = row.get(index);
String cell = "";
if (c instanceof LimitedEntryCol) {
if (dcv.getBooleanValue() == true) {
LimitedEntryCol lec = (LimitedEntryCol) c;
cell = GuidedDTDRLUtilities.convertDTCellValueToString(lec.getValue());
}
} else {
cell = GuidedDTDRLUtilities.convertDTCellValueToString(dcv);
}
if (validCell(cell, dcv.getDataType())) {
if (c instanceof ActionWorkItemInsertFactCol52) {
doAction(actions, (ActionWorkItemInsertFactCol52) c, cell);
} else if (c instanceof ActionInsertFactCol52) {
doAction(actions, (ActionInsertFactCol52) c, cell);
} else if (c instanceof ActionWorkItemSetFieldCol52) {
doAction(actions, (ActionWorkItemSetFieldCol52) c, cell);
} else if (c instanceof ActionSetFieldCol52) {
doAction(actions, (ActionSetFieldCol52) c, cell);
} else if (c instanceof ActionRetractFactCol52) {
doAction(actions, cell);
} else if (c instanceof ActionWorkItemCol52) {
doAction(actions, (ActionWorkItemCol52) c, cell);
}
}
}
}
rm.rhs = new IAction[actions.size()];
for (int i = 0; i < rm.rhs.length; i++) {
rm.rhs[i] = actions.get(i).action;
}
}
use of org.drools.workbench.models.guided.dtable.shared.model.ActionCol52 in project drools by kiegroup.
the class GuidedDecisionTableUpgradeHelper1 method makeNewColumn.
private ActionCol52 makeNewColumn(ActionCol c) {
if (c instanceof ActionInsertFactCol) {
return makeNewColumn((ActionInsertFactCol) c);
} else if (c instanceof ActionRetractFactCol) {
return makeNewColumn((ActionRetractFactCol) c);
} else if (c instanceof ActionSetFieldCol) {
return makeNewColumn((ActionSetFieldCol) c);
}
ActionCol52 nc = new ActionCol52();
nc.setDefaultValue(new DTCellValue52(c.defaultValue));
nc.setHeader(c.header);
nc.setHideColumn(c.hideColumn);
nc.setWidth(c.width);
return nc;
}
use of org.drools.workbench.models.guided.dtable.shared.model.ActionCol52 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.ActionCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testRHSWithBRLColumn_ParseToRuleModel.
@Test
public // This test checks a Decision Table involving BRL columns is correctly converted into a RuleModel
void testRHSWithBRLColumn_ParseToRuleModel() {
GuidedDecisionTable52 dtable = new GuidedDecisionTable52();
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
// All three rows are entered, some columns with optional data
String[][] data = new String[][] { new String[] { "1", "desc", "Gargamel", "Pupa", "50" }, new String[] { "2", "desc", "Gargamel", "", "50" }, new String[] { "3", "desc", "Gargamel", "Pupa", "" } };
// Simple (mandatory) columns
dtable.setRowNumberCol(new RowNumberCol52());
dtable.setDescriptionCol(new DescriptionCol52());
// Simple Action
ActionInsertFactCol52 a1 = new ActionInsertFactCol52();
a1.setBoundName("$b");
a1.setFactType("Baddie");
a1.setFactField("name");
a1.setType(DataType.TYPE_STRING);
dtable.getActionCols().add(a1);
// BRL Column
BRLActionColumn brl1 = new BRLActionColumn();
// BRL Column definition
List<IAction> brl1Definition = new ArrayList<IAction>();
ActionInsertFact brl1DefinitionAction1 = new ActionInsertFact("Smurf");
ActionFieldValue brl1DefinitionAction1FieldValue1 = new ActionFieldValue("name", "$name", DataType.TYPE_STRING);
brl1DefinitionAction1FieldValue1.setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brl1DefinitionAction1.addFieldValue(brl1DefinitionAction1FieldValue1);
ActionFieldValue brl1DefinitionAction1FieldValue2 = new ActionFieldValue("age", "$age", DataType.TYPE_NUMERIC_INTEGER);
brl1DefinitionAction1FieldValue2.setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brl1DefinitionAction1.addFieldValue(brl1DefinitionAction1FieldValue2);
brl1Definition.add(brl1DefinitionAction1);
brl1.setDefinition(brl1Definition);
// Setup BRL column bindings
BRLActionVariableColumn brl1Variable1 = new BRLActionVariableColumn("$name", DataType.TYPE_STRING, "Person", "name");
brl1.getChildColumns().add(brl1Variable1);
BRLActionVariableColumn brl1Variable2 = new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Person", "age");
brl1.getChildColumns().add(brl1Variable2);
dtable.getActionCols().add(brl1);
// Now to test conversion
RuleModel rm = new RuleModel();
List<BaseColumn> allColumns = dtable.getExpandedColumns();
List<ActionCol52> allActions = dtable.getActionCols();
// Row 0
List<DTCellValue52> dtRowData0 = DataUtilities.makeDataRowList(data[0]);
TemplateDataProvider rowDataProvider0 = new GuidedDTTemplateDataProvider(allColumns, dtRowData0);
p.doActions(allColumns, allActions, rowDataProvider0, dtRowData0, rm);
assertEquals(2, rm.rhs.length);
assertEquals("Baddie", ((ActionInsertFact) rm.rhs[0]).getFactType());
assertEquals("Smurf", ((ActionInsertFact) rm.rhs[1]).getFactType());
// examine the first action
ActionInsertFact result0Action1 = (ActionInsertFact) rm.rhs[0];
assertEquals(1, result0Action1.getFieldValues().length);
ActionFieldValue result0Action1FieldValue1 = (ActionFieldValue) result0Action1.getFieldValues()[0];
assertEquals(DataType.TYPE_STRING, result0Action1FieldValue1.getType());
assertEquals("name", result0Action1FieldValue1.getField());
assertEquals("Gargamel", result0Action1FieldValue1.getValue());
// examine the second action
ActionInsertFact result0Action2 = (ActionInsertFact) rm.rhs[1];
assertEquals(2, result0Action2.getFieldValues().length);
ActionFieldValue result0Action2FieldValue1 = (ActionFieldValue) result0Action2.getFieldValues()[0];
assertEquals(DataType.TYPE_STRING, result0Action2FieldValue1.getType());
assertEquals("name", result0Action2FieldValue1.getField());
assertEquals("$name", result0Action2FieldValue1.getValue());
ActionFieldValue result0Action2FieldValue2 = (ActionFieldValue) result0Action2.getFieldValues()[1];
assertEquals(DataType.TYPE_NUMERIC_INTEGER, result0Action2FieldValue2.getType());
assertEquals("age", result0Action2FieldValue2.getField());
assertEquals("$age", result0Action2FieldValue2.getValue());
// Row 1
List<DTCellValue52> dtRowData1 = DataUtilities.makeDataRowList(data[1]);
TemplateDataProvider rowDataProvider1 = new GuidedDTTemplateDataProvider(allColumns, dtRowData1);
p.doActions(allColumns, allActions, rowDataProvider1, dtRowData1, rm);
assertEquals(2, rm.rhs.length);
assertEquals("Baddie", ((ActionInsertFact) rm.rhs[0]).getFactType());
assertEquals("Smurf", ((ActionInsertFact) rm.rhs[1]).getFactType());
// examine the first action
ActionInsertFact result1Action1 = (ActionInsertFact) rm.rhs[0];
assertEquals(1, result1Action1.getFieldValues().length);
ActionFieldValue result1Action1FieldValue1 = (ActionFieldValue) result1Action1.getFieldValues()[0];
assertEquals(DataType.TYPE_STRING, result1Action1FieldValue1.getType());
assertEquals("name", result1Action1FieldValue1.getField());
assertEquals("Gargamel", result1Action1FieldValue1.getValue());
// examine the second action
ActionInsertFact result1Action2 = (ActionInsertFact) rm.rhs[1];
assertEquals(2, result1Action2.getFieldValues().length);
ActionFieldValue result1Action2FieldValue1 = (ActionFieldValue) result1Action2.getFieldValues()[0];
assertEquals(DataType.TYPE_STRING, result1Action2FieldValue1.getType());
assertEquals("name", result1Action2FieldValue1.getField());
assertEquals("$name", result1Action2FieldValue1.getValue());
ActionFieldValue result1Action2FieldValue2 = (ActionFieldValue) result1Action2.getFieldValues()[1];
assertEquals(DataType.TYPE_NUMERIC_INTEGER, result1Action2FieldValue2.getType());
assertEquals("age", result1Action2FieldValue2.getField());
assertEquals("$age", result1Action2FieldValue2.getValue());
// Row 2
List<DTCellValue52> dtRowData2 = DataUtilities.makeDataRowList(data[2]);
TemplateDataProvider rowDataProvider2 = new GuidedDTTemplateDataProvider(allColumns, dtRowData2);
p.doActions(allColumns, allActions, rowDataProvider2, dtRowData2, rm);
assertEquals(2, rm.rhs.length);
assertEquals("Baddie", ((ActionInsertFact) rm.rhs[0]).getFactType());
assertEquals("Smurf", ((ActionInsertFact) rm.rhs[1]).getFactType());
// examine the first action
ActionInsertFact result2Action1 = (ActionInsertFact) rm.rhs[0];
assertEquals(1, result2Action1.getFieldValues().length);
ActionFieldValue result2Action1FieldValue1 = (ActionFieldValue) result2Action1.getFieldValues()[0];
assertEquals(DataType.TYPE_STRING, result2Action1FieldValue1.getType());
assertEquals("name", result2Action1FieldValue1.getField());
assertEquals("Gargamel", result2Action1FieldValue1.getValue());
// examine the second action
ActionInsertFact result2Action2 = (ActionInsertFact) rm.rhs[1];
assertEquals(2, result2Action2.getFieldValues().length);
ActionFieldValue result2Action2FieldValue1 = (ActionFieldValue) result2Action2.getFieldValues()[0];
assertEquals(DataType.TYPE_STRING, result2Action2FieldValue1.getType());
assertEquals("name", result2Action2FieldValue1.getField());
assertEquals("$name", result2Action2FieldValue1.getValue());
ActionFieldValue result3Action2FieldValue2 = (ActionFieldValue) result2Action2.getFieldValues()[1];
assertEquals(DataType.TYPE_NUMERIC_INTEGER, result3Action2FieldValue2.getType());
assertEquals("age", result3Action2FieldValue2.getField());
assertEquals("$age", result3Action2FieldValue2.getValue());
}
use of org.drools.workbench.models.guided.dtable.shared.model.ActionCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testRHSExecuteWorkItem.
@Test
public void testRHSExecuteWorkItem() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
String[] row = new String[] { "1", "desc", "true" };
List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
allColumns.add(new RowNumberCol52());
allColumns.add(new DescriptionCol52());
List<ActionCol52> cols = new ArrayList<ActionCol52>();
ActionWorkItemCol52 awi = new ActionWorkItemCol52();
PortableWorkDefinition pwd = new PortableWorkDefinition();
pwd.setName("work-item");
awi.setWorkItemDefinition(pwd);
PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
p1.setName("BooleanParameter");
p1.setValue(Boolean.TRUE);
pwd.addParameter(p1);
PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
p2.setName("FloatParameter");
p2.setValue(123.456f);
pwd.addParameter(p2);
PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
p3.setName("IntegerParameter");
p3.setValue(123);
pwd.addParameter(p3);
PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
p4.setName("StringParameter");
p4.setValue("hello");
pwd.addParameter(p4);
cols.add(awi);
RuleModel rm = new RuleModel();
allColumns.addAll(cols);
List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
p.doActions(allColumns, cols, rowDataProvider, rowData, rm);
assertEquals(1, rm.rhs.length);
// Examine RuleModel action
ActionExecuteWorkItem aw = (ActionExecuteWorkItem) rm.rhs[0];
assertNotNull(aw);
PortableWorkDefinition mpwd = aw.getWorkDefinition();
assertNotNull(mpwd);
assertEquals(4, mpwd.getParameters().size());
PortableBooleanParameterDefinition mp1 = (PortableBooleanParameterDefinition) mpwd.getParameter("BooleanParameter");
assertNotNull(mp1);
assertEquals(Boolean.TRUE, mp1.getValue());
PortableFloatParameterDefinition mp2 = (PortableFloatParameterDefinition) mpwd.getParameter("FloatParameter");
assertNotNull(mp2);
assertEquals(new Float(123.456f), mp2.getValue());
PortableIntegerParameterDefinition mp3 = (PortableIntegerParameterDefinition) mpwd.getParameter("IntegerParameter");
assertNotNull(mp3);
assertEquals(new Integer(123), mp3.getValue());
PortableStringParameterDefinition mp4 = (PortableStringParameterDefinition) mpwd.getParameter("StringParameter");
assertNotNull(mp4);
assertEquals("hello", mp4.getValue());
}
Aggregations