use of org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel in project drools-wb by kiegroup.
the class DefaultGuidedDecisionTableLinkManager method link.
@Override
public void link(final GuidedDecisionTable52 model, final GuidedDecisionTable52 otherModel, final LinkFoundCallback callback) {
if (model == null) {
return;
}
if (otherModel == null) {
return;
}
if (callback == null) {
return;
}
final BRLRuleModel helper = new BRLRuleModel(model);
// Re-create links to other Decision Tables
for (CompositeColumn<? extends BaseColumn> otherDecisionTableConditions : otherModel.getConditions()) {
if (otherDecisionTableConditions instanceof Pattern52) {
final Pattern52 otherDecisionTablePattern = (Pattern52) otherDecisionTableConditions;
for (ConditionCol52 otherDecisionTableCondition : otherDecisionTablePattern.getChildColumns()) {
final String factType = otherDecisionTablePattern.getFactType();
final String fieldName = otherDecisionTableCondition.getFactField();
final ActionCol52 linkedActionColumn = getLinkedActionColumn(factType, fieldName, model, helper);
if (linkedActionColumn != null) {
final int sourceColumnIndex = model.getExpandedColumns().indexOf(linkedActionColumn);
final int targetColumnIndex = otherModel.getExpandedColumns().indexOf(otherDecisionTableCondition);
callback.link(sourceColumnIndex, targetColumnIndex);
}
}
} else if (otherDecisionTableConditions instanceof BRLConditionColumn) {
final BRLConditionColumn fragment = (BRLConditionColumn) otherDecisionTableConditions;
for (BRLConditionVariableColumn var : fragment.getChildColumns()) {
final String factType = var.getFactType();
final String fieldName = var.getFactField();
final ActionCol52 linkedActionColumn = getLinkedActionColumn(factType, fieldName, model, helper);
if (linkedActionColumn != null) {
final int sourceColumnIndex = model.getExpandedColumns().indexOf(linkedActionColumn);
final int targetColumnIndex = otherModel.getExpandedColumns().indexOf(var);
callback.link(sourceColumnIndex, targetColumnIndex);
}
}
}
}
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel in project drools-wb by kiegroup.
the class ActionWorkItemSetFieldPlugin 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 ActionWorkItemSetFieldPlugin 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 ConditionColumnPluginTest method testMakeBRLRuleModel.
@Test
public void testMakeBRLRuleModel() {
final String factType = "FactType";
final String boundName1 = "$fact1";
final String boundName2 = "$fact2";
final Pattern52 pattern = new Pattern52() {
{
setFactType(factType);
setBoundName(boundName1);
}
};
final FactPattern factPattern = new FactPattern() {
{
setFactType(factType);
setBoundName(boundName2);
}
};
final PatternWrapper patternWrapper = mock(PatternWrapper.class);
doReturn(factPattern).when(patternWrapper).makeFactPattern();
doReturn(patternWrapper).when(plugin).patternWrapper();
doReturn(Collections.singletonList(pattern)).when(model).getConditions();
doReturn(pattern).when(model).getConditionPattern(boundName1);
final BRLRuleModel brlRuleModel = plugin.makeBRLRuleModel();
final List<String> expectedVariables = Arrays.asList(boundName1, boundName2);
final List<String> actualVariables = brlRuleModel.getAllVariables();
assertEquals(expectedVariables, actualVariables);
}
Aggregations