Search in sources :

Example 11 with BRLRuleModel

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());
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) Test(org.junit.Test)

Example 12 with BRLRuleModel

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"));
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) Test(org.junit.Test)

Example 13 with BRLRuleModel

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()));
}
Also used : ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) ValueOptionsPageInitializer(org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.commons.ValueOptionsPageInitializer) WizardPageStatusChangeEvent(org.uberfire.ext.widgets.core.client.wizards.WizardPageStatusChangeEvent) ActionWrapper(org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.commons.ActionWrapper) DefaultWidgetFactory(org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.commons.DefaultWidgetFactory) LimitedWidgetFactory(org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.commons.LimitedWidgetFactory) 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) HasValueOptionsPage(org.drools.workbench.screens.guided.dtable.client.wizard.column.commons.HasValueOptionsPage) HasPatternPage(org.drools.workbench.screens.guided.dtable.client.wizard.column.commons.HasPatternPage) FieldAccessorsAndMutators(org.kie.soup.project.datamodel.oracle.FieldAccessorsAndMutators) IsWidget(com.google.gwt.user.client.ui.IsWidget) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) 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) 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) ActionInsertFactWrapper(org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.commons.ActionInsertFactWrapper) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Set(java.util.Set) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) 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) List(java.util.List) ValueOptionsPage(org.drools.workbench.screens.guided.dtable.client.wizard.column.pages.ValueOptionsPage) WizardPage(org.uberfire.ext.widgets.core.client.wizards.WizardPage) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) Dependent(javax.enterprise.context.Dependent) ActionSetFactWrapper(org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.commons.ActionSetFactWrapper) 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) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel)

Example 14 with BRLRuleModel

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;
}
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 15 with BRLRuleModel

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;
}
Also used : IAction(org.drools.workbench.models.datamodel.rule.IAction) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel)

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