Search in sources :

Example 1 with ActionInsertFactCol52

use of org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52 in project drools by kiegroup.

the class GuidedDTDRLPersistence method doActions.

void doActions(List<BaseColumn> allColumns, List<ActionCol52> actionCols, TemplateDataProvider rowDataProvider, List<DTCellValue52> row, RuleModel rm) {
    List<LabelledAction> actions = new ArrayList<LabelledAction>();
    for (ActionCol52 c : actionCols) {
        if (c instanceof LimitedEntryBRLActionColumn) {
            doAction(allColumns, (LimitedEntryBRLActionColumn) c, actions, rowDataProvider, row, rm);
        } else if (c instanceof BRLActionColumn) {
            doAction(allColumns, (BRLActionColumn) c, actions, rowDataProvider, row, rm);
        } else {
            int index = allColumns.indexOf(c);
            DTCellValue52 dcv = row.get(index);
            String cell = "";
            if (c instanceof LimitedEntryCol) {
                if (dcv.getBooleanValue() == true) {
                    LimitedEntryCol lec = (LimitedEntryCol) c;
                    cell = GuidedDTDRLUtilities.convertDTCellValueToString(lec.getValue());
                }
            } else {
                cell = GuidedDTDRLUtilities.convertDTCellValueToString(dcv);
            }
            if (validCell(cell, dcv.getDataType())) {
                if (c instanceof ActionWorkItemInsertFactCol52) {
                    doAction(actions, (ActionWorkItemInsertFactCol52) c, cell);
                } else if (c instanceof ActionInsertFactCol52) {
                    doAction(actions, (ActionInsertFactCol52) c, cell);
                } else if (c instanceof ActionWorkItemSetFieldCol52) {
                    doAction(actions, (ActionWorkItemSetFieldCol52) c, cell);
                } else if (c instanceof ActionSetFieldCol52) {
                    doAction(actions, (ActionSetFieldCol52) c, cell);
                } else if (c instanceof ActionRetractFactCol52) {
                    doAction(actions, cell);
                } else if (c instanceof ActionWorkItemCol52) {
                    doAction(actions, (ActionWorkItemCol52) c, cell);
                }
            }
        }
    }
    rm.rhs = new IAction[actions.size()];
    for (int i = 0; i < rm.rhs.length; i++) {
        rm.rhs[i] = actions.get(i).action;
    }
}
Also used : ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) ActionWorkItemInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemInsertFactCol52) ActionRetractFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52) ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) ArrayList(java.util.ArrayList) ActionWorkItemSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemSetFieldCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) LimitedEntryCol(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol) LimitedEntryBRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryBRLActionColumn) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) LimitedEntryBRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryBRLActionColumn)

Example 2 with ActionInsertFactCol52

use of org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52 in project drools by kiegroup.

the class GuidedDecisionTableUpgradeHelper1 method makeNewColumn.

private ActionInsertFactCol52 makeNewColumn(ActionInsertFactCol c) {
    ActionInsertFactCol52 nc = new ActionInsertFactCol52();
    nc.setBoundName(c.boundName);
    nc.setDefaultValue(new DTCellValue52(c.defaultValue));
    nc.setFactField(c.factField);
    nc.setFactType(c.factType);
    nc.setHeader(c.header);
    nc.setHideColumn(c.hideColumn);
    nc.setType(c.type);
    nc.setValueList(c.valueList);
    nc.setWidth(c.width);
    return nc;
}
Also used : ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)

Example 3 with ActionInsertFactCol52

use of org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52 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 4 with ActionInsertFactCol52

use of org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52 in project drools by kiegroup.

the class BRLRuleModelTest method testRuleModelWithRHSBoundFactsUsageWithActionInsertFact.

@Test
public void testRuleModelWithRHSBoundFactsUsageWithActionInsertFact() {
    final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    // Setup Decision Table columns
    final Pattern52 p1 = new Pattern52();
    p1.setFactType("Driver");
    p1.setBoundName("$d");
    dt.getConditions().add(p1);
    final ActionInsertFactCol52 ins = new ActionInsertFactCol52();
    ins.setBoundName("$ins");
    ins.setFactField("rating");
    ins.setFactType("Person");
    ins.setType(DataType.TYPE_STRING);
    dt.getActionCols().add(ins);
    final BRLRuleModel model = new BRLRuleModel(dt);
    // Checks
    assertTrue(model.isBoundFactUsed("$ins"));
    assertFalse(model.isBoundFactUsed("$cheese"));
}
Also used : 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) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) Test(org.junit.Test)

Example 5 with ActionInsertFactCol52

use of org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52 in project drools by kiegroup.

the class BRLRuleModelTest method testDecisionTableColumnsWithLHSBoundFacts.

@Test
public void testDecisionTableColumnsWithLHSBoundFacts() {
    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.getLHSBoundFacts());
    assertEquals(2, model.getLHSBoundFacts().size());
    assertTrue(model.getLHSBoundFacts().contains("$p1"));
    assertTrue(model.getLHSBoundFacts().contains("$brl1"));
    assertNotNull(model.getLHSBindingType("$p1"));
    assertEquals("Driver", model.getLHSBindingType("$p1"));
    assertNotNull(model.getLHSBindingType("$brl1"));
    assertEquals("Driver", model.getLHSBindingType("$brl1"));
    FactPattern r1 = model.getLHSBoundFact("$p1");
    assertNotNull(r1);
    assertTrue(r1 instanceof Pattern52FactPatternAdaptor);
    Pattern52FactPatternAdaptor raif1 = (Pattern52FactPatternAdaptor) r1;
    assertEquals("Driver", raif1.getFactType());
    FactPattern r2 = model.getLHSBoundFact("$brl1");
    assertNotNull(r2);
    assertEquals("Driver", r2.getFactType());
}
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) Pattern52FactPatternAdaptor(org.drools.workbench.models.guided.dtable.shared.model.adaptors.Pattern52FactPatternAdaptor) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) Test(org.junit.Test)

Aggregations

ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)105 Test (org.junit.Test)74 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)43 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)40 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)39 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)38 LimitedEntryActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)32 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)24 LimitedEntryActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52)20 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)20 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)20 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)20 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)20 Path (org.uberfire.backend.vfs.Path)20 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)19 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)19 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)15 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)14 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)13 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)13