Search in sources :

Example 26 with BRLRuleModel

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);
                }
            }
        }
    }
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Example 27 with BRLRuleModel

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;
}
Also used : PatternWrapper(org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.commons.PatternWrapper) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) HashSet(java.util.HashSet)

Example 28 with BRLRuleModel

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()));
}
Also used : WizardPageStatusChangeEvent(org.uberfire.ext.widgets.core.client.wizards.WizardPageStatusChangeEvent) ActionWorkItemInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemInsertFactCol52) ActionWorkItemWrapper(org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.commons.ActionWorkItemWrapper) HashMap(java.util.HashMap) WorkItemPage(org.drools.workbench.screens.guided.dtable.client.wizard.column.pages.WorkItemPage) PatternWrapper(org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.commons.PatternWrapper) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) DecisionTableColumnViewUtils.nil(org.drools.workbench.screens.guided.dtable.client.wizard.column.pages.common.DecisionTableColumnViewUtils.nil) HasPatternPage(org.drools.workbench.screens.guided.dtable.client.wizard.column.commons.HasPatternPage) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) HasWorkItemPage(org.drools.workbench.screens.guided.dtable.client.wizard.column.commons.HasWorkItemPage) FieldAccessorsAndMutators(org.kie.soup.project.datamodel.oracle.FieldAccessorsAndMutators) ActionWorkItemSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemSetFieldCol52) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) HasFieldPage(org.drools.workbench.screens.guided.dtable.client.wizard.column.commons.HasFieldPage) DTColumnConfig52(org.drools.workbench.models.guided.dtable.shared.model.DTColumnConfig52) AdditionalInfoPage(org.drools.workbench.screens.guided.dtable.client.wizard.column.pages.AdditionalInfoPage) Event(javax.enterprise.event.Event) ActionWorkItemInsertWrapper(org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.commons.ActionWorkItemInsertWrapper) PatternPage(org.drools.workbench.screens.guided.dtable.client.wizard.column.pages.PatternPage) HasAdditionalInfoPage(org.drools.workbench.screens.guided.dtable.client.wizard.column.commons.HasAdditionalInfoPage) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) TranslationService(org.jboss.errai.ui.client.local.spi.TranslationService) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Set(java.util.Set) AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) AdditionalInfoPageInitializer(org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.commons.AdditionalInfoPageInitializer) BaseDecisionTableColumnPlugin(org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.commons.BaseDecisionTableColumnPlugin) Collectors(java.util.stream.Collectors) ModelSynchronizer(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer) ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) List(java.util.List) WizardPage(org.uberfire.ext.widgets.core.client.wizards.WizardPage) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionWorkItemSetWrapper(org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.commons.ActionWorkItemSetWrapper) Dependent(javax.enterprise.context.Dependent) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) NewGuidedDecisionTableColumnWizard(org.drools.workbench.screens.guided.dtable.client.wizard.column.NewGuidedDecisionTableColumnWizard) Optional(java.util.Optional) GuidedDecisionTableErraiConstants(org.drools.workbench.screens.guided.dtable.client.resources.i18n.GuidedDecisionTableErraiConstants) FieldPage(org.drools.workbench.screens.guided.dtable.client.wizard.column.pages.FieldPage) PortableParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel)

Example 29 with BRLRuleModel

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);
}
Also used : Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) PatternWrapper(org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.commons.PatternWrapper) Mockito.anyString(org.mockito.Mockito.anyString) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) Test(org.junit.Test)

Aggregations

BRLRuleModel (org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel)29 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)22 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)18 Test (org.junit.Test)17 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)10 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)10 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)9 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)7 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)7 PatternWrapper (org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.commons.PatternWrapper)6 HashSet (java.util.HashSet)5 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)5 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)4 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)4 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)4 ActionInsertFactCol52ActionInsertFactAdaptor (org.drools.workbench.models.guided.dtable.shared.model.adaptors.ActionInsertFactCol52ActionInsertFactAdaptor)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)3 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)3