Search in sources :

Example 21 with ActionInsertFact

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

the class GuidedDTDRLPersistence method addAction.

private void addAction(IAction action, List<LabelledAction> actions) {
    String binding = null;
    if (action instanceof ActionInsertFact) {
        final ActionInsertFact af = (ActionInsertFact) action;
        binding = af.getBoundName();
    } else if (action instanceof ActionSetField) {
        final ActionSetField af = (ActionSetField) action;
        binding = af.getVariable();
    }
    // the binding use a unique identifier, in this case the Object itself.
    if (binding == null) {
        binding = action.toString();
    }
    final LabelledAction a = new LabelledAction();
    a.boundName = binding;
    a.action = action;
    actions.add(a);
}
Also used : ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact)

Example 22 with ActionInsertFact

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

the class GuidedDTDRLPersistence method doAction.

private void doAction(List<LabelledAction> actions, ActionWorkItemInsertFactCol52 ac, String cell) {
    if (Boolean.TRUE.equals(Boolean.parseBoolean(cell))) {
        LabelledAction a = findByLabelledAction(actions, ac.getBoundName());
        if (a == null) {
            a = new LabelledAction();
            a.boundName = ac.getBoundName();
            if (!ac.isInsertLogical()) {
                ActionInsertFact ins = new ActionInsertFact(ac.getFactType());
                ins.setBoundName(ac.getBoundName());
                a.action = ins;
            } else {
                ActionInsertLogicalFact ins = new ActionInsertLogicalFact(ac.getFactType());
                ins.setBoundName(ac.getBoundName());
                a.action = ins;
            }
            actions.add(a);
        }
        ActionInsertFact ins = (ActionInsertFact) a.action;
        ActionWorkItemFieldValue val = new ActionWorkItemFieldValue(ac.getFactField(), ac.getType(), ac.getWorkItemName(), ac.getWorkItemResultParameterName(), ac.getParameterClassName());
        ins.addFieldValue(val);
    }
}
Also used : ActionWorkItemFieldValue(org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) ActionInsertLogicalFact(org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact)

Example 23 with ActionInsertFact

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

the class GuidedDTDRLPersistence method doAction.

private void doAction(List<LabelledAction> actions, ActionInsertFactCol52 ac, String cell) {
    LabelledAction a = findByLabelledAction(actions, ac.getBoundName());
    if (a == null) {
        a = new LabelledAction();
        a.boundName = ac.getBoundName();
        if (!ac.isInsertLogical()) {
            ActionInsertFact ins = new ActionInsertFact(ac.getFactType());
            ins.setBoundName(ac.getBoundName());
            a.action = ins;
        } else {
            ActionInsertLogicalFact ins = new ActionInsertLogicalFact(ac.getFactType());
            ins.setBoundName(ac.getBoundName());
            a.action = ins;
        }
        actions.add(a);
    }
    ActionInsertFact ins = (ActionInsertFact) a.action;
    ActionFieldValue val = new ActionFieldValue(ac.getFactField(), cell, ac.getType());
    ins.addFieldValue(val);
}
Also used : ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) ActionInsertLogicalFact(org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact)

Example 24 with ActionInsertFact

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

the class BRLRuleModelTest method testRuleModelRHSBoundFacts_NoDuplicates.

@Test
public void testRuleModelRHSBoundFacts_NoDuplicates() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    // Setup Decision Table columns (with existing BRLActionColumn)
    ActionInsertFactCol52 ins = new ActionInsertFactCol52();
    ins.setBoundName("$ins");
    ins.setFactField("rating");
    ins.setFactType("Person");
    ins.setType(DataType.TYPE_STRING);
    dt.getActionCols().add(ins);
    BRLActionColumn brlAction = new BRLActionColumn();
    ActionInsertFact aif1 = new ActionInsertFact("Person");
    aif1.setBoundName("$aif");
    aif1.addFieldValue(new ActionFieldValue("rating", null, DataType.TYPE_STRING));
    aif1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_LITERAL);
    brlAction.getDefinition().add(aif1);
    dt.getActionCols().add(brlAction);
    // Setup RuleModel columns (existing BRLActionColumn being edited)
    BRLRuleModel model = new BRLRuleModel(dt);
    ActionInsertFact aif2 = new ActionInsertFact("Person");
    aif2.setBoundName("$aif");
    aif2.addFieldValue(new ActionFieldValue("rating", null, DataType.TYPE_STRING));
    aif2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_LITERAL);
    model.addRhsItem(aif2);
    // Checks
    assertNotNull(model.getRHSBoundFacts());
    assertEquals(2, model.getRHSBoundFacts().size());
    assertTrue(model.getRHSBoundFacts().contains("$ins"));
    assertTrue(model.getRHSBoundFacts().contains("$aif"));
    ActionInsertFact r1 = model.getRHSBoundFact("$ins");
    assertNotNull(r1);
    assertTrue(r1 instanceof ActionInsertFactCol52ActionInsertFactAdaptor);
    ActionInsertFactCol52ActionInsertFactAdaptor raif1 = (ActionInsertFactCol52ActionInsertFactAdaptor) r1;
    assertEquals("Person", raif1.getFactType());
    assertEquals("rating", raif1.getFieldValues()[0].getField());
    assertEquals(DataType.TYPE_STRING, raif1.getFieldValues()[0].getType());
    assertNull(raif1.getFieldValues()[0].getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, raif1.getFieldValues()[0].getNature());
    ActionInsertFact r2 = model.getRHSBoundFact("$aif");
    assertNotNull(r2);
    assertTrue(r2 instanceof ActionInsertFact);
    ActionInsertFact raif2 = (ActionInsertFact) r2;
    assertEquals("Person", raif2.getFactType());
    assertEquals("rating", raif2.getFieldValues()[0].getField());
    assertEquals(DataType.TYPE_STRING, raif2.getFieldValues()[0].getType());
    assertNull(raif2.getFieldValues()[0].getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, raif2.getFieldValues()[0].getNature());
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) ActionInsertFactCol52ActionInsertFactAdaptor(org.drools.workbench.models.guided.dtable.shared.model.adaptors.ActionInsertFactCol52ActionInsertFactAdaptor) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) Test(org.junit.Test)

Example 25 with ActionInsertFact

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

the class BRLRuleModelTest method testRuleModelRHSBoundFacts.

@Test
public void testRuleModelRHSBoundFacts() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    // Setup Decision Table columns
    ActionInsertFactCol52 ins = new ActionInsertFactCol52();
    ins.setBoundName("$ins");
    ins.setFactField("rating");
    ins.setFactType("Person");
    ins.setType(DataType.TYPE_STRING);
    dt.getActionCols().add(ins);
    // Setup RuleModel columns (new BRLActionColumn being added)
    BRLRuleModel model = new BRLRuleModel(dt);
    ActionInsertFact aif = new ActionInsertFact("Person");
    aif.setBoundName("$aif");
    aif.addFieldValue(new ActionFieldValue("rating", null, DataType.TYPE_STRING));
    aif.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_LITERAL);
    model.addRhsItem(aif);
    // Checks
    assertNotNull(model.getRHSBoundFacts());
    assertEquals(2, model.getRHSBoundFacts().size());
    assertTrue(model.getRHSBoundFacts().contains("$ins"));
    assertTrue(model.getRHSBoundFacts().contains("$aif"));
    ActionInsertFact r1 = model.getRHSBoundFact("$ins");
    assertNotNull(r1);
    assertTrue(r1 instanceof ActionInsertFactCol52ActionInsertFactAdaptor);
    ActionInsertFactCol52ActionInsertFactAdaptor raif1 = (ActionInsertFactCol52ActionInsertFactAdaptor) r1;
    assertEquals("Person", raif1.getFactType());
    assertEquals("rating", raif1.getFieldValues()[0].getField());
    assertEquals(DataType.TYPE_STRING, raif1.getFieldValues()[0].getType());
    assertNull(raif1.getFieldValues()[0].getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, raif1.getFieldValues()[0].getNature());
    ActionInsertFact r2 = model.getRHSBoundFact("$aif");
    assertNotNull(r2);
    assertTrue(r2 instanceof ActionInsertFact);
    ActionInsertFact raif2 = (ActionInsertFact) r2;
    assertEquals("Person", raif2.getFactType());
    assertEquals("rating", raif2.getFieldValues()[0].getField());
    assertEquals(DataType.TYPE_STRING, raif2.getFieldValues()[0].getType());
    assertNull(raif2.getFieldValues()[0].getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, raif2.getFieldValues()[0].getNature());
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) ActionInsertFactCol52ActionInsertFactAdaptor(org.drools.workbench.models.guided.dtable.shared.model.adaptors.ActionInsertFactCol52ActionInsertFactAdaptor) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) Test(org.junit.Test)

Aggregations

ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)78 Test (org.junit.Test)64 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)48 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)47 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)43 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)42 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)39 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)34 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)34 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)34 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)32 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)24 IAction (org.drools.workbench.models.datamodel.rule.IAction)17 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)13 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)12 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)12 ArrayList (java.util.ArrayList)11 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)10 RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)10 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)10