Search in sources :

Example 11 with ActionRetractFact

use of org.drools.workbench.models.datamodel.rule.ActionRetractFact in project drools by kiegroup.

the class BRLActionColumnTest method testDiffAll.

@Test
public void testDiffAll() {
    List<IAction> definition1 = Arrays.asList(new ActionRetractFact("var1"));
    column1.setDefinition(definition1);
    List<BRLActionVariableColumn> childColumns1 = Arrays.asList(new BRLActionVariableColumn("var1", "FieldType1"));
    column1.setChildColumns(childColumns1);
    column1.setHeader("header1");
    column1.setHideColumn(false);
    List<IAction> definition2 = Arrays.asList(new ActionRetractFact("var2"));
    column2.setDefinition(definition2);
    List<BRLActionVariableColumn> childColumns2 = Arrays.asList(new BRLActionVariableColumn("var2", "FieldType2"));
    column2.setChildColumns(childColumns2);
    column2.setHeader("header2");
    column2.setHideColumn(true);
    List<BaseColumnFieldDiff> diff = column1.diff(column2);
    assertNotNull(diff);
    assertEquals(5, diff.size());
    assertEquals(FIELD_HIDE_COLUMN, diff.get(0).getFieldName());
    assertEquals(false, diff.get(0).getOldValue());
    assertEquals(true, diff.get(0).getValue());
    assertEquals(FIELD_HEADER, diff.get(1).getFieldName());
    assertEquals("header1", diff.get(1).getOldValue());
    assertEquals("header2", diff.get(1).getValue());
    assertEquals(FIELD_DEFINITION, diff.get(2).getFieldName());
    assertEquals(definition1, diff.get(2).getOldValue());
    assertEquals(definition2, diff.get(2).getValue());
    assertEquals(FIELD_VAR_NAME, diff.get(3).getFieldName());
    assertEquals("var1", diff.get(3).getOldValue());
    assertEquals("var2", diff.get(3).getValue());
    assertEquals(FIELD_FIELD_TYPE, diff.get(4).getFieldName());
    assertEquals("FieldType1", diff.get(4).getOldValue());
    assertEquals("FieldType2", diff.get(4).getValue());
}
Also used : ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) IAction(org.drools.workbench.models.datamodel.rule.IAction) Test(org.junit.Test)

Example 12 with ActionRetractFact

use of org.drools.workbench.models.datamodel.rule.ActionRetractFact in project drools by kiegroup.

the class RuleModelTest method testBoundFactFinder.

@Test
public void testBoundFactFinder() {
    final RuleModel model = new RuleModel();
    assertNull(model.getLHSBoundFact("x"));
    model.lhs = new IPattern[3];
    final FactPattern x = new FactPattern("Car");
    model.lhs[0] = x;
    x.setBoundName("x");
    assertNotNull(model.getLHSBoundFact("x"));
    assertEquals(x, model.getLHSBoundFact("x"));
    final FactPattern y = new FactPattern("Car");
    model.lhs[1] = y;
    y.setBoundName("y");
    final FactPattern other = new FactPattern("House");
    model.lhs[2] = other;
    assertEquals(y, model.getLHSBoundFact("y"));
    assertEquals(x, model.getLHSBoundFact("x"));
    model.rhs = new IAction[1];
    final ActionSetField set = new ActionSetField();
    set.setVariable("x");
    model.rhs[0] = set;
    assertTrue(model.isBoundFactUsed("x"));
    assertFalse(model.isBoundFactUsed("y"));
    assertEquals(3, model.lhs.length);
    assertFalse(model.removeLhsItem(0));
    assertEquals(3, model.lhs.length);
    final ActionRetractFact fact = new ActionRetractFact("q");
    model.rhs[0] = fact;
    assertTrue(model.isBoundFactUsed("q"));
    assertFalse(model.isBoundFactUsed("x"));
    final XStream xt = XStreamUtils.createTrustingXStream();
    xt.alias("rule", RuleModel.class);
    xt.alias("fact", FactPattern.class);
    xt.alias("retract", ActionRetractFact.class);
    // See https://issues.jboss.org/browse/GUVNOR-1115
    xt.aliasPackage("org.drools.guvnor.client", "org.drools.ide.common.client");
    final String brl = xt.toXML(model);
    logger.debug(brl);
}
Also used : ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) XStream(com.thoughtworks.xstream.XStream) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 13 with ActionRetractFact

use of org.drools.workbench.models.datamodel.rule.ActionRetractFact in project drools by kiegroup.

the class GuidedDTDRLPersistenceTest method testRHS.

@Test
public void testRHS() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] { "1", "desc", "a", "a condition", "actionsetfield1", "actionupdatefield2", "retract", "actioninsertfact1", "actioninsertfact2" };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    allColumns.add(new MetadataCol52());
    allColumns.add(new ConditionCol52());
    List<ActionCol52> cols = new ArrayList<ActionCol52>();
    ActionSetFieldCol52 asf1 = new ActionSetFieldCol52();
    asf1.setBoundName("a");
    asf1.setFactField("field1");
    asf1.setType(DataType.TYPE_STRING);
    cols.add(asf1);
    ActionSetFieldCol52 asf2 = new ActionSetFieldCol52();
    asf2.setBoundName("a");
    asf2.setFactField("field2");
    asf2.setUpdate(true);
    asf2.setType(DataType.TYPE_NUMERIC_INTEGER);
    cols.add(asf2);
    ActionRetractFactCol52 ret = new ActionRetractFactCol52();
    cols.add(ret);
    ActionInsertFactCol52 ins1 = new ActionInsertFactCol52();
    ins1.setBoundName("ins");
    ins1.setFactType("Cheese");
    ins1.setFactField("price");
    ins1.setType(DataType.TYPE_NUMERIC_INTEGER);
    cols.add(ins1);
    ActionInsertFactCol52 ins2 = new ActionInsertFactCol52();
    ins2.setBoundName("ins");
    ins2.setFactType("Cheese");
    ins2.setFactField("type");
    ins2.setType(DataType.TYPE_NUMERIC_INTEGER);
    cols.add(ins2);
    RuleModel rm = new RuleModel();
    allColumns.addAll(cols);
    List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
    TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
    p.doActions(allColumns, cols, rowDataProvider, rowData, rm);
    assertEquals(4, rm.rhs.length);
    // examine the set field action that is produced
    ActionSetField a1 = (ActionSetField) rm.rhs[0];
    assertEquals("a", a1.getVariable());
    assertEquals(1, a1.getFieldValues().length);
    assertEquals("field1", a1.getFieldValues()[0].getField());
    assertEquals("actionsetfield1", a1.getFieldValues()[0].getValue());
    assertEquals(DataType.TYPE_STRING, a1.getFieldValues()[0].getType());
    ActionSetField a2 = (ActionSetField) rm.rhs[1];
    assertEquals("a", a2.getVariable());
    assertEquals(1, a2.getFieldValues().length);
    assertEquals("field2", a2.getFieldValues()[0].getField());
    assertEquals("actionupdatefield2", a2.getFieldValues()[0].getValue());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, a2.getFieldValues()[0].getType());
    // examine the retract
    ActionRetractFact a3 = (ActionRetractFact) rm.rhs[2];
    assertEquals("retract", a3.getVariableName());
    // examine the insert
    ActionInsertFact a4 = (ActionInsertFact) rm.rhs[3];
    assertEquals("Cheese", a4.getFactType());
    assertEquals(2, a4.getFieldValues().length);
    assertEquals("price", a4.getFieldValues()[0].getField());
    assertEquals("actioninsertfact1", a4.getFieldValues()[0].getValue());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, a4.getFieldValues()[0].getType());
    assertEquals("type", a4.getFieldValues()[1].getField());
    assertEquals("actioninsertfact2", a4.getFieldValues()[1].getValue());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, a4.getFieldValues()[1].getType());
}
Also used : ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) LimitedEntryActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52) ActionRetractFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) ArrayList(java.util.ArrayList) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) LimitedEntryActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) TemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider) Test(org.junit.Test)

Example 14 with ActionRetractFact

use of org.drools.workbench.models.datamodel.rule.ActionRetractFact in project drools by kiegroup.

the class GuidedDTDRLPersistence method doAction.

private void doAction(List<LabelledAction> actions, String cell) {
    LabelledAction a = new LabelledAction();
    a.action = new ActionRetractFact(cell);
    a.boundName = cell;
    actions.add(a);
}
Also used : ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact)

Example 15 with ActionRetractFact

use of org.drools.workbench.models.datamodel.rule.ActionRetractFact in project drools-wb by kiegroup.

the class RuleModellerWidgetFactory method getWidget.

public RuleModellerWidget getWidget(RuleModeller ruleModeller, EventBus eventBus, IAction action, Boolean readOnly) {
    if (action instanceof ActionCallMethod) {
        return new ActionCallMethodWidget(ruleModeller, eventBus, (ActionCallMethod) action, readOnly);
    }
    if (action instanceof ActionSetField) {
        return new ActionSetFieldWidget(ruleModeller, eventBus, (ActionSetField) action, readOnly);
    }
    if (action instanceof ActionInsertFact) {
        return new ActionInsertFactWidget(ruleModeller, eventBus, (ActionInsertFact) action, readOnly);
    }
    if (action instanceof ActionRetractFact) {
        return new ActionRetractFactWidget(ruleModeller, eventBus, (ActionRetractFact) action, readOnly);
    }
    if (action instanceof DSLSentence) {
        RuleModellerWidget w = new DSLSentenceWidget(ruleModeller, eventBus, (DSLSentence) action, readOnly);
        return w;
    }
    if (action instanceof FreeFormLine) {
        return new FreeFormLineWidget(ruleModeller, eventBus, (FreeFormLine) action, readOnly);
    }
    if (action instanceof ActionGlobalCollectionAdd) {
        return new GlobalCollectionAddWidget(ruleModeller, eventBus, (ActionGlobalCollectionAdd) action, readOnly);
    }
    // All hardcoded action widgets have been checked, perform a plugin lookup
    List<RuleModellerActionPlugin> matchingActionPlugins = actionPlugins.stream().filter(p -> p.accept(action)).collect(Collectors.toList());
    if (matchingActionPlugins.size() > 1) {
        throw new IllegalStateException("Ambigious " + RuleModellerActionPlugin.class.getName() + " implementations for action " + action);
    }
    if (matchingActionPlugins.size() == 1) {
        RuleModellerActionPlugin actionPlugin = matchingActionPlugins.get(0);
        RuleModellerWidget ruleModellerWidget = actionPlugin.createWidget(ruleModeller, eventBus, action, readOnly);
        return ruleModellerWidget;
    }
    // NON-NLS
    throw new RuntimeException("I don't know what type of action is: " + action);
}
Also used : ExpressionBuilder(org.drools.workbench.screens.guided.rule.client.widget.ExpressionBuilder) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.CompositeFactPatternWidget) RuleModellerActionPlugin(org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin) FromCompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromCompositeFactPatternWidget) ActionCallMethodWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionCallMethodWidget) ActionInsertFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionInsertFactWidget) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromEntryPointFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromEntryPointFactPatternWidget) PortablePreconditions(org.kie.soup.commons.validation.PortablePreconditions) ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) ActionSetFieldWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionSetFieldWidget) GlobalCollectionAddWidget(org.drools.workbench.screens.guided.rule.client.widget.GlobalCollectionAddWidget) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) IAction(org.drools.workbench.models.datamodel.rule.IAction) EventBus(com.google.gwt.event.shared.EventBus) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) FactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FactPatternWidget) Collection(java.util.Collection) RuleModellerWidget(org.drools.workbench.screens.guided.rule.client.widget.RuleModellerWidget) FreeFormLineWidget(org.drools.workbench.screens.guided.rule.client.widget.FreeFormLineWidget) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) Collectors(java.util.stream.Collectors) FromCollectCompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromCollectCompositeFactPatternWidget) ActionRetractFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionRetractFactWidget) List(java.util.List) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) FromAccumulateCompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromAccumulateCompositeFactPatternWidget) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) DSLSentenceWidget(org.drools.workbench.screens.guided.rule.client.widget.DSLSentenceWidget) Collections(java.util.Collections) GlobalCollectionAddWidget(org.drools.workbench.screens.guided.rule.client.widget.GlobalCollectionAddWidget) RuleModellerActionPlugin(org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) ActionInsertFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionInsertFactWidget) ActionCallMethodWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionCallMethodWidget) RuleModellerWidget(org.drools.workbench.screens.guided.rule.client.widget.RuleModellerWidget) DSLSentenceWidget(org.drools.workbench.screens.guided.rule.client.widget.DSLSentenceWidget) FreeFormLineWidget(org.drools.workbench.screens.guided.rule.client.widget.FreeFormLineWidget) ActionSetFieldWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionSetFieldWidget) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) ActionRetractFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionRetractFactWidget)

Aggregations

ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)17 Test (org.junit.Test)8 IAction (org.drools.workbench.models.datamodel.rule.IAction)7 ActionSetField (org.drools.workbench.models.datamodel.rule.ActionSetField)6 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)6 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)6 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)6 ArrayList (java.util.ArrayList)5 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)5 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)5 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)5 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)4 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)4 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)4 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)4 ActionGlobalCollectionAdd (org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd)3 DSLSentence (org.drools.workbench.models.datamodel.rule.DSLSentence)3 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)3 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)3 RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)3