Search in sources :

Example 81 with BRLConditionColumn

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

the class GuidedDecisionTableGeneratorListenerTest method testTestNonExistentCellsFromPOI.

@Test
public // https://issues.jboss.org/browse/GUVNOR-2188
void testTestNonExistentCellsFromPOI() {
    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("GUVNOR-2188.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
    final List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
    assertNotNull(dtables);
    assertEquals(1, dtables.size());
    final GuidedDecisionTable52 dtable = dtables.get(0);
    assertEquals("IdentifyMetadataRules", dtable.getTableName());
    assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
    // Check expanded columns
    List<BaseColumn> columns = dtable.getExpandedColumns();
    assertNotNull(columns);
    assertEquals(7, columns.size());
    assertTrue(columns.get(0) instanceof RowNumberCol52);
    assertTrue(columns.get(1) instanceof RuleNameColumn);
    assertTrue(columns.get(2) instanceof DescriptionCol52);
    assertTrue(columns.get(3) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(4) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(5) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(6) instanceof BRLActionVariableColumn);
    // Check individual condition columns
    assertEquals(1, dtable.getConditions().size());
    assertTrue(dtable.getConditions().get(0) instanceof BRLConditionColumn);
    // Column 1
    BRLConditionColumn conditionCol0 = ((BRLConditionColumn) dtable.getConditions().get(0));
    assertEquals("Converted from ['Ingest Path', 'Court Id', 'Artifact Metadata Identified']", conditionCol0.getHeader());
    assertEquals(3, conditionCol0.getChildColumns().size());
    List<IPattern> conditionCol0definition = conditionCol0.getDefinition();
    assertEquals(1, conditionCol0definition.size());
    assertTrue(conditionCol0definition.get(0) instanceof FactPattern);
    FactPattern conditionCol0fp = (FactPattern) conditionCol0definition.get(0);
    assertEquals("IdentifyMetadataArtifact", conditionCol0fp.getFactType());
    assertEquals(3, conditionCol0fp.getNumberOfConstraints());
    assertTrue(conditionCol0fp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc0 = (SingleFieldConstraint) conditionCol0fp.getConstraint(0);
    assertEquals("ingestPath", conditionCol0fpsfc0.getFieldName());
    assertEquals("==", conditionCol0fpsfc0.getOperator());
    assertEquals("param1", conditionCol0fpsfc0.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc0.getConstraintValueType());
    assertEquals(DataType.TYPE_STRING, conditionCol0fpsfc0.getFieldType());
    assertTrue(conditionCol0fp.getConstraint(1) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc1 = (SingleFieldConstraint) conditionCol0fp.getConstraint(1);
    assertEquals("courtId", conditionCol0fpsfc1.getFieldName());
    assertEquals("==", conditionCol0fpsfc1.getOperator());
    assertEquals("param2", conditionCol0fpsfc1.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc1.getConstraintValueType());
    assertEquals(DataType.TYPE_STRING, conditionCol0fpsfc1.getFieldType());
    assertTrue(conditionCol0fp.getConstraint(2) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc2 = (SingleFieldConstraint) conditionCol0fp.getConstraint(2);
    assertEquals("artifactMetadataIdentified", conditionCol0fpsfc2.getFieldName());
    assertEquals("==", conditionCol0fpsfc2.getOperator());
    assertEquals("param3", conditionCol0fpsfc2.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc2.getConstraintValueType());
    assertEquals(DataType.TYPE_STRING, conditionCol0fpsfc2.getFieldType());
    // Column 1 - Variable 1
    BRLConditionVariableColumn conditionCol0param0 = conditionCol0.getChildColumns().get(0);
    assertEquals("param1", conditionCol0param0.getVarName());
    assertEquals("Ingest Path", conditionCol0param0.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0param0.getFieldType());
    assertEquals("IdentifyMetadataArtifact", conditionCol0param0.getFactType());
    assertEquals("ingestPath", conditionCol0param0.getFactField());
    // Column 1 - Variable 2
    BRLConditionVariableColumn conditionCol0param1 = conditionCol0.getChildColumns().get(1);
    assertEquals("param2", conditionCol0param1.getVarName());
    assertEquals("Court Id", conditionCol0param1.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0param1.getFieldType());
    assertEquals("IdentifyMetadataArtifact", conditionCol0param1.getFactType());
    assertEquals("courtId", conditionCol0param1.getFactField());
    // Column 1 - Variable 3
    BRLConditionVariableColumn conditionCol0param2 = conditionCol0.getChildColumns().get(2);
    assertEquals("param3", conditionCol0param2.getVarName());
    assertEquals("Artifact Metadata Identified", conditionCol0param2.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0param2.getFieldType());
    assertEquals("IdentifyMetadataArtifact", conditionCol0param2.getFactType());
    assertEquals("artifactMetadataIdentified", conditionCol0param2.getFactField());
    // Check individual action columns
    assertEquals(1, dtable.getActionCols().size());
    assertTrue(dtable.getActionCols().get(0) instanceof BRLActionColumn);
    // Column 2
    BRLActionColumn actionCol0 = ((BRLActionColumn) dtable.getActionCols().get(0));
    assertEquals("Converted from ['Identify Metadata Required']", actionCol0.getHeader());
    assertEquals(1, actionCol0.getChildColumns().size());
    List<IAction> actionCol0definition = actionCol0.getDefinition();
    assertEquals(1, actionCol0definition.size());
    assertTrue(actionCol0definition.get(0) instanceof ActionSetField);
    ActionSetField actionCol0asf = (ActionSetField) actionCol0definition.get(0);
    assertEquals("fact1", actionCol0asf.getVariable());
    assertEquals(1, actionCol0asf.getFieldValues().length);
    ActionFieldValue actionCol0asf_afv0 = actionCol0asf.getFieldValues()[0];
    assertEquals("identifiedMetadataRequired", actionCol0asf_afv0.getField());
    assertEquals("param4", actionCol0asf_afv0.getValue());
    assertEquals(FieldNatureType.TYPE_TEMPLATE, actionCol0asf_afv0.getNature());
    assertEquals(DataType.TYPE_STRING, actionCol0asf_afv0.getType());
}
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) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) 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) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) IAction(org.drools.workbench.models.datamodel.rule.IAction) InputStream(java.io.InputStream) IOException(java.io.IOException) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) DataListener(org.drools.template.parser.DataListener) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) RuleNameColumn(org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 82 with BRLConditionColumn

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

the class GuidedDecisionTableGeneratorListenerTest method checkConversionWithBigMaths.

private void checkConversionWithBigMaths(final ConversionResult result, final GuidedDecisionTableGeneratorListener listener, final Supplier<String> expectedDataType, final Supplier<Object> expectedDataValueRow0, final Supplier<Object> expectedDataValueRow1) {
    // Check conversion results
    assertEquals(0, result.getMessages().size());
    // Check basics
    final List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
    assertNotNull(dtables);
    assertEquals(1, dtables.size());
    GuidedDecisionTable52 dtable = dtables.get(0);
    assertEquals("HelloWorld1", dtable.getTableName());
    assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
    // Check expanded columns
    List<BaseColumn> columns = dtable.getExpandedColumns();
    assertNotNull(columns);
    assertEquals(9, columns.size());
    assertTrue(columns.get(0) instanceof RowNumberCol52);
    assertTrue(columns.get(1) instanceof RuleNameColumn);
    assertTrue(columns.get(2) instanceof DescriptionCol52);
    assertTrue(columns.get(3) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(4) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(5) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(6) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(7) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(8) instanceof BRLActionVariableColumn);
    // Check individual condition columns
    assertEquals(1, dtable.getConditions().size());
    assertTrue(dtable.getConditions().get(0) instanceof BRLConditionColumn);
    BRLConditionColumn conditionCol0 = ((BRLConditionColumn) dtable.getConditions().get(0));
    assertEquals("Converted from ['Status']", conditionCol0.getHeader());
    assertEquals(1, conditionCol0.getChildColumns().size());
    List<IPattern> conditionCol0definition = conditionCol0.getDefinition();
    assertEquals(1, conditionCol0definition.size());
    assertTrue(conditionCol0definition.get(0) instanceof FactPattern);
    FactPattern conditionCol0fp = (FactPattern) conditionCol0definition.get(0);
    assertEquals("Message", conditionCol0fp.getFactType());
    assertEquals(1, conditionCol0fp.getNumberOfConstraints());
    // Field Constraint 1
    assertTrue(conditionCol0fp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc0 = (SingleFieldConstraint) conditionCol0fp.getConstraint(0);
    assertEquals("status", conditionCol0fpsfc0.getFieldName());
    assertEquals("==", conditionCol0fpsfc0.getOperator());
    assertEquals("param1", conditionCol0fpsfc0.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc0.getConstraintValueType());
    assertEquals(DataType.TYPE_STRING, conditionCol0fpsfc0.getFieldType());
    // Field Constraint 1 - Variable 1
    BRLConditionVariableColumn conditionCol0param0 = conditionCol0.getChildColumns().get(0);
    assertEquals("param1", conditionCol0param0.getVarName());
    assertEquals("Status", conditionCol0param0.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0param0.getFieldType());
    assertEquals("Message", conditionCol0param0.getFactType());
    assertEquals("status", conditionCol0param0.getFactField());
    // Check individual action columns
    assertEquals(3, dtable.getActionCols().size());
    // Action 1
    assertTrue(dtable.getActionCols().get(0) instanceof BRLActionColumn);
    BRLActionColumn actionCol0 = ((BRLActionColumn) dtable.getActionCols().get(0));
    assertEquals("Converted from ['Print out message?']", actionCol0.getHeader());
    assertEquals(1, actionCol0.getChildColumns().size());
    List<IAction> actionCol0definition = actionCol0.getDefinition();
    assertEquals(1, actionCol0definition.size());
    assertTrue(actionCol0definition.get(0) instanceof FreeFormLine);
    FreeFormLine actionCol0ffl0 = (FreeFormLine) actionCol0definition.get(0);
    assertEquals("System.out.println(m.getMessage());", actionCol0ffl0.getText());
    // Action 2
    BRLActionColumn actionCol1 = ((BRLActionColumn) dtable.getActionCols().get(1));
    assertEquals("Converted from ['Set message', 'Set status', 'Set rate']", actionCol1.getHeader());
    assertEquals(3, actionCol1.getChildColumns().size());
    List<IAction> actionCol1definition = actionCol1.getDefinition();
    assertEquals(1, actionCol1definition.size());
    assertTrue(actionCol1definition.get(0) instanceof ActionSetField);
    ActionSetField actionCol1asf0 = (ActionSetField) actionCol1definition.get(0);
    assertEquals("m", actionCol1asf0.getVariable());
    ActionFieldValue[] actionCol1asf0afvs = actionCol1asf0.getFieldValues();
    assertEquals(3, actionCol1asf0afvs.length);
    ActionFieldValue actionCol1asf0afv0 = actionCol1asf0afvs[0];
    assertEquals("message", actionCol1asf0afv0.getField());
    assertEquals("param2", actionCol1asf0afv0.getValue());
    assertEquals(FieldNatureType.TYPE_TEMPLATE, actionCol1asf0afv0.getNature());
    assertEquals(DataType.TYPE_STRING, actionCol1asf0afv0.getType());
    ActionFieldValue actionCol1asf0afv1 = actionCol1asf0afvs[1];
    assertEquals("status", actionCol1asf0afv1.getField());
    assertEquals("param3", actionCol1asf0afv1.getValue());
    assertEquals(FieldNatureType.TYPE_TEMPLATE, actionCol1asf0afv1.getNature());
    assertEquals(DataType.TYPE_STRING, actionCol1asf0afv1.getType());
    // Action 1 - Variable 1
    BRLActionVariableColumn actionCol0param0 = actionCol0.getChildColumns().get(0);
    assertEquals("", actionCol0param0.getVarName());
    assertEquals("Print out message?", actionCol0param0.getHeader());
    assertEquals(DataType.TYPE_BOOLEAN, actionCol0param0.getFieldType());
    assertNull(actionCol0param0.getFactType());
    assertNull(actionCol0param0.getFactField());
    assertTrue(dtable.getActionCols().get(0) instanceof BRLActionColumn);
    // Action 2 - Variable 1
    BRLActionVariableColumn actionCol1param0 = actionCol1.getChildColumns().get(0);
    assertEquals("param2", actionCol1param0.getVarName());
    assertEquals("Set message", actionCol1param0.getHeader());
    assertEquals(DataType.TYPE_STRING, actionCol1param0.getFieldType());
    assertEquals("Message", actionCol1param0.getFactType());
    assertEquals("message", actionCol1param0.getFactField());
    // Action 2 - Variable 2
    BRLActionVariableColumn actionCol1param1 = actionCol1.getChildColumns().get(1);
    assertEquals("param3", actionCol1param1.getVarName());
    assertEquals("Set status", actionCol1param1.getHeader());
    assertEquals(DataType.TYPE_STRING, actionCol1param1.getFieldType());
    assertEquals("Message", actionCol1param1.getFactType());
    assertEquals("status", actionCol1param1.getFactField());
    // Action 2 - Variable 3
    BRLActionVariableColumn actionCol1param2 = actionCol1.getChildColumns().get(2);
    assertEquals("param4", actionCol1param2.getVarName());
    assertEquals("Set rate", actionCol1param2.getHeader());
    assertEquals(expectedDataType.get(), actionCol1param2.getFieldType());
    assertEquals("Message", actionCol1param2.getFactType());
    assertEquals("rate", actionCol1param2.getFactField());
    // Check data
    assertEquals(2, dtable.getData().size());
    assertTrue(isRowEquivalent(new Object[] { 1, "", "Hello World", "Message.HELLO", false, "Goodbye cruel world", "Message.GOODBYE", expectedDataValueRow0.get(), "m" }, dtable.getData().get(0)));
    assertTrue(isRowEquivalent(new Object[] { 2, "", "Goodbye", "Message.GOODBYE", false, "", "", expectedDataValueRow1.get(), "m" }, dtable.getData().get(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) IAction(org.drools.workbench.models.datamodel.rule.IAction) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) 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) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) RuleNameColumn(org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)

Example 83 with BRLConditionColumn

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

the class GuidedDecisionTableGeneratorListenerTest method testMultipleRuleTables.

@Test
public void testMultipleRuleTables() {
    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("MultipleRuleTables.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(2, dtables.size());
    GuidedDecisionTable52 dtable0 = dtables.get(0);
    assertEquals("Table1", dtable0.getTableName());
    assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable0.getTableFormat());
    GuidedDecisionTable52 dtable1 = dtables.get(1);
    assertEquals("Table2", dtable1.getTableName());
    assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable1.getTableFormat());
    // Check expanded columns
    List<BaseColumn> columns0 = dtable0.getExpandedColumns();
    assertNotNull(columns0);
    assertEquals(6, columns0.size());
    assertTrue(columns0.get(0) instanceof RowNumberCol52);
    assertTrue(columns0.get(1) instanceof RuleNameColumn);
    assertTrue(columns0.get(2) instanceof DescriptionCol52);
    assertTrue(columns0.get(3) instanceof AttributeCol52);
    assertTrue(columns0.get(4) instanceof BRLConditionVariableColumn);
    assertTrue(columns0.get(5) instanceof BRLActionVariableColumn);
    AttributeCol52 attrCol0_2 = ((AttributeCol52) columns0.get(3));
    assertEquals(Attribute.AGENDA_GROUP.getAttributeName(), attrCol0_2.getAttribute());
    // Check individual condition columns
    assertEquals(1, dtable0.getConditions().size());
    assertTrue(dtable0.getConditions().get(0) instanceof BRLConditionColumn);
    // Column 1
    BRLConditionColumn conditionCol0_0 = ((BRLConditionColumn) dtable0.getConditions().get(0));
    assertEquals("Converted from ['Person's name']", conditionCol0_0.getHeader());
    assertEquals(1, conditionCol0_0.getChildColumns().size());
    List<IPattern> conditionCol0_0definition = conditionCol0_0.getDefinition();
    assertEquals(1, conditionCol0_0definition.size());
    assertTrue(conditionCol0_0definition.get(0) instanceof FactPattern);
    FactPattern conditionCol0_0fp = (FactPattern) conditionCol0_0definition.get(0);
    assertEquals("Person", conditionCol0_0fp.getFactType());
    assertEquals(1, conditionCol0_0fp.getNumberOfConstraints());
    assertTrue(conditionCol0_0fp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0_0fpsfc0 = (SingleFieldConstraint) conditionCol0_0fp.getConstraint(0);
    assertEquals("name", conditionCol0_0fpsfc0.getFieldName());
    assertEquals("==", conditionCol0_0fpsfc0.getOperator());
    assertEquals("param1", conditionCol0_0fpsfc0.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0_0fpsfc0.getConstraintValueType());
    // Column 1 - Variable 1
    BRLConditionVariableColumn conditionCol0_0param0 = conditionCol0_0.getChildColumns().get(0);
    assertEquals("param1", conditionCol0_0param0.getVarName());
    assertEquals("Person's name", conditionCol0_0param0.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0_0param0.getFieldType());
    assertEquals("Person", conditionCol0_0param0.getFactType());
    assertEquals("name", conditionCol0_0param0.getFactField());
    // Column 2
    BRLActionColumn actionCol0_0 = ((BRLActionColumn) dtable0.getActionCols().get(0));
    assertEquals("Converted from ['Salutation']", actionCol0_0.getHeader());
    assertEquals(1, actionCol0_0.getChildColumns().size());
    List<IAction> actionCol0_0definition = actionCol0_0.getDefinition();
    assertEquals(1, actionCol0_0definition.size());
    assertTrue(actionCol0_0definition.get(0) instanceof FreeFormLine);
    FreeFormLine actionCol0_0ffl = (FreeFormLine) actionCol0_0definition.get(0);
    assertEquals("System.out.println(\"@{param2}\");", actionCol0_0ffl.getText());
    // Column 1 - Variable 1
    BRLActionVariableColumn actionCol0_0param0 = actionCol0_0.getChildColumns().get(0);
    assertEquals("param2", actionCol0_0param0.getVarName());
    assertEquals("Salutation", actionCol0_0param0.getHeader());
    assertEquals(DataType.TYPE_OBJECT, actionCol0_0param0.getFieldType());
    assertNull(actionCol0_0param0.getFactType());
    assertNull(actionCol0_0param0.getFactField());
    // Check data
    assertEquals(2, dtable0.getData().size());
    assertTrue(isRowEquivalent(new Object[] { 1, "", "Created from row 7", "AG1", "John", "Hello Sir" }, dtable0.getData().get(0)));
    assertTrue(isRowEquivalent(new Object[] { 2, "", "Row 2", "AG2", "Jane", "Hello Madam" }, dtable0.getData().get(1)));
    // Check expanded columns
    List<BaseColumn> columns1 = dtable1.getExpandedColumns();
    assertNotNull(columns1);
    assertEquals(5, columns1.size());
    assertTrue(columns1.get(0) instanceof RowNumberCol52);
    assertTrue(columns1.get(1) instanceof RuleNameColumn);
    assertTrue(columns1.get(2) instanceof DescriptionCol52);
    assertTrue(columns1.get(3) instanceof BRLConditionVariableColumn);
    assertTrue(columns1.get(4) instanceof BRLConditionVariableColumn);
    // Check individual condition columns
    assertEquals(1, dtable0.getConditions().size());
    assertTrue(dtable0.getConditions().get(0) instanceof BRLConditionColumn);
    // Column 1
    BRLConditionColumn conditionCol1_0 = ((BRLConditionColumn) dtable1.getConditions().get(0));
    assertEquals("Converted from ['Person’s name', 'Person’s age']", conditionCol1_0.getHeader());
    assertEquals(2, conditionCol1_0.getChildColumns().size());
    List<IPattern> conditionCol1_0definition = conditionCol1_0.getDefinition();
    assertEquals(1, conditionCol1_0definition.size());
    assertTrue(conditionCol1_0definition.get(0) instanceof FactPattern);
    FactPattern conditionCol1_0fp = (FactPattern) conditionCol1_0definition.get(0);
    assertEquals("Person", conditionCol1_0fp.getFactType());
    assertEquals(2, conditionCol1_0fp.getNumberOfConstraints());
    assertTrue(conditionCol1_0fp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol1_0fpsfc0 = (SingleFieldConstraint) conditionCol1_0fp.getConstraint(0);
    assertEquals("name", conditionCol1_0fpsfc0.getFieldName());
    assertEquals("==", conditionCol1_0fpsfc0.getOperator());
    assertEquals("param1", conditionCol1_0fpsfc0.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol1_0fpsfc0.getConstraintValueType());
    assertTrue(conditionCol1_0fp.getConstraint(1) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol1_0fpsfc1 = (SingleFieldConstraint) conditionCol1_0fp.getConstraint(1);
    assertEquals("age", conditionCol1_0fpsfc1.getFieldName());
    assertEquals("==", conditionCol1_0fpsfc1.getOperator());
    assertEquals("param2", conditionCol1_0fpsfc1.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol1_0fpsfc1.getConstraintValueType());
    // Column 1 - Variable 1
    BRLConditionVariableColumn conditionCol1_0param0 = conditionCol1_0.getChildColumns().get(0);
    assertEquals("param1", conditionCol1_0param0.getVarName());
    assertEquals("Person’s name", conditionCol1_0param0.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol1_0param0.getFieldType());
    assertEquals("Person", conditionCol1_0param0.getFactType());
    assertEquals("name", conditionCol1_0param0.getFactField());
    // Column 1 - Variable 2
    BRLConditionVariableColumn conditionCol1_0param1 = conditionCol1_0.getChildColumns().get(1);
    assertEquals("param2", conditionCol1_0param1.getVarName());
    assertEquals("Person’s age", conditionCol1_0param1.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol1_0param1.getFieldType());
    assertEquals("Person", conditionCol1_0param1.getFactType());
    assertEquals("age", conditionCol1_0param1.getFactField());
    // Check data
    assertEquals(2, dtable1.getData().size());
    assertTrue(isRowEquivalent(new Object[] { 1, "", "Row 1", "John", "25" }, dtable1.getData().get(0)));
    assertTrue(isRowEquivalent(new Object[] { 2, "", "Created from row 16", "Jane", "29" }, dtable1.getData().get(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) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) IAction(org.drools.workbench.models.datamodel.rule.IAction) InputStream(java.io.InputStream) IOException(java.io.IOException) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) DataListener(org.drools.template.parser.DataListener) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) RuleNameColumn(org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 84 with BRLConditionColumn

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

the class DecisionTableXLSToDecisionTableGuidedConverterTest method checkConversionOfXLSXFilesRHDM1159.

@Test
public void checkConversionOfXLSXFilesRHDM1159() {
    final InputStream is = this.getClass().getResourceAsStream("RHDM-1159.xls");
    when(ioService.newInputStream(any(org.uberfire.java.nio.file.Path.class))).thenReturn(is);
    // Mock imports to match project attached to JIRA
    final ProjectImports projectImports = new ProjectImports();
    projectImports.getImports().addImport(new Import("com.aia.model.underWriting.Benefit"));
    projectImports.getImports().addImport(new Import("com.aia.model.underWriting.Plans"));
    projectImports.getImports().addImport(new Import("com.aia.model.underWriting.CaseInfo"));
    projectImports.getImports().addImport(new Import("com.aia.model.underWriting.UnderwritingRuleRequest"));
    projectImports.getImports().addImport(new Import("com.aia.model.underWriting.UnderwritingRuleResponse"));
    doReturn(projectImports).when(converter).loadProjectImports(eq(expectedProjectImportsPath));
    final ConversionResult result = converter.convert(path);
    assertNotNull(result);
    final List<ConversionMessage> messages = result.getMessages();
    assertEquals(1, messages.size());
    assertTrue(messages.get(0).getMessage().startsWith("Created Guided Decision Table 'SampleAUWRule"));
    verify(guidedDecisionTableService, times(1)).create(any(Path.class), any(String.class), decisionTableArgumentCaptor.capture(), any(String.class));
    final GuidedDecisionTable52 dtable = decisionTableArgumentCaptor.getValue();
    assertNotNull(dtable);
    // Check attributes
    final List<AttributeCol52> attributes = dtable.getAttributeCols();
    assertEquals(1, attributes.size());
    assertEquals(Attribute.RULEFLOW_GROUP.getAttributeName(), attributes.get(0).getAttribute());
    // Check LHS
    final List<CompositeColumn<? extends BaseColumn>> conditions = dtable.getConditions();
    assertEquals(3, conditions.size());
    assertTrue(conditions.get(0) instanceof BRLConditionColumn);
    final BRLConditionColumn condition0 = (BRLConditionColumn) conditions.get(0);
    assertEquals(1, condition0.getDefinition().size());
    assertTrue(condition0.getDefinition().get(0) instanceof FactPattern);
    final FactPattern condition0FactPattern = (FactPattern) condition0.getDefinition().get(0);
    assertEquals("UnderwritingRuleRequest", condition0FactPattern.getFactType());
    assertEquals(1, condition0FactPattern.getNumberOfConstraints());
    final FieldConstraint condition0FactPatternConstraint = condition0FactPattern.getConstraint(0);
    assertTrue(condition0FactPatternConstraint instanceof SingleFieldConstraint);
    final SingleFieldConstraint condition0FactPatternSingleFieldConstraint = (SingleFieldConstraint) condition0FactPattern.getConstraint(0);
    assertEquals("traceId", condition0FactPatternSingleFieldConstraint.getFieldName());
    assertEquals("==", condition0FactPatternSingleFieldConstraint.getOperator());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, condition0FactPatternSingleFieldConstraint.getConstraintValueType());
    assertEquals("param1", condition0FactPatternSingleFieldConstraint.getValue());
    assertEquals(1, condition0.getChildColumns().size());
    final BRLConditionVariableColumn condition0Variable = condition0.getChildColumns().get(0);
    assertEquals("param1", condition0Variable.getVarName());
    assertEquals("UnderwritingRuleRequest", condition0Variable.getFactType());
    assertEquals("traceId", condition0Variable.getFactField());
    assertTrue(conditions.get(1) instanceof BRLConditionColumn);
    final BRLConditionColumn condition1 = (BRLConditionColumn) conditions.get(1);
    assertEquals(1, condition1.getDefinition().size());
    assertTrue(condition1.getDefinition().get(0) instanceof FromCompositeFactPattern);
    final FromCompositeFactPattern condition1FromCompositeFactPattern = (FromCompositeFactPattern) condition1.getDefinition().get(0);
    final FactPattern condition1FactPattern = condition1FromCompositeFactPattern.getFactPattern();
    assertEquals("CaseInfo", condition1FactPattern.getFactType());
    assertEquals(1, condition1FactPattern.getNumberOfConstraints());
    final FieldConstraint condition1FactPatternConstraint = condition1FactPattern.getConstraint(0);
    assertTrue(condition1FactPatternConstraint instanceof SingleFieldConstraint);
    final SingleFieldConstraint condition1FactPatternSingleFieldConstraint = (SingleFieldConstraint) condition1FactPattern.getConstraint(0);
    assertEquals("channel", condition1FactPatternSingleFieldConstraint.getFieldName());
    assertEquals("in", condition1FactPatternSingleFieldConstraint.getOperator());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, condition1FactPatternSingleFieldConstraint.getConstraintValueType());
    assertEquals("param2", condition1FactPatternSingleFieldConstraint.getValue());
    assertEquals(1, condition1.getChildColumns().size());
    final BRLConditionVariableColumn condition1Variable = condition1.getChildColumns().get(0);
    assertEquals("param2", condition1Variable.getVarName());
    assertEquals("CaseInfo", condition1Variable.getFactType());
    assertEquals("channel", condition1Variable.getFactField());
    assertTrue(conditions.get(2) instanceof BRLConditionColumn);
    final BRLConditionColumn condition2 = (BRLConditionColumn) conditions.get(2);
    assertEquals(1, condition2.getDefinition().size());
    assertTrue(condition2.getDefinition().get(0) instanceof FreeFormLine);
    final FreeFormLine condition2FreeFormLine = (FreeFormLine) condition2.getDefinition().get(0);
    assertEquals("plan :Plans();bn:Benefit(benefitCode  in (\"@{param3}\")) from plan.benefit;\n", condition2FreeFormLine.getText());
    assertEquals(1, condition2.getChildColumns().size());
    final BRLConditionVariableColumn condition2Variable = condition2.getChildColumns().get(0);
    assertEquals("param3", condition2Variable.getVarName());
    assertEquals("Benefit", condition2Variable.getFactType());
    assertEquals("benefitCode", condition2Variable.getFactField());
    // Check RHS
    final List<ActionCol52> actions = dtable.getActionCols();
    assertEquals(1, actions.size());
    assertTrue(actions.get(0) instanceof BRLActionColumn);
    final BRLActionColumn action0 = (BRLActionColumn) actions.get(0);
    assertTrue(action0.getDefinition().get(0) instanceof FreeFormLine);
    final FreeFormLine action0FreeFormLine = (FreeFormLine) action0.getDefinition().get(0);
    assertEquals("UnderwritingRuleResponse uwr= new UnderwritingRuleResponse();uwr.setAuwStatus(@{param4});", action0FreeFormLine.getText());
    assertEquals(1, action0.getChildColumns().size());
    final BRLActionVariableColumn action0Variable = action0.getChildColumns().get(0);
    assertEquals("param4", action0Variable.getVarName());
    // Check data
    final List<List<DTCellValue52>> data = dtable.getData();
    assertEquals(5, data.size());
    assertRHDM1159RowData(data.get(0), "abc", "AGENT", "RB", "\"FAIL\"");
    assertRHDM1159RowData(data.get(1), "sdf", "AGENT", "RB", "\"FAIL\"");
    assertRHDM1159RowData(data.get(2), "dsds", "AGENT", "RB", "\"FAIL\"");
    assertRHDM1159RowData(data.get(3), "sdddv", "AGENT", "RB", "\"FAIL\"");
    assertRHDM1159RowData(data.get(4), "", "", "", "");
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) ConversionMessage(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionMessage) Import(org.kie.soup.project.datamodel.imports.Import) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) CompositeColumn(org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) List(java.util.List) Path(org.uberfire.backend.vfs.Path) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) InputStream(java.io.InputStream) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) Test(org.junit.Test)

Example 85 with BRLConditionColumn

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

the class BRLConditionColumnDefinitionBuilderTest method setupBRLConditionColumn.

private void setupBRLConditionColumn() {
    final BRLConditionColumn brl = new BRLConditionColumn();
    final FactPattern fp1 = new FactPattern();
    fp1.setFactType("Person");
    final SingleFieldConstraint sfc1 = new SingleFieldConstraint();
    sfc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    sfc1.setFactType("Person");
    sfc1.setOperator("==");
    sfc1.setFieldName("name");
    sfc1.setValue("f1");
    fp1.addConstraint(sfc1);
    final FactPattern fp2 = new FactPattern();
    fp2.setFactType("Smurf");
    final SingleFieldConstraint sfc2 = new SingleFieldConstraint();
    sfc2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    sfc2.setFactType("Smurf");
    sfc2.setOperator("==");
    sfc2.setFieldName("colour");
    sfc2.setValue("f2");
    fp2.addConstraint(sfc2);
    brl.getDefinition().add(fp1);
    brl.getDefinition().add(fp2);
    brl.getChildColumns().add(new BRLConditionVariableColumn("f1", DataType.TYPE_STRING));
    brl.getChildColumns().add(new BRLConditionVariableColumn("f2", DataType.TYPE_STRING));
    model.getConditions().add(brl);
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Aggregations

BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)85 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)62 Test (org.junit.Test)54 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)39 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)36 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)27 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)27 ArrayList (java.util.ArrayList)23 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)23 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)23 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)22 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)18 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)17 RuleNameColumn (org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn)17 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)16 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)16 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)16 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)12 InputStream (java.io.InputStream)11 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)11