use of org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel in project drools by kiegroup.
the class BRLRuleModelTest method testDecisionTableColumnsWithRHS.
@Test
public void testDecisionTableColumnsWithRHS() {
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);
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 aif = new ActionInsertFact("Person");
aif.setBoundName("$aif");
aif.addFieldValue(new ActionFieldValue("rating", null, DataType.TYPE_STRING));
aif.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_LITERAL);
brlAction.getDefinition().add(aif);
dt.getActionCols().add(brlAction);
BRLRuleModel model = new BRLRuleModel(dt);
assertNotNull(model.getAllVariables());
assertEquals(4, model.getAllVariables().size());
assertTrue(model.getAllVariables().contains("$p1"));
assertTrue(model.getAllVariables().contains("$c1"));
assertTrue(model.getAllVariables().contains("$ins"));
assertTrue(model.getAllVariables().contains("$aif"));
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.BRLRuleModel in project drools by kiegroup.
the class BRLRuleModelTest method testRuleModelLHSBoundFacts_NoDuplicates.
@Test
public void testRuleModelLHSBoundFacts_NoDuplicates() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
// Setup Decision Table columns (with existing BRLConditionColumn)
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 fp1 = new FactPattern("Driver");
fp1.setBoundName("$brl1");
SingleFieldConstraint sfc1 = new SingleFieldConstraint();
sfc1.setFieldBinding("$sfc1");
sfc1.setOperator("==");
sfc1.setFactType("Driver");
sfc1.setFieldName("name");
sfc1.setFieldType(DataType.TYPE_STRING);
fp1.addConstraint(sfc1);
brlCondition.getDefinition().add(fp1);
dt.getConditions().add(brlCondition);
// Setup RuleModel columns (existing BRLConditionColumn being edited)
BRLRuleModel model = new BRLRuleModel(dt);
FactPattern fp2 = new FactPattern("Driver");
fp2.setBoundName("$brl1");
SingleFieldConstraint sfc2 = new SingleFieldConstraint();
sfc2.setFieldBinding("$sfc1");
sfc2.setOperator("==");
sfc2.setFactType("Driver");
sfc2.setFieldName("name");
sfc2.setFieldType(DataType.TYPE_STRING);
fp2.addConstraint(sfc2);
model.addLhsItem(fp2);
// Checks
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());
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel in project drools by kiegroup.
the class BRLRuleModelTest method testRuleModelWithRHSBoundFactsUsageWithLimitedEntryActionRetractFact.
@Test
public void testRuleModelWithRHSBoundFactsUsageWithLimitedEntryActionRetractFact() {
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 LimitedEntryActionRetractFactCol52 del = new LimitedEntryActionRetractFactCol52();
del.setValue(new DTCellValue52("$d"));
dt.getActionCols().add(del);
final BRLRuleModel model = new BRLRuleModel(dt);
// Checks
assertTrue(model.isBoundFactUsed("$d"));
assertFalse(model.isBoundFactUsed("$cheese"));
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel in project drools by kiegroup.
the class BRLRuleModelTest method testRuleModelWithRHSBoundFactsUsageWithActionSetField.
@Test
public void testRuleModelWithRHSBoundFactsUsageWithActionSetField() {
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 ActionSetFieldCol52 set = new ActionSetFieldCol52();
set.setBoundName("$d");
set.setFactField("rating");
dt.getActionCols().add(set);
final BRLRuleModel model = new BRLRuleModel(dt);
// Checks
assertTrue(model.isBoundFactUsed("$d"));
assertFalse(model.isBoundFactUsed("$cheese"));
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel in project drools-wb by kiegroup.
the class GuidedDecisionTablePresenter method initialiseContent.
void initialiseContent(final ObservablePath path, final PlaceRequest placeRequest, final GuidedDecisionTableEditorContent content, final boolean isReadOnly) {
final GuidedDecisionTable52 model = content.getModel();
final PackageDataModelOracleBaselinePayload dataModel = content.getDataModel();
this.workItemDefinitions = content.getWorkItemDefinitions();
this.currentPath = path;
this.placeRequest = placeRequest;
this.model = model;
this.overview = content.getOverview();
this.oracle = oracleFactory.makeAsyncPackageDataModelOracle(path, model, dataModel);
this.rm = new BRLRuleModel(model);
this.uiModel = makeUiModel();
this.renderer = makeViewRenderer();
this.view = makeView(workItemDefinitions);
initialiseAccess(isReadOnly);
initialiseLockManager();
initialiseUtilities();
initialiseModels();
initialiseValidationAndVerification();
initialiseEventHandlers();
initialiseAuditLog();
}
Aggregations