Search in sources :

Example 46 with DescriptionCol52

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

the class GuidedDecisionTableUpgradeHelper1 method upgrade.

/**
 * Convert the legacy Decision Table model to the new
 *
 * @param legacyDTModel
 * @return The new DTModel
 */
public GuidedDecisionTable52 upgrade(GuidedDecisionTable legacyDTModel) {
    assertConditionColumnPatternGrouping(legacyDTModel);
    GuidedDecisionTable52 newDTModel = new GuidedDecisionTable52();
    newDTModel.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY);
    newDTModel.setTableName(legacyDTModel.tableName);
    newDTModel.setParentName(legacyDTModel.parentName);
    newDTModel.setRowNumberCol(new RowNumberCol52());
    newDTModel.setDescriptionCol(new DescriptionCol52());
    // a String metadata attribute is: "value", a numerical: 1. No conversion action required
    if (legacyDTModel.metadataCols != null) {
        for (MetadataCol c : legacyDTModel.metadataCols) {
            newDTModel.getMetadataCols().add(makeNewColumn(c));
        }
    }
    // Attribute columns' data-type is based upon the attribute name
    if (legacyDTModel.attributeCols != null) {
        for (AttributeCol c : legacyDTModel.attributeCols) {
            newDTModel.getAttributeCols().add(makeNewColumn(c));
        }
    }
    // Legacy decision tables did not have Condition field data-types. Set all Condition
    // fields to a *sensible* default of String (as this matches legacy behaviour).
    List<Pattern52> patterns = new ArrayList<Pattern52>();
    Map<String, Pattern52> uniquePatterns = new HashMap<String, Pattern52>();
    if (legacyDTModel.conditionCols != null) {
        for (int i = 0; i < legacyDTModel.conditionCols.size(); i++) {
            ConditionCol c = legacyDTModel.conditionCols.get(i);
            String boundName = c.boundName;
            Pattern52 p = uniquePatterns.get(boundName);
            if (p == null) {
                p = new Pattern52();
                p.setBoundName(boundName);
                p.setFactType(c.factType);
                patterns.add(p);
                uniquePatterns.put(boundName, p);
            }
            if (p.getFactType() != null && !p.getFactType().equals(c.factType)) {
                throw new IllegalArgumentException("Inconsistent FactTypes for ConditionCols bound to '" + boundName + "' detected.");
            }
            p.getChildColumns().add(makeNewColumn(c));
        }
        for (Pattern52 p : patterns) {
            newDTModel.getConditions().add(p);
        }
    }
    // Action columns have a discrete data-type. No conversion action required.
    if (legacyDTModel.actionCols != null) {
        for (ActionCol c : legacyDTModel.actionCols) {
            newDTModel.getActionCols().add(makeNewColumn(c));
        }
    }
    // Copy across data
    newDTModel.setData(DataUtilities.makeDataLists(legacyDTModel.data));
    // Copy the boundName for ActionRetractFactCol into the data of the new Guided Decision Table model
    if (legacyDTModel.actionCols != null) {
        final int metaDataColCount = (legacyDTModel.metadataCols == null ? 0 : legacyDTModel.metadataCols.size());
        final int attributeColCount = (legacyDTModel.attributeCols == null ? 0 : legacyDTModel.attributeCols.size());
        final int conditionColCount = (legacyDTModel.conditionCols == null ? 0 : legacyDTModel.conditionCols.size());
        final int DATA_COLUMN_OFFSET = metaDataColCount + attributeColCount + conditionColCount + GuidedDecisionTable.INTERNAL_ELEMENTS;
        for (int iCol = 0; iCol < legacyDTModel.actionCols.size(); iCol++) {
            ActionCol lc = legacyDTModel.actionCols.get(iCol);
            if (lc instanceof ActionRetractFactCol) {
                String boundName = ((ActionRetractFactCol) lc).boundName;
                for (List<DTCellValue52> row : newDTModel.getData()) {
                    row.get(DATA_COLUMN_OFFSET + iCol).setStringValue(boundName);
                }
            }
        }
    }
    return newDTModel;
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ActionCol(org.drools.workbench.models.guided.dtable.shared.model.legacy.ActionCol) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) MetadataCol(org.drools.workbench.models.guided.dtable.shared.model.legacy.MetadataCol) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) AttributeCol(org.drools.workbench.models.guided.dtable.shared.model.legacy.AttributeCol) ActionRetractFactCol(org.drools.workbench.models.guided.dtable.shared.model.legacy.ActionRetractFactCol) ConditionCol(org.drools.workbench.models.guided.dtable.shared.model.legacy.ConditionCol) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)

Example 47 with DescriptionCol52

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

the class GuidedDTDRLPersistenceTest method testLHSWithBRLColumn_ParseToDRL_NoVariables.

@Test
public // This test checks a Decision Table involving BRL columns is correctly converted into DRL
void testLHSWithBRLColumn_ParseToDRL_NoVariables() {
    GuidedDecisionTable52 dtable = new GuidedDecisionTable52();
    // Row 0 should become an IPattern in the resulting RuleModel as it contains getValue()s for all Template fields in the BRL Column
    // Row 1 should *NOT* become an IPattern in the resulting RuleModel as it does *NOT* contain getValue()s for all Template fields in the BRL Column
    Object[][] data = new Object[][] { new Object[] { "1", "desc", Boolean.TRUE }, new Object[] { "2", "desc", Boolean.FALSE } };
    // Simple (mandatory) columns
    dtable.setRowNumberCol(new RowNumberCol52());
    dtable.setDescriptionCol(new DescriptionCol52());
    // BRL Column
    BRLConditionColumn brl1 = new BRLConditionColumn();
    // BRL Column definition
    List<IPattern> brl1Definition = new ArrayList<IPattern>();
    FactPattern brl1DefinitionFactPattern1 = new FactPattern("Baddie");
    SingleFieldConstraint brl1DefinitionFactPattern1Constraint1 = new SingleFieldConstraint();
    brl1DefinitionFactPattern1Constraint1.setFieldType(DataType.TYPE_STRING);
    brl1DefinitionFactPattern1Constraint1.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    brl1DefinitionFactPattern1Constraint1.setFieldName("name");
    brl1DefinitionFactPattern1Constraint1.setOperator("==");
    brl1DefinitionFactPattern1Constraint1.setValue("Gargamel");
    brl1DefinitionFactPattern1.addConstraint(brl1DefinitionFactPattern1Constraint1);
    brl1Definition.add(brl1DefinitionFactPattern1);
    brl1.setDefinition(brl1Definition);
    // Setup BRL column bindings
    BRLConditionVariableColumn brl1Variable1 = new BRLConditionVariableColumn("", DataType.TYPE_BOOLEAN);
    brl1.getChildColumns().add(brl1Variable1);
    dtable.getConditions().add(brl1);
    dtable.setData(DataUtilities.makeDataLists(data));
    // Now to test conversion
    int ruleStartIndex;
    int pattern1StartIndex;
    GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
    String drl = p.marshal(dtable);
    // Row 0
    ruleStartIndex = drl.indexOf("//from row number: 1");
    assertFalse(ruleStartIndex == -1);
    pattern1StartIndex = drl.indexOf("Baddie( name == \"Gargamel\" )", ruleStartIndex);
    assertFalse(pattern1StartIndex == -1);
    // Row 1
    ruleStartIndex = drl.indexOf("//from row number: 2");
    assertFalse(ruleStartIndex == -1);
    pattern1StartIndex = drl.indexOf("Baddie( name == \"Gargamel\" )", ruleStartIndex);
    assertTrue(pattern1StartIndex == -1);
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ArrayList(java.util.ArrayList) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 48 with DescriptionCol52

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

the class GuidedDTDRLPersistenceTest method testMetaData.

@Test
public void testMetaData() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] { "1", "desc", "bar", "" };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    List<MetadataCol52> metadataCols = new ArrayList<MetadataCol52>();
    RuleModel rm = new RuleModel();
    RuleMetadata[] orig = rm.metadataList;
    // RuleAttribute[] orig = rm.attributes;
    p.doMetadata(allColumns, metadataCols, DataUtilities.makeDataRowList(row), rm);
    assertSame(orig, rm.metadataList);
    MetadataCol52 col1 = new MetadataCol52();
    col1.setMetadata("foo");
    MetadataCol52 col2 = new MetadataCol52();
    col2.setMetadata("foo2");
    metadataCols.add(col1);
    metadataCols.add(col2);
    allColumns.addAll(metadataCols);
    p.doMetadata(allColumns, metadataCols, DataUtilities.makeDataRowList(row), rm);
    assertEquals(1, rm.metadataList.length);
    assertEquals("foo", rm.metadataList[0].getAttributeName());
    assertEquals("bar", rm.metadataList[0].getValue());
    row = new String[] { "1", "desc", "bar1", "bar2" };
    p.doMetadata(allColumns, metadataCols, DataUtilities.makeDataRowList(row), rm);
    assertEquals(2, rm.metadataList.length);
    assertEquals("foo", rm.metadataList[0].getAttributeName());
    assertEquals("bar1", rm.metadataList[0].getValue());
    assertEquals("foo2", rm.metadataList[1].getAttributeName());
    assertEquals("bar2", rm.metadataList[1].getValue());
}
Also used : ArrayList(java.util.ArrayList) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RuleMetadata(org.drools.workbench.models.datamodel.rule.RuleMetadata) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 49 with DescriptionCol52

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

the class GuidedDTDRLPersistenceTest method testLHSWithBRLColumn_ParseToDRL.

@Test
public // This test checks a Decision Table involving BRL columns is correctly converted into DRL
void testLHSWithBRLColumn_ParseToDRL() {
    GuidedDecisionTable52 dtable = new GuidedDecisionTable52();
    // All 3 rows should render, as the code is now lower down for skipping columns with empty cells
    String[][] data = new String[][] { new String[] { "1", "desc", "Gargamel", "Pupa", "50" }, new String[] { "2", "desc", "Gargamel", "", "50" }, new String[] { "3", "desc", "Gargamel", "Pupa", "" } };
    // Simple (mandatory) columns
    dtable.setRowNumberCol(new RowNumberCol52());
    dtable.setDescriptionCol(new DescriptionCol52());
    // Simple Condition
    Pattern52 p1 = new Pattern52();
    p1.setFactType("Baddie");
    ConditionCol52 con = new ConditionCol52();
    con.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    con.setFactField("name");
    con.setOperator("==");
    p1.getChildColumns().add(con);
    dtable.getConditions().add(p1);
    // BRL Column
    BRLConditionColumn brl1 = new BRLConditionColumn();
    // BRL Column definition
    List<IPattern> brl1Definition = new ArrayList<IPattern>();
    FactPattern brl1DefinitionFactPattern1 = new FactPattern("Smurf");
    SingleFieldConstraint brl1DefinitionFactPattern1Constraint1 = new SingleFieldConstraint();
    brl1DefinitionFactPattern1Constraint1.setFieldType(DataType.TYPE_STRING);
    brl1DefinitionFactPattern1Constraint1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    brl1DefinitionFactPattern1Constraint1.setFieldName("name");
    brl1DefinitionFactPattern1Constraint1.setOperator("==");
    brl1DefinitionFactPattern1Constraint1.setValue("$name");
    brl1DefinitionFactPattern1.addConstraint(brl1DefinitionFactPattern1Constraint1);
    SingleFieldConstraint brl1DefinitionFactPattern1Constraint2 = new SingleFieldConstraint();
    brl1DefinitionFactPattern1Constraint2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    brl1DefinitionFactPattern1Constraint2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    brl1DefinitionFactPattern1Constraint2.setFieldName("age");
    brl1DefinitionFactPattern1Constraint2.setOperator("==");
    brl1DefinitionFactPattern1Constraint2.setValue("$age");
    brl1DefinitionFactPattern1.addConstraint(brl1DefinitionFactPattern1Constraint2);
    brl1Definition.add(brl1DefinitionFactPattern1);
    brl1.setDefinition(brl1Definition);
    // Setup BRL column bindings
    BRLConditionVariableColumn brl1Variable1 = new BRLConditionVariableColumn("$name", DataType.TYPE_STRING, "Person", "name");
    brl1.getChildColumns().add(brl1Variable1);
    BRLConditionVariableColumn brl1Variable2 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Person", "age");
    brl1.getChildColumns().add(brl1Variable2);
    dtable.getConditions().add(brl1);
    dtable.setData(DataUtilities.makeDataLists(data));
    // Now to test conversion
    int ruleStartIndex;
    int pattern1StartIndex;
    int pattern2StartIndex;
    GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
    String drl = p.marshal(dtable);
    System.out.println(drl);
    // Row 0
    ruleStartIndex = drl.indexOf("//from row number: 1");
    assertFalse(ruleStartIndex == -1);
    pattern1StartIndex = drl.indexOf("Baddie( name == \"Gargamel\" )", ruleStartIndex);
    assertFalse(pattern1StartIndex == -1);
    pattern2StartIndex = drl.indexOf("Smurf( name == \"Pupa\" , age == 50 )", ruleStartIndex);
    assertFalse(pattern2StartIndex == -1);
    // Row 1
    ruleStartIndex = drl.indexOf("//from row number: 2");
    assertFalse(ruleStartIndex == -1);
    pattern1StartIndex = drl.indexOf("Baddie( name == \"Gargamel\" )", ruleStartIndex);
    assertFalse(pattern1StartIndex == -1);
    pattern2StartIndex = drl.indexOf("Smurf( age == 50 )", ruleStartIndex);
    assertFalse(pattern2StartIndex == -1);
    // Row 2
    ruleStartIndex = drl.indexOf("//from row number: 3");
    assertFalse(ruleStartIndex == -1);
    pattern1StartIndex = drl.indexOf("Baddie( name == \"Gargamel\" )", ruleStartIndex);
    assertFalse(pattern1StartIndex == -1);
    pattern2StartIndex = drl.indexOf("Smurf( name == \"Pupa\" )", ruleStartIndex);
    assertFalse(pattern2StartIndex == -1);
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ArrayList(java.util.ArrayList) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 50 with DescriptionCol52

use of org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52 in project drools-wb by kiegroup.

the class GuidedDecisionTableSourceServiceTest method setUp.

@Before
public void setUp() throws Exception {
    service = new GuidedDecisionTableSourceService(resourceTypeDefinition, guidedDecisionTableEditorService, ioService, fileDiscoveryService, moduleService);
    // Simulates that no DSL files are present
    when(moduleService.resolvePackage(any())).thenReturn(packageMock);
    when(discoveryService.discoverFiles(any(), any())).thenReturn(new ArrayList<Path>());
    when(fileSystem.supportedFileAttributeViews()).thenReturn(new HashSet<String>());
    when(path.getFileSystem()).thenReturn(fileSystem);
    when(path.toString()).thenReturn("/");
    when(path.getFileName()).thenReturn(path);
    when(path.toUri()).thenReturn(new URI("/"));
    model = new GuidedDecisionTable52();
    model.setPackageName("com.sample");
    model.setImports(new Imports(Arrays.asList(new Import("com.sample.Person"))));
    model.setRowNumberCol(new RowNumberCol52());
    model.setDescriptionCol(new DescriptionCol52());
    pattern = new Pattern52();
    pattern.setBoundName("$p");
    pattern.setFactType("Person");
    nameEqualToLiteralCondition = new ConditionCol52();
    nameEqualToLiteralCondition.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    nameEqualToLiteralCondition.setHeader("name equals to");
    nameEqualToLiteralCondition.setFactField("name");
    nameEqualToLiteralCondition.setOperator("==");
    pattern.setChildColumns(Arrays.asList(nameEqualToLiteralCondition));
    model.setConditionPatterns(Arrays.asList(pattern));
    data = new ArrayList<>();
}
Also used : Path(org.uberfire.java.nio.file.Path) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Import(org.kie.soup.project.datamodel.imports.Import) Imports(org.kie.soup.project.datamodel.imports.Imports) URI(java.net.URI) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Before(org.junit.Before)

Aggregations

DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)68 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)66 Test (org.junit.Test)59 ArrayList (java.util.ArrayList)47 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)43 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)33 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)24 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)23 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)23 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)22 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)22 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)21 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)21 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)21 GuidedDTTemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider)19 TemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider)19 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)19 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)18 IOException (java.io.IOException)17 InputStream (java.io.InputStream)17