Search in sources :

Example 1 with GuidedDecisionTable52

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

the class GuidedDTDRLPersistence method marshal.

public String marshal(final GuidedDecisionTable52 originalDTable) {
    final GuidedDecisionTable52 dt = DecisionTableHitPolicyEnhancer.enhance(originalDTable);
    StringBuilder sb = new StringBuilder();
    List<List<DTCellValue52>> data = dt.getData();
    List<BaseColumn> allColumns = dt.getExpandedColumns();
    // Append package name and imports to DRL
    PackageNameWriter.write(sb, dt);
    ImportsWriter.write(sb, dt);
    // Build rules
    for (int i = 0; i < data.size(); i++) {
        List<DTCellValue52> row = data.get(i);
        // Specialised BRDRLPersistence provider than can handle template key expansion
        TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, row);
        Integer num = (Integer) row.get(0).getNumericValue();
        String desc = row.get(1).getStringValue();
        BRLRuleModel rm = new BRLRuleModel(dt);
        rm.name = getName(dt.getTableName(), num);
        doMetadata(allColumns, dt.getMetadataCols(), row, rm);
        doAttribs(allColumns, dt.getAttributeCols(), row, rm);
        doConditions(allColumns, dt.getConditions(), rowDataProvider, row, data, rm);
        doActions(allColumns, dt.getActionCols(), rowDataProvider, row, rm);
        if (dt.getParentName() != null) {
            rm.parentName = dt.getParentName();
        }
        sb.append("//from row number: " + (i + 1) + "\n");
        if (desc != null && desc.length() > 0) {
            sb.append("//" + desc + "\n");
        }
        GuidedDTBRDRLPersistence drlMarshaller = new GuidedDTBRDRLPersistence(rowDataProvider);
        String rule = drlMarshaller.marshal(rm);
        sb.append(rule);
        sb.append("\n");
    }
    return sb.toString();
}
Also used : GuidedDTBRDRLPersistence(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTBRDRLPersistence) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) List(java.util.List) ActionFieldList(org.drools.workbench.models.datamodel.rule.ActionFieldList) ArrayList(java.util.ArrayList) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) TemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider)

Example 2 with GuidedDecisionTable52

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

the class GuidedDTXMLPersistence method unmarshal.

public GuidedDecisionTable52 unmarshal(String xml) {
    if (xml == null || xml.trim().equals("")) {
        return new GuidedDecisionTable52();
    }
    // Upgrade DTModel to new class
    Object model = xt.fromXML(xml);
    GuidedDecisionTable52 newDTModel;
    if (model instanceof GuidedDecisionTable) {
        GuidedDecisionTable legacyDTModel = (GuidedDecisionTable) model;
        newDTModel = upgrader1.upgrade(legacyDTModel);
    } else {
        newDTModel = (GuidedDecisionTable52) model;
    }
    // Upgrade RowNumber, Salience and Duration data-types are correct
    newDTModel = upgrader2.upgrade(newDTModel);
    // Upgrade Default Values to typed equivalents
    newDTModel = upgrader3.upgrade(newDTModel);
    return newDTModel;
}
Also used : GuidedDecisionTable(org.drools.workbench.models.guided.dtable.shared.model.legacy.GuidedDecisionTable) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)

Example 3 with GuidedDecisionTable52

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

the class GuidedDecisionTableUpgradeHelper3 method upgrade.

/**
 * Convert the Default Values in the Decision Table model
 *
 * @param source
 * @return The new DTModel
 */
public GuidedDecisionTable52 upgrade(GuidedDecisionTable52 source) {
    final GuidedDecisionTable52 destination = source;
    for (BaseColumn column : source.getExpandedColumns()) {
        DTColumnConfig52 dtColumn = null;
        if (column instanceof MetadataCol52) {
            dtColumn = (DTColumnConfig52) column;
        } else if (column instanceof AttributeCol52) {
            dtColumn = (DTColumnConfig52) column;
        } else if (column instanceof ConditionCol52) {
            dtColumn = (DTColumnConfig52) column;
        } else if (column instanceof ActionCol52) {
            dtColumn = (DTColumnConfig52) column;
        }
        if (dtColumn instanceof LimitedEntryCol) {
            dtColumn = null;
        }
        if (dtColumn instanceof BRLVariableColumn) {
            dtColumn = null;
        }
        if (dtColumn != null) {
            final String legacyDefaultValue = dtColumn.defaultValue;
            if (legacyDefaultValue != null) {
                dtColumn.setDefaultValue(new DTCellValue52(legacyDefaultValue));
                dtColumn.defaultValue = null;
            }
        }
    }
    return destination;
}
Also used : MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) DTColumnConfig52(org.drools.workbench.models.guided.dtable.shared.model.DTColumnConfig52) BRLVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) LimitedEntryCol(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol)

Example 4 with GuidedDecisionTable52

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

the class BRLRuleModelTest method testUpdateModifyMultipleFieldsWithMultipleSkipped4.

@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped4() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("x");
    p1.setFactType("Context");
    ConditionCol52 c = new ConditionCol52();
    c.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    p1.getChildColumns().add(c);
    dt.getConditions().add(p1);
    BRLActionColumn brlAction1 = new BRLActionColumn();
    ActionUpdateField auf1 = new ActionUpdateField("x");
    auf1.addFieldValue(new ActionFieldValue("f1", "$f1", DataType.TYPE_STRING));
    auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brlAction1.getDefinition().add(auf1);
    brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f1", DataType.TYPE_STRING, "Context", "f1"));
    ActionUpdateField auf2 = new ActionUpdateField("x");
    auf2.addFieldValue(new ActionFieldValue("f2", "$f2", DataType.TYPE_STRING));
    auf2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brlAction1.getDefinition().add(auf2);
    brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f2", DataType.TYPE_STRING, "Context", "f2"));
    ActionUpdateField auf3 = new ActionUpdateField("x");
    auf3.addFieldValue(new ActionFieldValue("f3", "$f3", DataType.TYPE_STRING));
    auf3.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brlAction1.getDefinition().add(auf3);
    brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f3", DataType.TYPE_STRING, "Context", "f3"));
    dt.getActionCols().add(brlAction1);
    dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "x", "v1", null, "v3" } }));
    String drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
    final String expected = "//from row number: 1\n" + "//desc\n" + "rule \"Row 1 null\"\n" + "dialect \"mvel\"\n" + "when\n" + "  x : Context( )\n" + "then\n" + "  modify( x ) {\n" + "    setF1( \"v1\" ),\n" + "    setF3( \"v3\" )\n" + "}\n" + "end\n";
    assertEqualsIgnoreWhitespace(expected, drl);
}
Also used : ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) Test(org.junit.Test)

Example 5 with GuidedDecisionTable52

use of org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52 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)

Aggregations

GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)262 Test (org.junit.Test)193 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)92 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)74 Path (org.uberfire.backend.vfs.Path)52 ArrayList (java.util.ArrayList)51 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)51 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)47 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)39 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)37 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)35 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)33 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)33 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)33 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)32 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)31 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)27 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)27 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)26 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)26