use of org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52 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.ActionInsertFactCol52 in project drools by kiegroup.
the class GuidedDecisionTableUpgradeHelper1 method makeNewColumn.
private ActionInsertFactCol52 makeNewColumn(ActionInsertFactCol c) {
ActionInsertFactCol52 nc = new ActionInsertFactCol52();
nc.setBoundName(c.boundName);
nc.setDefaultValue(new DTCellValue52(c.defaultValue));
nc.setFactField(c.factField);
nc.setFactType(c.factType);
nc.setHeader(c.header);
nc.setHideColumn(c.hideColumn);
nc.setType(c.type);
nc.setValueList(c.valueList);
nc.setWidth(c.width);
return nc;
}
use of org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52 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());
}
use of org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52 in project drools by kiegroup.
the class BRLRuleModelTest method testRuleModelWithRHSBoundFactsUsageWithActionInsertFact.
@Test
public void testRuleModelWithRHSBoundFactsUsageWithActionInsertFact() {
final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
// Setup Decision Table columns
final Pattern52 p1 = new Pattern52();
p1.setFactType("Driver");
p1.setBoundName("$d");
dt.getConditions().add(p1);
final ActionInsertFactCol52 ins = new ActionInsertFactCol52();
ins.setBoundName("$ins");
ins.setFactField("rating");
ins.setFactType("Person");
ins.setType(DataType.TYPE_STRING);
dt.getActionCols().add(ins);
final BRLRuleModel model = new BRLRuleModel(dt);
// Checks
assertTrue(model.isBoundFactUsed("$ins"));
assertFalse(model.isBoundFactUsed("$cheese"));
}
use of org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52 in project drools by kiegroup.
the class BRLRuleModelTest method testDecisionTableColumnsWithLHSBoundFacts.
@Test
public void testDecisionTableColumnsWithLHSBoundFacts() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
Pattern52 p1 = new Pattern52();
p1.setFactType("Driver");
p1.setBoundName("$p1");
ConditionCol52 c1 = new ConditionCol52();
c1.setFactField("name");
c1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
c1.setBinding("$c1");
p1.getChildColumns().add(c1);
dt.getConditions().add(p1);
BRLConditionColumn brlCondition = new BRLConditionColumn();
FactPattern fp = new FactPattern("Driver");
fp.setBoundName("$brl1");
SingleFieldConstraint sfc1 = new SingleFieldConstraint();
sfc1.setFieldBinding("$sfc1");
sfc1.setOperator("==");
sfc1.setFactType("Driver");
sfc1.setFieldName("name");
sfc1.setFieldType(DataType.TYPE_STRING);
fp.addConstraint(sfc1);
brlCondition.getDefinition().add(fp);
dt.getConditions().add(brlCondition);
ActionInsertFactCol52 ins = new ActionInsertFactCol52();
ins.setBoundName("$ins");
ins.setFactField("rating");
ins.setFactType("Person");
ins.setType(DataType.TYPE_STRING);
dt.getActionCols().add(ins);
BRLRuleModel model = new BRLRuleModel(dt);
assertNotNull(model.getLHSBoundFacts());
assertEquals(2, model.getLHSBoundFacts().size());
assertTrue(model.getLHSBoundFacts().contains("$p1"));
assertTrue(model.getLHSBoundFacts().contains("$brl1"));
assertNotNull(model.getLHSBindingType("$p1"));
assertEquals("Driver", model.getLHSBindingType("$p1"));
assertNotNull(model.getLHSBindingType("$brl1"));
assertEquals("Driver", model.getLHSBindingType("$brl1"));
FactPattern r1 = model.getLHSBoundFact("$p1");
assertNotNull(r1);
assertTrue(r1 instanceof Pattern52FactPatternAdaptor);
Pattern52FactPatternAdaptor raif1 = (Pattern52FactPatternAdaptor) r1;
assertEquals("Driver", raif1.getFactType());
FactPattern r2 = model.getLHSBoundFact("$brl1");
assertNotNull(r2);
assertEquals("Driver", r2.getFactType());
}
Aggregations