use of org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel in project drools by kiegroup.
the class BRLRuleModelTest method testDecisionTableColumnsWithLHSBoundFields.
@Test
public void testDecisionTableColumnsWithLHSBoundFields() {
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);
FieldConstraint fcr1 = model.getLHSBoundField("$sfc1");
assertNotNull(fcr1);
assertTrue(fcr1 instanceof SingleFieldConstraint);
SingleFieldConstraint fcr1sfc = (SingleFieldConstraint) fcr1;
assertEquals("name", fcr1sfc.getFieldName());
assertEquals(DataType.TYPE_STRING, fcr1sfc.getFieldType());
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel in project drools by kiegroup.
the class BRLRuleModelTest method testDecisionTableColumnsWithLHS.
@Test
public void testDecisionTableColumnsWithLHS() {
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.getAllVariables());
assertEquals(5, model.getAllVariables().size());
assertTrue(model.getAllVariables().contains("$p1"));
assertTrue(model.getAllVariables().contains("$c1"));
assertTrue(model.getAllVariables().contains("$ins"));
assertTrue(model.getAllVariables().contains("$brl1"));
assertTrue(model.getAllVariables().contains("$sfc1"));
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel in project drools-wb by kiegroup.
the class ActionSetFactPlugin method isNewFactPattern.
boolean isNewFactPattern() {
final BRLRuleModel brlRuleModel = new BRLRuleModel(presenter.getModel());
final List<String> variables = brlRuleModel.getLHSPatternVariables();
return !variables.stream().anyMatch(b -> b.equals(patternWrapper().getBoundName()));
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel in project drools-wb by kiegroup.
the class ActionSetFactPlugin method getPatterns.
@Override
public Set<PatternWrapper> getPatterns() {
final Set<PatternWrapper> patterns = new HashSet<>();
if (isNewColumn() || !isNewFactPattern()) {
final BRLRuleModel brlRuleModel = new BRLRuleModel(presenter.getModel());
final List<String> variables = brlRuleModel.getLHSPatternVariables();
variables.forEach(var -> {
final String factType = brlRuleModel.getLHSBoundFact(var).getFactType();
final boolean isNegated = brlRuleModel.getLHSBoundFact(var).isNegated();
patterns.add(new PatternWrapper(factType, var, isNegated));
});
}
if (isNewColumn() || isNewFactPattern()) {
final BRLRuleModel brlRuleModel = new BRLRuleModel(presenter.getModel());
final List<String> variables = brlRuleModel.getRHSBoundFacts();
variables.forEach(var -> {
final String factType = brlRuleModel.getRHSBoundFact(var).getFactType();
patterns.add(new PatternWrapper(factType, var));
});
}
return patterns;
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel in project drools-wb by kiegroup.
the class BRLActionColumnPlugin method newRuleModel.
private RuleModel newRuleModel() {
final BRLRuleModel ruleModel = new BRLRuleModel(presenter.getModel());
final List<IAction> definition = editingCol.getDefinition();
ruleModel.rhs = definition.toArray(new IAction[definition.size()]);
return ruleModel;
}
Aggregations