Search in sources :

Example 26 with DataListener

use of org.drools.template.parser.DataListener in project drools-wb by kiegroup.

the class GuidedDecisionTableGeneratorListenerTest method testSequentialSalience.

@Test
public void testSequentialSalience() {
    final ConversionResult result = new ConversionResult();
    final List<DataListener> listeners = new ArrayList<DataListener>();
    final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
    listeners.add(listener);
    // Convert
    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream is = this.getClass().getResourceAsStream("SequentialSalience.xls");
    try {
        parser.parseFile(is);
    } finally {
        try {
            is.close();
        } catch (IOException ioe) {
            fail(ioe.getMessage());
        }
    }
    // Check conversion results
    assertEquals(0, result.getMessages().size());
    // Check basics
    List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
    assertNotNull(dtables);
    assertEquals(1, dtables.size());
    GuidedDecisionTable52 dtable = dtables.get(0);
    assertEquals("SequentialSalienceTest", dtable.getTableName());
    assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
    // Check expanded columns
    List<BaseColumn> columns = dtable.getExpandedColumns();
    assertNotNull(columns);
    assertEquals(3, columns.size());
    assertTrue(columns.get(0) instanceof RowNumberCol52);
    assertTrue(columns.get(1) instanceof DescriptionCol52);
    assertTrue(columns.get(2) instanceof AttributeCol52);
    // Check attribute column
    AttributeCol52 attrCol2 = ((AttributeCol52) columns.get(2));
    assertEquals(GuidedDecisionTable52.SALIENCE_ATTR, attrCol2.getAttribute());
    assertTrue(attrCol2.isUseRowNumber());
    assertTrue(attrCol2.isReverseOrder());
    // Check data
    assertEquals(2, dtable.getData().size());
    assertTrue(isRowEquivalent(new Object[] { 1, "Rule 1", 2 }, dtable.getData().get(0)));
    assertTrue(isRowEquivalent(new Object[] { 2, "Rule 2", 1 }, dtable.getData().get(1)));
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) DataListener(org.drools.template.parser.DataListener) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 27 with DataListener

use of org.drools.template.parser.DataListener in project drools-wb by kiegroup.

the class GuidedDecisionTableGeneratorListenerTest method testMetadata.

@Test
public void testMetadata() {
    final ConversionResult result = new ConversionResult();
    final List<DataListener> listeners = new ArrayList<DataListener>();
    final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
    listeners.add(listener);
    // Convert
    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream is = this.getClass().getResourceAsStream("Metadata.xls");
    try {
        parser.parseFile(is);
    } finally {
        try {
            is.close();
        } catch (IOException ioe) {
            fail(ioe.getMessage());
        }
    }
    // Check conversion results
    assertEquals(0, result.getMessages().size());
    // Check basics
    List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
    assertNotNull(dtables);
    assertEquals(1, dtables.size());
    GuidedDecisionTable52 dtable = dtables.get(0);
    assertEquals("MetadataTest", dtable.getTableName());
    assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
    // Check expanded columns
    List<BaseColumn> columns = dtable.getExpandedColumns();
    assertNotNull(columns);
    assertEquals(3, columns.size());
    assertTrue(columns.get(0) instanceof RowNumberCol52);
    assertTrue(columns.get(1) instanceof DescriptionCol52);
    assertTrue(columns.get(2) instanceof MetadataCol52);
    // Check metadata column
    MetadataCol52 mdCol2 = ((MetadataCol52) columns.get(2));
    assertEquals("cheese", mdCol2.getMetadata());
    // Check data
    assertEquals(2, dtable.getData().size());
    assertTrue(isRowEquivalent(new Object[] { 1, "Rule 1", "cheddar" }, dtable.getData().get(0)));
    assertTrue(isRowEquivalent(new Object[] { 2, "Rule 2", "edam" }, dtable.getData().get(1)));
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) DataListener(org.drools.template.parser.DataListener) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 28 with DataListener

use of org.drools.template.parser.DataListener in project drools-wb by kiegroup.

the class GuidedDecisionTableGeneratorListenerTest method conversionWithBigDecimals.

@Test
public // https://issues.jboss.org/browse/RHBPMS-4737
void conversionWithBigDecimals() {
    final ConversionResult result = new ConversionResult();
    final List<DataListener> listeners = new ArrayList<>();
    addModelField("org.test.Message", "this", "org.test.Message", DataType.TYPE_THIS);
    addModelField("org.test.Message", "status", String.class.getName(), DataType.TYPE_STRING);
    addModelField("org.test.Message", "message", String.class.getName(), DataType.TYPE_STRING);
    addModelField("org.test.Message", "rate", BigDecimal.class.getName(), DataType.TYPE_NUMERIC_BIGDECIMAL);
    addModelField("org.test.Reply", "this", "org.test.Reply", DataType.TYPE_THIS);
    addModelField("org.test.Reply", "message", String.class.getName(), DataType.TYPE_STRING);
    final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
    listeners.add(listener);
    // Convert
    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream is = this.getClass().getResourceAsStream("RHBPMS-4737 (BigDecimal).xlsx");
    try {
        parser.parseFile(is);
    } finally {
        try {
            is.close();
        } catch (IOException ioe) {
            fail(ioe.getMessage());
        }
    }
    checkConversionWithBigMaths(result, listener, () -> DataType.TYPE_NUMERIC_BIGDECIMAL, () -> new BigDecimal("10.00"), () -> new BigDecimal("20.00"));
}
Also used : ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) DataListener(org.drools.template.parser.DataListener) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 29 with DataListener

use of org.drools.template.parser.DataListener in project drools-wb by kiegroup.

the class DecisionTableXLSToDecisionTableGuidedConverter method parseAssets.

private GuidedDecisionTableGeneratorListener parseAssets(final Path path, final ConversionResult result, final PackageDataModelOracle dmo) {
    final List<DataListener> listeners = new ArrayList<DataListener>();
    final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
    listeners.add(listener);
    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream stream = ioService.newInputStream(Paths.convert(path));
    try {
        parser.parseFile(stream);
    } finally {
        try {
            stream.close();
        } catch (IOException ioe) {
            result.addMessage(ioe.getMessage(), ConversionMessageType.ERROR);
        }
    }
    return listener;
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) DataListener(org.drools.template.parser.DataListener) IOException(java.io.IOException)

Aggregations

ArrayList (java.util.ArrayList)29 DataListener (org.drools.template.parser.DataListener)29 ExcelParser (org.drools.decisiontable.parser.xls.ExcelParser)28 InputStream (java.io.InputStream)26 Test (org.junit.Test)25 IOException (java.io.IOException)24 ConversionResult (org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult)23 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)18 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)17 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)17 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)17 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)11 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)10 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)10 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)10 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)9 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)9 IAction (org.drools.workbench.models.datamodel.rule.IAction)9 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)9 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)9