Search in sources :

Example 31 with DTCellValue52

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

the class GuidedDTDRLPersistenceResolvedHitPolicyTest method prioritiesSet.

@Test
public void prioritiesSet() throws Exception {
    final MetadataCol52 metadataCol = new MetadataCol52();
    metadataCol.setMetadata(GuidedDecisionTable52.HitPolicy.RESOLVED_HIT_METADATA_NAME);
    dtable.getMetadataCols().add(metadataCol);
    int indexOf = dtable.getExpandedColumns().indexOf(metadataCol);
    int index = 0;
    for (final List<DTCellValue52> row : dtable.getData()) {
        final DTCellValue52 element = new DTCellValue52();
        element.setStringValue(Integer.toString(index++));
        row.add(indexOf, element);
    }
    final String drl = GuidedDTDRLPersistence.getInstance().marshal(dtable);
    assertContainsLinesInOrder(drl, "rule \"Row 1 Resolved hit policy table\"", "activation-group \"resolved-hit-policy-group Resolved hit policy table\"", "salience 0", "rule \"Row 2 Resolved hit policy table\"", "activation-group \"resolved-hit-policy-group Resolved hit policy table\"", "salience 1", "rule \"Row 3 Resolved hit policy table\"", "activation-group \"resolved-hit-policy-group Resolved hit policy table\"", "salience 2");
}
Also used : MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) Test(org.junit.Test)

Example 32 with DTCellValue52

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

the class GuidedDTDRLPersistenceResolvedHitPolicyTest method blockUseOfSalience.

@Test(expected = IllegalArgumentException.class)
public void blockUseOfSalience() {
    final AttributeCol52 attributeCol52 = new AttributeCol52();
    attributeCol52.setAttribute("salience");
    attributeCol52.setDefaultValue(new DTCellValue52("123"));
    dtable.getAttributeCols().add(attributeCol52);
    GuidedDTDRLPersistence.getInstance().marshal(dtable);
}
Also used : AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) Test(org.junit.Test)

Example 33 with DTCellValue52

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

the class GuidedDTDRLPersistenceTest method testLHS.

@Test
public void testLHS() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] { "1", "desc", "a", "mike", "33 + 1", "age > 6", "stilton" };
    String[][] data = new String[1][];
    data[0] = row;
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    List<CompositeColumn<? extends BaseColumn>> allPatterns = new ArrayList<CompositeColumn<? extends BaseColumn>>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    allColumns.add(new MetadataCol52());
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("p1");
    p1.setFactType("Person");
    allPatterns.add(p1);
    ConditionCol52 col = new ConditionCol52();
    col.setFactField("name");
    col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    col.setOperator("==");
    p1.getChildColumns().add(col);
    allColumns.add(col);
    ConditionCol52 col2 = new ConditionCol52();
    col2.setFactField("age");
    col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_RET_VALUE);
    col2.setOperator("<");
    p1.getChildColumns().add(col2);
    allColumns.add(col2);
    ConditionCol52 col3 = new ConditionCol52();
    col3.setConstraintValueType(BaseSingleFieldConstraint.TYPE_PREDICATE);
    p1.getChildColumns().add(col3);
    allColumns.add(col3);
    Pattern52 p2 = new Pattern52();
    p2.setBoundName("c");
    p2.setFactType("Cheese");
    allPatterns.add(p2);
    ConditionCol52 col4 = new ConditionCol52();
    col4.setFactField("type");
    col4.setOperator("==");
    col4.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    p2.getChildColumns().add(col4);
    allColumns.add(col4);
    RuleModel rm = new RuleModel();
    List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
    TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
    p.doConditions(allColumns, allPatterns, rowDataProvider, rowData, DataUtilities.makeDataLists(data), rm);
    assertEquals(2, rm.lhs.length);
    assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
    assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
    assertEquals("Cheese", ((FactPattern) rm.lhs[1]).getFactType());
    assertEquals("c", ((FactPattern) rm.lhs[1]).getBoundName());
    // examine the first pattern
    FactPattern person = (FactPattern) rm.lhs[0];
    assertEquals(3, person.getConstraintList().getConstraints().length);
    SingleFieldConstraint cons = (SingleFieldConstraint) person.getConstraint(0);
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cons.getConstraintValueType());
    assertEquals("name", cons.getFieldName());
    assertEquals("==", cons.getOperator());
    assertEquals("mike", cons.getValue());
    cons = (SingleFieldConstraint) person.getConstraint(1);
    assertEquals(BaseSingleFieldConstraint.TYPE_RET_VALUE, cons.getConstraintValueType());
    assertEquals("age", cons.getFieldName());
    assertEquals("<", cons.getOperator());
    assertEquals("33 + 1", cons.getValue());
    cons = (SingleFieldConstraint) person.getConstraint(2);
    assertEquals(BaseSingleFieldConstraint.TYPE_PREDICATE, cons.getConstraintValueType());
    assertEquals("age > 6", cons.getValue());
    // examine the second pattern
    FactPattern cheese = (FactPattern) rm.lhs[1];
    assertEquals(1, cheese.getConstraintList().getConstraints().length);
    cons = (SingleFieldConstraint) cheese.getConstraint(0);
    assertEquals("type", cons.getFieldName());
    assertEquals("==", cons.getOperator());
    assertEquals("stilton", cons.getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cons.getConstraintValueType());
}
Also used : ArrayList(java.util.ArrayList) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeColumn(org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn) MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) 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) 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 34 with DTCellValue52

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

the class GuidedDTDRLPersistenceTest method testLHSOtherwisePatternString.

@Test
public void testLHSOtherwisePatternString() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[][] row = new String[3][];
    String[][] data = new String[3][];
    row[0] = new String[] { "1", "desc1", "Michael1", "Michael1" };
    List<DTCellValue52> rowDTModel0 = DataUtilities.makeDataRowList(row[0]);
    data[0] = row[0];
    row[1] = new String[] { "2", "desc2", "Michael2", "Michael2" };
    List<DTCellValue52> rowDTModel1 = DataUtilities.makeDataRowList(row[1]);
    data[1] = row[1];
    row[2] = new String[] { "3", "desc3", "", "" };
    List<DTCellValue52> rowDTModel2 = DataUtilities.makeDataRowList(row[2]);
    rowDTModel2.get(2).setOtherwise(true);
    rowDTModel2.get(3).setOtherwise(true);
    data[2] = row[2];
    final List<List<DTCellValue52>> allDTData = new ArrayList<List<DTCellValue52>>() {

        {
            add(rowDTModel0);
            add(rowDTModel1);
            add(rowDTModel2);
        }
    };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    List<CompositeColumn<? extends BaseColumn>> allPatterns = new ArrayList<CompositeColumn<? extends BaseColumn>>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("p1");
    p1.setFactType("Person");
    allPatterns.add(p1);
    ConditionCol52 col = new ConditionCol52();
    col.setFactField("name");
    col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    col.setFieldType(DataType.TYPE_STRING);
    col.setOperator("==");
    p1.getChildColumns().add(col);
    allColumns.add(col);
    Pattern52 p2 = new Pattern52();
    p2.setBoundName("p2");
    p2.setFactType("Person");
    allPatterns.add(p2);
    ConditionCol52 col2 = new ConditionCol52();
    col2.setFactField("name");
    col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    col2.setFieldType(DataType.TYPE_STRING);
    col2.setOperator("!=");
    p2.getChildColumns().add(col2);
    allColumns.add(col2);
    RuleModel rm = new RuleModel();
    TemplateDataProvider rowDataProvider0 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel0);
    p.doConditions(allColumns, allPatterns, rowDataProvider0, rowDTModel0, allDTData, rm);
    String drl0 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
    assertEquals(2, rm.lhs.length);
    assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
    assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
    assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
    assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
    assertTrue(drl0.indexOf("p1 : Person( name == \"Michael1\" )") > 0);
    assertTrue(drl0.indexOf("p2 : Person( name != \"Michael1\" )") > 0);
    TemplateDataProvider rowDataProvider1 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel1);
    p.doConditions(allColumns, allPatterns, rowDataProvider1, rowDTModel1, allDTData, rm);
    String drl1 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
    assertEquals(2, rm.lhs.length);
    assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
    assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
    assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
    assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
    assertTrue(drl1.indexOf("p1 : Person( name == \"Michael2\" )") > 0);
    assertTrue(drl1.indexOf("p2 : Person( name != \"Michael2\" )") > 0);
    TemplateDataProvider rowDataProvider2 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel2);
    p.doConditions(allColumns, allPatterns, rowDataProvider2, rowDTModel2, allDTData, rm);
    String drl2 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
    assertEquals(2, rm.lhs.length);
    assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
    assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
    assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
    assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
    assertTrue(drl2.indexOf("p1 : Person( name not in ( \"Michael1\", \"Michael2\" )") > 0);
    assertTrue(drl2.indexOf("p2 : Person( name in ( \"Michael1\", \"Michael2\" )") > 0);
}
Also used : ArrayList(java.util.ArrayList) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeColumn(org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn) 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) List(java.util.List) ArrayList(java.util.ArrayList) 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 35 with DTCellValue52

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

the class DecisionTableAnalyzerTest method testRedundancy.

@Test
public void testRedundancy() throws Exception {
    table52 = new LimitedGuidedDecisionTableBuilder("org.test", new ArrayList<Import>(), "mytable").withIntegerColumn("a", "Person", "age", "==", 0).withAction("a", "Person", "approved", new DTCellValue52() {

        {
            setBooleanValue(true);
        }
    }).withAction("a", "Person", "approved", new DTCellValue52() {

        {
            setBooleanValue(true);
        }
    }).withData(new Object[][] { { 1, "description", true, true, false }, { 2, "description", true, false, true } }).buildTable();
    fireUpAnalyzer();
    assertContains(analyzerProvider.getAnalysisReport(), REDUNDANT_ROWS, Severity.WARNING, 1, 2);
    assertNotNull(analyzerProvider.getStatus());
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) LimitedGuidedDecisionTableBuilder(org.drools.workbench.services.verifier.webworker.client.testutil.LimitedGuidedDecisionTableBuilder) Test(org.junit.Test)

Aggregations

DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)244 Test (org.junit.Test)121 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)53 ArrayList (java.util.ArrayList)51 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)46 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)46 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)39 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)39 AttributeCol52 (org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52)30 List (java.util.List)29 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)28 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)27 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)25 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)24 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)23 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)21 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)20 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)20 GuidedDTTemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider)20 TemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider)20